-
Notifications
You must be signed in to change notification settings - Fork 2
98 lines (85 loc) · 3.07 KB
/
Copy pathpython-release.yml
File metadata and controls
98 lines (85 loc) · 3.07 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
name: Release
on:
push:
branches: ["main", "master"]
paths:
- "CHANGELOG.md"
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.13"
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
enable-cache: false
- name: Read release version
id: release
run: |
version=$(python - <<'PY'
import tomllib
from pathlib import Path
pyproject = tomllib.loads(Path("pyproject.toml").read_text())
print(pyproject["project"]["version"])
PY
)
notes=".changes/${version}.md"
if [ ! -f "$notes" ]; then
echo "Missing release notes: $notes" >&2
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "notes=$notes" >> "$GITHUB_OUTPUT"
- name: Check version changed
id: version-changed
run: |
previous_version=$(git show "${{ github.event.before }}:pyproject.toml" | python -c '
import sys
import tomllib
print(tomllib.loads(sys.stdin.read())["project"]["version"])
'
)
if [ "$previous_version" = "${{ steps.release.outputs.version }}" ]; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Check for existing release
id: existing-release
if: steps.version-changed.outputs.changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh release view "${{ steps.release.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Build package
if: steps.version-changed.outputs.changed == 'true' && steps.existing-release.outputs.exists == 'false'
run: uv build
- name: Publish package
if: steps.version-changed.outputs.changed == 'true' && steps.existing-release.outputs.exists == 'false'
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
with:
user: __token__
password: ${{ secrets.pypi_password }}
- name: Create GitHub release
if: steps.version-changed.outputs.changed == 'true' && steps.existing-release.outputs.exists == 'false'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${{ steps.release.outputs.version }}" \
--title "${{ steps.release.outputs.version }}" \
--notes-file "${{ steps.release.outputs.notes }}" \
dist/*