Repository navigation
138 lines (117 loc) · 3.83 KB
/
Copy pathrelease.yml
File metadata and controls
138 lines (117 loc) · 3.83 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
name: Release
on:
push:
tags: ["v*"]
permissions:
contents: read
jobs:
quality:
name: Verify tagged commit
uses: ./.github/workflows/test.yml
build:
name: Build distribution
needs: quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install build tool
run: pip install build
- name: Build sdist and wheel
run: python -m build
- name: Audit wheel contents against source
run: |
set -euo pipefail
WHEEL=$(python -c 'from pathlib import Path; wheels = sorted(Path("dist").glob("*.whl")); assert len(wheels) == 1, wheels; print(wheels[0])')
python .github/scripts/audit_wheel.py --wheel "$WHEEL"
- name: Verify built package version matches tag
run: |
TAG=${GITHUB_REF#refs/tags/v}
python -m pip install dist/*.whl
PKG_VERSION=$(python -c "from importlib.metadata import version; print(version('pt-snap-cli'))")
if [ "$TAG" != "$PKG_VERSION" ]; then
echo "::error::Tag v$TAG does not match built package version $PKG_VERSION"
exit 1
fi
- name: Verify package runs
run: pt-snap --version
- name: Extract release notes from changelog
run: |
python - <<'PY'
import os
import re
from pathlib import Path
tag = os.environ["GITHUB_REF"].removeprefix("refs/tags/v")
text = Path("CHANGELOG.md").read_text()
pattern = rf"^## \[{re.escape(tag)}\].*?$(.*?)(?=^## \[|\Z)"
match = re.search(pattern, text, re.MULTILINE | re.DOTALL)
if not match:
raise SystemExit(f"CHANGELOG.md does not contain release notes for ## [{tag}]")
notes = match.group(1).strip()
if not notes:
raise SystemExit(f"CHANGELOG.md release notes for ## [{tag}] are empty")
Path("release-notes.md").write_text(notes + "\n")
PY
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 90
- name: Upload release notes
uses: actions/upload-artifact@v4
with:
name: release-notes
path: release-notes.md
retention-days: 90
publish:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
permissions:
id-token: write
environment:
name: pypi
url: https://pypi.org/project/pt-snap-cli/
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# Uses Trusted Publisher (OIDC) by default - no API token needed.
# To publish to TestPyPI instead, uncomment:
# with:
# repository-url: https://test.pypi.org/legacy/
# Alternative: token-based publishing (if OIDC not configured)
# with:
# password: ${{ secrets.PYPI_API_TOKEN }}
github-release:
name: Create GitHub Release
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Download release notes
uses: actions/download-artifact@v4
with:
name: release-notes
- name: Create GitHub Release
run: |
TAG=${GITHUB_REF#refs/tags/}
gh release create "$TAG" dist/* --title "$TAG" --notes-file release-notes.md
env:
GH_TOKEN: ${{ github.token }}