Repository navigation
108 lines (105 loc) · 3.23 KB
/
Copy pathrelease.yml
File metadata and controls
108 lines (105 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
publish:
description: "Run full publish flow"
default: "false"
required: false
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.11"
- name: Test release source
run: |
python -m pip install pytest
pytest -q
python scripts/validate_registry.py
- name: Verify tag matches package version
if: startsWith(github.ref, 'refs/tags/')
env:
RELEASE_TAG: ${{ github.ref_name }}
run: |
python - <<'PYCODE'
import os, pathlib, tomllib
version = tomllib.loads(pathlib.Path('pyproject.toml').read_text())['project']['version']
assert os.environ['RELEASE_TAG'] == 'v' + version
PYCODE
- name: Install build backend
run: python -m pip install --upgrade build
- name: Build distributions
run: python -m build
- name: Verify installed wheel
run: |
python -m pip install twine
twine check dist/*
python -m venv /tmp/set-wheel
/tmp/set-wheel/bin/pip install dist/*.whl
python scripts/release_smoke.py --exe /tmp/set-wheel/bin/set-plan-config-apply
- name: Upload packages
uses: actions/upload-artifact@v7
with:
name: dist
path: dist/
publish:
if: |
github.event_name == 'push' ||
github.event.inputs.publish == 'true'
needs: build
runs-on: ubuntu-latest
timeout-minutes: 20
environment: pypi
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Download packages
uses: actions/download-artifact@v8
with:
name: dist
path: dist
- name: Detect PyPI token availability
id: detect_pypi_token
shell: bash
run: |
if [ -n "${{ secrets.PYPI_API_TOKEN }}" ]; then
echo "has_token=true" >> "$GITHUB_OUTPUT"
else
echo "has_token=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish to PyPI (OIDC)
id: publish_oidc
uses: pypa/gh-action-pypi-publish@release/v1
continue-on-error: true
- name: Publish to PyPI (API token fallback)
if: steps.publish_oidc.outcome == 'failure' && steps.detect_pypi_token.outputs.has_token == 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m pip install --upgrade twine
twine upload --non-interactive dist/*
- name: Ensure PyPI publish
if: steps.publish_oidc.outcome == 'failure' && steps.detect_pypi_token.outputs.has_token == 'false'
run: |
echo "No trusted publisher and no PYPI_API_TOKEN provided." >&2
exit 1
- name: Publish GitHub release
uses: softprops/action-gh-release@v3
with:
generate_release_notes: true
files: dist/*