-
Notifications
You must be signed in to change notification settings - Fork 0
226 lines (201 loc) · 7.22 KB
/
release.yml
File metadata and controls
226 lines (201 loc) · 7.22 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
name: Release
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
permissions:
contents: read
jobs:
prepare:
name: Plan semantic release
if: ${{ github.event_name == 'workflow_dispatch' || !contains(github.event.head_commit.message, '[skip release]') }}
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
released: ${{ steps.plan.outputs.released }}
version: ${{ steps.plan.outputs.version }}
tag: ${{ steps.tag.outputs.tag }}
notes: ${{ steps.release_notes.outputs.notes }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install semantic release tooling
run: |
python -m pip install --upgrade pip
python -m pip install python-semantic-release build towncrier
- name: Detect next version
id: plan
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring
run: |
set +e
VERSION_OUTPUT=$(python -m semantic_release version --print 2>&1)
STATUS=$?
set -e
echo "$VERSION_OUTPUT"
if [ "$STATUS" -ne 0 ]; then
echo "released=false" >> "$GITHUB_OUTPUT"
echo "version=" >> "$GITHUB_OUTPUT"
exit 0
fi
VERSION=$(echo "$VERSION_OUTPUT" | tail -n 1 | tr -d ' \n')
if [ -z "$VERSION" ]; then
echo "released=false" >> "$GITHUB_OUTPUT"
echo "version=" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "released=true" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Compile release notes draft
id: release_notes
if: steps.plan.outputs.released == 'true'
env:
VERSION: ${{ steps.plan.outputs.version }}
run: |
NOTES_FILE=$(mktemp)
towncrier build --config docs/towncrier.toml --draft --version "$VERSION" > "$NOTES_FILE"
cat "$NOTES_FILE"
NOTES_CONTENT=$(cat "$NOTES_FILE")
NOTES_CONTENT="${NOTES_CONTENT//'%'/'%25'}"
NOTES_CONTENT="${NOTES_CONTENT//$'\n'/'%0A'}"
NOTES_CONTENT="${NOTES_CONTENT//$'\r'/'%0D'}"
echo "notes=$NOTES_CONTENT" >> "$GITHUB_OUTPUT"
- name: Regenerate versioned changelog
if: steps.plan.outputs.released == 'true'
env:
VERSION: ${{ steps.plan.outputs.version }}
run: towncrier build --config docs/towncrier.toml --yes --version "$VERSION"
- name: Commit changelog updates
if: steps.plan.outputs.released == 'true'
env:
VERSION: ${{ steps.plan.outputs.version }}
run: |
git add docs/releases.md
git add -A docs/changelog.d
if git diff --cached --quiet; then
echo "No changelog updates to commit."
exit 0
fi
git config user.name "tnfr-release-bot"
git config user.email "release-bot@users.noreply.github.com"
git commit -m "chore(release-notes): update changelog for v$VERSION [skip release]"
git push origin HEAD:main
- name: Apply release tag
if: steps.plan.outputs.released == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring
run: python -m semantic_release version --skip-build --no-vcs-release
- name: Emit tag output
id: tag
if: steps.plan.outputs.released == 'true'
run: |
echo "tag=v${VERSION}" >> "$GITHUB_OUTPUT"
env:
VERSION: ${{ steps.plan.outputs.version }}
publish:
name: Build and publish release
needs: prepare
if: needs.prepare.outputs.released == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout release tag
uses: actions/checkout@v5
with:
fetch-depth: 0
ref: ${{ needs.prepare.outputs.tag }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: |
pyproject.toml
- name: Cache pytest state
uses: actions/cache@v5
with:
path: |
.pytest_cache
~/.cache/pytest
key: ${{ runner.os }}-pytest-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pytest-
- name: Install QA dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .[test,typecheck]
- name: Run QA checks
id: qa
run: |
set -o pipefail
mkdir -p artifacts
./scripts/run_tests.sh | tee artifacts/qa-validation.log
- name: Upload validation logs
if: ${{ always() && steps.qa.outcome != 'skipped' }}
uses: actions/upload-artifact@v5
with:
name: qa-validation-${{ needs.prepare.outputs.version }}
path: artifacts/qa-validation.log
if-no-files-found: ignore
- name: Install build tooling
run: |
python -m pip install build python-semantic-release
- name: Import PyPI signing key
if: ${{ secrets.PYPI_SIGNING_KEY != '' && secrets.PYPI_SIGNING_KEY_ID != '' }}
env:
PYPI_SIGNING_KEY: ${{ secrets.PYPI_SIGNING_KEY }}
run: |
printf '%s' "$PYPI_SIGNING_KEY" | gpg --batch --import
- name: Build distributions
id: build
env:
TNFR_VERSION: ${{ needs.prepare.outputs.version }}
run: python -m build
- name: Sign distributions
if: ${{ secrets.PYPI_SIGNING_KEY != '' && secrets.PYPI_SIGNING_KEY_ID != '' && steps.build.outcome == 'success' }}
env:
GPG_KEY_ID: ${{ secrets.PYPI_SIGNING_KEY_ID }}
GPG_PASSPHRASE: ${{ secrets.PYPI_SIGNING_KEY_PASSPHRASE }}
run: |
for artifact in dist/*; do
[ -f "$artifact" ] || continue
if [ -n "$GPG_PASSPHRASE" ]; then
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" --local-user "$GPG_KEY_ID" --armor --detach-sign "$artifact"
else
gpg --batch --yes --local-user "$GPG_KEY_ID" --armor --detach-sign "$artifact"
fi
done
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.prepare.outputs.tag }}
body: ${{ needs.prepare.outputs.notes }}
files: |
dist/*
docs/releases.md
- name: Upload signed distributions
if: ${{ always() && steps.build.outcome == 'success' }}
uses: actions/upload-artifact@v5
with:
name: tnfr-${{ needs.prepare.outputs.version }}-dist
path: dist/*