-
Notifications
You must be signed in to change notification settings - Fork 0
316 lines (271 loc) · 8.34 KB
/
release.yml
File metadata and controls
316 lines (271 loc) · 8.34 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
name: Release
on:
workflow_dispatch:
inputs:
package:
description: Language package to release
required: true
type: choice
options:
- js
- python
- go
version:
description: Stable SemVer version without a leading v, for example 0.3.1
required: true
type: string
dry_run:
description: Validate release without publishing or creating a tag
required: true
type: boolean
default: true
permissions:
contents: read
concurrency:
group: release-${{ inputs.package }}-${{ inputs.version }}
cancel-in-progress: false
jobs:
validate:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.meta.outputs.tag }}
title: ${{ steps.meta.outputs.title }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate release inputs
id: meta
env:
PACKAGE: ${{ inputs.package }}
VERSION: ${{ inputs.version }}
DRY_RUN: ${{ inputs.dry_run }}
run: |
set -euo pipefail
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version must be a stable SemVer value like 0.3.1"
exit 1
fi
if [[ "$DRY_RUN" != "true" && "$GITHUB_REF" != "refs/heads/main" && "$GITHUB_REF" != "refs/heads/master" ]]; then
echo "Real releases must be run from main or master"
exit 1
fi
case "$PACKAGE" in
js) TAG="js/v$VERSION" ;;
python) TAG="python/v$VERSION" ;;
go) TAG="go/v$VERSION" ;;
*)
echo "Unknown package: $PACKAGE"
exit 1
;;
esac
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
echo "Tag already exists: $TAG"
exit 1
fi
{
echo "tag=$TAG"
echo "title=$PACKAGE v$VERSION"
} >> "$GITHUB_OUTPUT"
js-check:
needs: validate
if: ${{ inputs.package == 'js' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Check JS package version
env:
VERSION: ${{ inputs.version }}
run: |
node -e "const pkg = require('./js/package.json'); if (pkg.version !== process.env.VERSION) { throw new Error(`js/package.json version ${pkg.version} does not match ${process.env.VERSION}`); }"
- run: pnpm run verify:fixtures
- run: pnpm -C js test
- run: pnpm -C js build
- run: npm pack --dry-run
working-directory: js
js-publish:
needs:
- validate
- js-check
if: ${{ inputs.package == 'js' && inputs.dry_run == false }}
runs-on: ubuntu-latest
environment: npm
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- run: pnpm install --frozen-lockfile
- run: pnpm -C js build
- run: npm publish --access public
working-directory: js
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.validate.outputs.tag }}
TITLE: ${{ needs.validate.outputs.title }}
run: |
gh release create "$TAG" --target "$GITHUB_SHA" --title "$TITLE" --notes "Published $TITLE to npm."
python-check:
needs: validate
if: ${{ inputs.package == 'python' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pnpm install --frozen-lockfile
- run: pnpm run verify:fixtures
- name: Check Python package version
env:
VERSION: ${{ inputs.version }}
run: |
python - <<'PY'
import os
import pathlib
import tomllib
pyproject = tomllib.loads(pathlib.Path("python/pyproject.toml").read_text())
actual = pyproject["project"]["version"]
expected = os.environ["VERSION"]
if actual != expected:
raise SystemExit(f"python/pyproject.toml version {actual} does not match {expected}")
PY
- run: python -m pip install -e 'python[dev]'
- run: python -m pytest python/tests
- run: python -m ruff check python/src python/tests
- run: python -m build python
- run: python -m twine check python/dist/*
- uses: actions/upload-artifact@v4
with:
name: python-dist
path: python/dist/*
if-no-files-found: error
python-publish:
needs:
- validate
- python-check
if: ${{ inputs.package == 'python' && inputs.dry_run == false }}
runs-on: ubuntu-latest
environment: pypi
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: python-dist
path: python/dist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: python/dist
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.validate.outputs.tag }}
TITLE: ${{ needs.validate.outputs.title }}
run: |
gh release create "$TAG" --target "$GITHUB_SHA" --title "$TITLE" --notes "Published $TITLE to PyPI."
go-check:
needs: validate
if: ${{ inputs.package == 'go' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
- uses: actions/setup-go@v5
with:
go-version: "1.22"
cache-dependency-path: go/go.mod
- run: pnpm install --frozen-lockfile
- run: pnpm run verify:fixtures
- run: go test ./...
working-directory: go
- run: go vet ./...
working-directory: go
- run: go mod tidy
working-directory: go
- run: git diff --exit-code -- go/go.mod go/go.sum
- run: test -z "$(git status --porcelain -- go/go.mod go/go.sum)"
go-release:
needs:
- validate
- go-check
if: ${{ inputs.package == 'go' && inputs.dry_run == false }}
runs-on: ubuntu-latest
environment: go-release
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Push Go module tag
env:
TAG: ${{ needs.validate.outputs.tag }}
run: |
git tag "$TAG" "$GITHUB_SHA"
git push origin "$TAG"
- name: Request Go module indexing
env:
VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
for attempt in {1..6}; do
if GOPROXY=proxy.golang.org go list -m "github.com/algoux/standard-ranklist-utils/go@v$VERSION"; then
exit 0
fi
echo "Go proxy has not indexed the module yet; retry $attempt/6"
sleep 10
done
GOPROXY=proxy.golang.org go list -m "github.com/algoux/standard-ranklist-utils/go@v$VERSION"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.validate.outputs.tag }}
TITLE: ${{ needs.validate.outputs.title }}
run: |
gh release create "$TAG" --title "$TITLE" --notes "Published $TITLE as a Go module tag."