1+ name : Release on GitHub
2+
3+ on :
4+ workflow_call :
5+ secrets :
6+ PAT_TOKEN :
7+ description : " GitHub Personal Access Token"
8+ required : true
9+
10+ env :
11+ TAG : ${{ github.ref_name }}
12+
13+ defaults :
14+ run :
15+ shell : bash {0}
16+
17+ jobs :
18+ prepare-release :
19+ if : ${{ ! contains(github.ref, 'rc') }}
20+ runs-on : ubuntu-latest
21+ steps :
22+ - name : Checkout the repository
23+ uses : actions/checkout@v4
24+ with :
25+ token : ${{ secrets.GITHUB_TOKEN }}
26+ fetch-depth : 0
27+ ref : main
28+
29+ - name : Update CHANGELOG
30+ run : |
31+ wget https://raw.githubusercontent.com/scikit-package/release-scripts/v0/.github/workflows/update-changelog.py
32+ python update-changelog.py "$TAG"
33+ rm update-changelog.py
34+
35+ - name : Commit updated CHANGELOG.rst
36+ run : |
37+ git config user.name "github-actions[bot]"
38+ git config user.email "github-actions[bot]@users.noreply.github.com"
39+ git add .
40+ if ! git diff --cached --quiet; then
41+ git commit -m "update changelog for $TAG"
42+ git push origin main
43+ else
44+ echo "No CHANGELOG.rst changes"
45+ fi
46+
47+ - name : New tag
48+ run : |
49+ git fetch --tags
50+ git tag -d "$TAG" 2>/dev/null || true
51+ git push origin ":$TAG" 2>/dev/null || true
52+ git tag "$TAG"
53+ git push origin "$TAG"
54+
55+ - name : Get CHANGELOG.txt
56+ run : |
57+ wget https://raw.githubusercontent.com/scikit-package/release-scripts/v0/.github/workflows/get-latest-changelog.py
58+ python get-latest-changelog.py "$TAG"
59+ rm get-latest-changelog.py
60+
61+ - name : Upload changelog.txt
62+ uses : actions/upload-artifact@v4
63+ with :
64+ name : changelog
65+ path : CHANGELOG.txt
66+
67+ release :
68+ needs : [prepare-release]
69+ if : always()
70+ runs-on : ubuntu-latest
71+ env :
72+ REPO_FULL : ${{ github.repository }}
73+ PAT_TOKEN : ${{ secrets.PAT_TOKEN }}
74+ steps :
75+ - name : Check prepare release
76+ run : |
77+ if [[ ${{ needs.prepare-release.result }} != 'success' && "$TAG" != *rc* ]]; then
78+ echo "::error::Skipping release job because prepare-release failed"
79+ exit 78
80+ fi
81+ echo "Continuing with release job"
82+
83+ - name : Download built wheels
84+ uses : actions/download-artifact@v4
85+ with :
86+ path : dist/
87+
88+ - name : Download changelog
89+ if : ${{ needs.prepare-release.result == 'success' }}
90+ uses : actions/download-artifact@v4
91+ with :
92+ name : changelog
93+ path : .
94+
95+ - name : Download instructions
96+ uses : actions/download-artifact@v4
97+ with :
98+ name : instructions
99+ path : .
100+
101+ - name : Zip wheels and instructions into dist/distanceprinter-$TAG-wheels.zip
102+ run : |
103+ mkdir -p dist
104+ find dist -type f -name '*.whl' | zip -j dist/distanceprinter-"$TAG"-wheels.zip -@
105+ zip -j dist/distanceprinter-"$TAG"-wheels.zip INSTRUCTIONS.txt
106+
107+ - name : Prepare release metadata
108+ id : meta
109+ run : |
110+ if [[ "$TAG" == *rc* ]]; then
111+ PRERELEASE=true
112+ TITLE="Pre-release $TAG"
113+ BODY_RAW="Changelog: https://github.com/$REPO_FULL/commits/$TAG"
114+ else
115+ PRERELEASE=false
116+ TITLE="Release $TAG"
117+ BODY_RAW=$(<CHANGELOG.txt)
118+ fi
119+
120+ jq -n \
121+ --arg tag "$TAG" \
122+ --arg name "$TITLE" \
123+ --arg body "$BODY_RAW" \
124+ --argjson prerelease "$PRERELEASE" \
125+ '{ tag_name: $tag,
126+ name: $name,
127+ body: $body,
128+ prerelease: $prerelease
129+ }' > payload.json
130+
131+ echo "Release metadata:"
132+ cat payload.json
133+
134+ - name : Create GitHub Release
135+ id : create_release
136+ run : |
137+ set -euo pipefail
138+
139+ HTTP_STATUS=$(
140+ curl --silent --output resp.json --write-out "%{http_code}" \
141+ -X POST "https://api.github.com/repos/$REPO_FULL/releases" \
142+ -H "Accept: application/vnd.github+json" \
143+ -H "Content-Type: application/json" \
144+ -H "Authorization: Bearer $PAT_TOKEN" \
145+ --data @payload.json
146+ )
147+ if [[ "$HTTP_STATUS" -ne 201 ]]; then
148+ echo "::error::Failed to create release (status $HTTP_STATUS)"
149+ exit 1
150+ fi
151+
152+ UPLOAD_URL=$(jq -r .upload_url resp.json | sed 's/{.*}//')
153+ echo "upload_url=$UPLOAD_URL" >> $GITHUB_OUTPUT
154+
155+ - name : Upload distanceprinter-$TAG-wheels.zip
156+ if : steps.create_release.outputs.upload_url != ''
157+ run : |
158+ FILE=dist/distanceprinter-$TAG-wheels.zip
159+ echo "Uploading asset: $FILE"
160+ curl --silent --fail --data-binary @"$FILE" \
161+ -H "Content-Type: application/zip" \
162+ -H "Authorization: Bearer $PAT_TOKEN" \
163+ "${{ steps.create_release.outputs.upload_url }}?name=$(basename "$FILE")"
0 commit comments