Repository navigation
342 lines (314 loc) · 12.1 KB
/
Copy pathrelease.yml
File metadata and controls
342 lines (314 loc) · 12.1 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
---
name: Release
on:
workflow_dispatch:
inputs:
version:
description: Release version without the v prefix.
required: true
type: string
ref:
description: Branch, tag, or SHA to release.
required: false
default: master
type: string
publish_github_release:
description: Create or update the GitHub Release.
required: false
default: true
type: boolean
publish_pypi:
description: Publish distributions to PyPI.
required: false
default: true
type: boolean
publish_provider_packages:
description: Include optional provider distributions in the PyPI upload.
required: false
default: false
type: boolean
concurrency:
group: wyrmctl-release-${{ inputs.version }}
cancel-in-progress: false
permissions:
actions: write
contents: write
id-token: write
jobs:
prepare:
runs-on:
group: shortlived
outputs:
target_ref: ${{ steps.target.outputs.ref }}
target_sha: ${{ steps.final-target.outputs.sha }}
tag_name: ${{ steps.prepare.outputs.tag-name }}
release_name: ${{ steps.prepare.outputs.release-name }}
release_notes: ${{ steps.prepare.outputs.release-notes }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.ref }}
fetch-depth: 0
- uses: ./.github/actions/setup-uv-python
- name: Resolve target ref
id: target
shell: bash
run: |
set -euo pipefail
echo "ref=${{ inputs.ref }}" >> "$GITHUB_OUTPUT"
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Bump release metadata
shell: bash
env:
VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
python - <<'PY'
import os
import re
from pathlib import Path
version = os.environ["VERSION"]
version_paths = [
Path("pyproject.toml"),
Path("packages/wyrmctl/pyproject.toml"),
Path("packages/wyrmctl-cloudflare/pyproject.toml"),
Path("packages/wyrmctl-digitalocean/pyproject.toml"),
Path("packages/wyrmctl-godaddy/pyproject.toml"),
Path("packages/wyrmctl-namecheap/pyproject.toml"),
Path("packages/wyrmctl-route53/pyproject.toml"),
]
for path in version_paths:
text = path.read_text(encoding="utf-8")
text = re.sub(
r'(^version\s*=\s*)["\'][^"\']*["\']',
rf'\1"{version}"',
text,
count=1,
flags=re.M,
)
path.write_text(text, encoding="utf-8")
init = Path("packages/wyrmctl/src/wyrmctl/__init__.py")
text = init.read_text(encoding="utf-8")
text = re.sub(
r'(__version__\s*=\s*)["\'][^"\']*["\']',
rf'\1"{version}"',
text,
)
init.write_text(text, encoding="utf-8")
PY
uv lock
uv run --locked readme-standards render --all --write
- name: Commit release metadata
shell: bash
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add \
README.md \
':(glob)packages/*/README.md' \
pyproject.toml \
packages/wyrmctl/pyproject.toml \
packages/wyrmctl-cloudflare/pyproject.toml \
packages/wyrmctl-digitalocean/pyproject.toml \
packages/wyrmctl-godaddy/pyproject.toml \
packages/wyrmctl-namecheap/pyproject.toml \
packages/wyrmctl-route53/pyproject.toml \
packages/wyrmctl/src/wyrmctl/__init__.py \
uv.lock
if git diff --cached --quiet; then
exit 0
fi
git commit -m "Release wyrmctl ${{ inputs.version }}"
git push
- name: Refresh target SHA after release commit
id: final-target
shell: bash
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Prepare release metadata
id: prepare
shell: bash
run: |
set -euo pipefail
notes="release-notes.md"
echo "Release wyrmctl v${{ inputs.version }}" > "$notes"
echo "tag-name=v${{ inputs.version }}" >> "$GITHUB_OUTPUT"
echo "release-name=wyrmctl v${{ inputs.version }}" >> "$GITHUB_OUTPUT"
echo "release-notes=$notes" >> "$GITHUB_OUTPUT"
- name: Verify synchronized package versions and publish compatibility matrix
shell: bash
env:
VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
uv run python - <<'PY'
import os
import tomllib
from pathlib import Path
expected = os.environ["VERSION"]
paths = [Path("pyproject.toml"), *sorted(Path("packages").glob("*/pyproject.toml"))]
versions = {str(path): tomllib.loads(path.read_text(encoding="utf-8"))["project"]["version"] for path in paths}
mismatches = {path: value for path, value in versions.items() if value != expected}
if mismatches:
raise SystemExit(f"workspace versions are not synchronized: {mismatches}")
PY
uv run wyrmctl --output json contract list > contract-compatibility-matrix.json
uv run wyrmctl migrate examples/desired-state --check
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wyrmctl-contract-compatibility
path: contract-compatibility-matrix.json
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wyrmctl-release-notes
path: ${{ steps.prepare.outputs.release-notes }}
gates:
needs: prepare
runs-on:
group: shortlived
steps:
- name: Install GitHub CLI
shell: bash
run: |
if command -v gh >/dev/null 2>&1; then
exit 0
fi
gh_dir="$(mktemp -d "$RUNNER_TEMP/wyrmctl-gh.XXXXXX")"
curl -fsSL https://api.github.com/repos/cli/cli/releases/latest -o "$gh_dir/release.json"
asset_url="$(grep -o 'https://[^" ]*gh_[^" ]*_linux_amd64.tar.gz' "$gh_dir/release.json" | sed -n '1p')"
test -n "$asset_url"
curl -fsSL "$asset_url" -o "$gh_dir/gh.tar.gz"
tar -xzf "$gh_dir/gh.tar.gz" -C "$gh_dir" --strip-components=1
test -x "$gh_dir/bin/gh"
echo "$gh_dir/bin" >> "$GITHUB_PATH"
- name: Dispatch and wait for release gates
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
TARGET_REF: ${{ needs.prepare.outputs.target_ref }}
TARGET_SHA: ${{ needs.prepare.outputs.target_sha }}
shell: bash
run: |
set -euo pipefail
wait_for_success() {
local workflow="$1"
local label="$2"
local started="$3"
local deadline=$((SECONDS + 3600))
local run_id=""
while (( SECONDS < deadline )); do
if ! run_id="$(gh run list --repo "$REPO" --workflow "$workflow" \
--json databaseId,headSha,status,conclusion,createdAt --limit 50 \
--jq '[.[] | select(.headSha == env.TARGET_SHA and .createdAt >= "'"$started"'")] | sort_by(.createdAt) | last | .databaseId // ""' \
2>/dev/null)"; then
sleep 5
continue
fi
if [[ -n "$run_id" ]]; then
if ! status="$(gh run view "$run_id" --repo "$REPO" --json status --jq .status 2>/dev/null)"; then
sleep 5
continue
fi
if ! conclusion="$(gh run view "$run_id" --repo "$REPO" --json conclusion --jq '.conclusion // ""' 2>/dev/null)"; then
sleep 5
continue
fi
if [[ "$status" == "completed" ]]; then
if [[ "$conclusion" == "success" ]]; then
echo "$label succeeded: $run_id"
return 0
fi
echo "$label failed: $run_id ($conclusion)" >&2
exit 1
fi
fi
sleep 20
done
echo "$label did not complete before timeout" >&2
exit 1
}
ci_started="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
gh workflow run ci.yml --repo "$REPO" --ref "$TARGET_REF"
wait_for_success ci.yml "CI" "$ci_started"
docs_started="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
gh workflow run docs-ssot.yml --repo "$REPO" --ref "$TARGET_REF"
wait_for_success docs-ssot.yml "Docs and SSOT" "$docs_started"
python_started="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
gh workflow run python-matrix.yml --repo "$REPO" --ref "$TARGET_REF"
wait_for_success python-matrix.yml "Python Matrix" "$python_started"
live_started="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
gh workflow run live-npm-gate.yml --repo "$REPO" --ref "$TARGET_REF"
wait_for_success live-npm-gate.yml "Portwyrm Acceptance" "$live_started"
build:
needs: [prepare, gates]
runs-on:
group: shortlived
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.prepare.outputs.target_sha }}
- uses: ./.github/actions/setup-uv-python
- uses: ./.github/actions/wyrmctl-release-build
publish:
needs: [prepare, build]
runs-on:
group: shortlived
environment: pypi
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: wyrmctl-dist
path: dist
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: wyrmctl-release-notes
path: .tmp/release
- name: Select PyPI distribution scope
id: pypi-scope
shell: bash
env:
VERSION: ${{ inputs.version }}
PUBLISH_PROVIDERS: ${{ inputs.publish_provider_packages }}
run: |
set -euo pipefail
if [[ "$PUBLISH_PROVIDERS" == "true" ]]; then
echo "directory=dist" >> "$GITHUB_OUTPUT"
exit 0
fi
mkdir -p .tmp/pypi-core
cp "dist/wyrmctl-${VERSION}.tar.gz" .tmp/pypi-core/
cp "dist/wyrmctl-${VERSION}-"*.whl .tmp/pypi-core/
echo "directory=.tmp/pypi-core" >> "$GITHUB_OUTPUT"
- name: Publish distributions to PyPI with Trusted Publishing
id: pypi-trusted-publishing
uses: pypa/gh-action-pypi-publish@release/v1
if: inputs.publish_pypi
continue-on-error: true
env:
DOCKER_API_VERSION: "1.43"
with:
packages-dir: ${{ steps.pypi-scope.outputs.directory }}
skip-existing: true
- name: Publish distributions to PyPI with API token fallback
if: inputs.publish_pypi && steps.pypi-trusted-publishing.outcome == 'failure'
env:
DOCKER_API_VERSION: "1.43"
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: ${{ steps.pypi-scope.outputs.directory }}
skip-existing: true
attestations: false
- uses: softprops/action-gh-release@e598afbe1493e6b1bafb1f389cabb956eab91231 # v3.0.3
if: >
inputs.publish_github_release && (
!inputs.publish_pypi ||
steps.pypi-trusted-publishing.outcome == 'success' ||
steps.pypi-trusted-publishing.outcome == 'failure'
)
with:
tag_name: ${{ needs.prepare.outputs.tag_name }}
name: ${{ needs.prepare.outputs.release_name }}
body_path: .tmp/release/release-notes.md
files: dist/*