Repository navigation
192 lines (183 loc) · 6.52 KB
/
Copy pathrelease.yml
File metadata and controls
192 lines (183 loc) · 6.52 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
name: Release
run-name: Release ${{ inputs.version }}${{ inputs.dry-run && ' (dry run)' || '' }}
on:
workflow_dispatch:
inputs:
version:
description: Version tag, such as v1.2.3
required: true
dry-run:
description: "Dry run: upload to Test PyPI only. Uncheck to publish to PyPI and create the GitHub release."
type: boolean
default: true
concurrency:
group: release
cancel-in-progress: false
permissions: {}
jobs:
check-version:
name: Check the version
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Check out the repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
enable-cache: false
- name: Check that the release runs from main
run: |
if [[ "$GITHUB_REF" != refs/heads/main ]]; then
echo "Releases run from main, not $GITHUB_REF"
exit 1
fi
- name: Check that the tag matches the package version
run: |
package_version=$(uv version --short --frozen)
echo "Tag: $INPUTS_VERSION, package version: $package_version"
[[ "$INPUTS_VERSION" == "v$package_version" ]]
env:
INPUTS_VERSION: ${{ inputs.version }}
- name: Check that the tag doesn't exist yet
run: |
if git ls-remote --exit-code --tags origin "refs/tags/$INPUTS_VERSION"; then
echo "Tag $INPUTS_VERSION already exists"
exit 1
fi
env:
INPUTS_VERSION: ${{ inputs.version }}
extract-changelog:
name: Extract the changelog entry
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Check out the repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Check the changelog has a released heading for this version
run: |
VERSION="${INPUTS_VERSION#v}" awk '
/^(```|~~~)/ { fence = !fence }
!fence && /^## / && $2 == ENVIRON["VERSION"] { ok = tolower($0) !~ /unreleased/; exit }
END { exit !ok }
' CHANGELOG.md
env:
INPUTS_VERSION: ${{ inputs.version }}
- name: Extract the changelog entry
run: |
VERSION="${INPUTS_VERSION#v}" awk '
/^(```|~~~)/ { fence = !fence }
!fence && /^## / { if (found) exit; if ($2 == ENVIRON["VERSION"]) { found = 1; next } }
found
' CHANGELOG.md > __CHANGELOG-extracted.md
cat __CHANGELOG-extracted.md
env:
INPUTS_VERSION: ${{ inputs.version }}
- name: Check the extracted entry isn't empty
run: grep -q '[^[:space:]]' __CHANGELOG-extracted.md
- name: Upload the extracted entry
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: changelog-extracted
path: __CHANGELOG-extracted.md
build:
name: Build and inspect the package
needs: [check-version, extract-changelog]
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # Build provenance attestation
attestations: write # Build provenance attestation
steps:
- name: Check out the repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Build and inspect the package
uses: hynek/build-and-inspect-python-package@67230f7b8410ae0052b39c1efc89d89fff43ff10 # v3.0.2
with:
attest-build-provenance-github: ${{ !inputs.dry-run }}
upload-to-test-pypi:
name: Upload to Test PyPI
needs: build
runs-on: ubuntu-latest
environment:
name: test-pypi
url: https://test.pypi.org/project/pdc-api/
permissions:
id-token: write # PyPI trusted publishing
steps:
- name: Download the package
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: Packages
path: dist
- name: Upload to Test PyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
upload-to-pypi:
name: Upload to PyPI
needs: upload-to-test-pypi
if: ${{ !inputs.dry-run }}
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/pdc-api/
permissions:
id-token: write # PyPI trusted publishing
steps:
- name: Download the package
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: Packages
path: dist
- name: Upload to PyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
github-release:
name: Create the GitHub release
needs: [upload-to-test-pypi, upload-to-pypi]
if: ${{ !cancelled()
&& needs.upload-to-test-pypi.result == 'success'
&& (needs.upload-to-pypi.result == 'success' || needs.upload-to-pypi.result == 'skipped') }}
runs-on: ubuntu-latest
permissions:
contents: write # Create the tag and release
steps:
- name: Download the package
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: Packages
path: dist
- name: Download the extracted changelog entry
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: changelog-extracted
- name: Show what the release would contain
if: ${{ inputs.dry-run }}
run: |
echo "Tag $INPUTS_VERSION on $GITHUB_SHA"
ls dist
cat __CHANGELOG-extracted.md
env:
INPUTS_VERSION: ${{ inputs.version }}
- name: Create the GitHub release
if: ${{ !inputs.dry-run }}
run: |
gh release create "$INPUTS_VERSION" \
--title "$INPUTS_VERSION" \
--target "$GITHUB_SHA" \
--notes-file __CHANGELOG-extracted.md \
dist/*.whl \
dist/*.tar.gz
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
INPUTS_VERSION: ${{ inputs.version }}