@@ -3,14 +3,28 @@ name: release
33on :
44 push :
55 branches : [main]
6+ workflow_dispatch :
67
78permissions :
8- contents : write
9+ contents : read
910
1011jobs :
12+ test :
13+ if : " !contains(github.event.head_commit.message, '[skip ci]')"
14+ uses : ./.github/workflows/test.yml
15+
1116 release :
1217 if : " !contains(github.event.head_commit.message, '[skip ci]')"
1318 runs-on : ubuntu-latest
19+ needs : test
20+
21+ outputs :
22+ released : ${{ steps.release.outputs.released }}
23+ tag : ${{ steps.release.outputs.tag }}
24+
25+ permissions :
26+ contents : write
27+
1428 steps :
1529 - name : Generate token for version incrementer app
1630 id : create_token
@@ -19,64 +33,61 @@ jobs:
1933 app_id : ${{ secrets.APP_ID }}
2034 private_key : ${{ secrets.PRIVATE_KEY }}
2135
22- - name : Checkout repository
36+ - name : Setup | Checkout Repository on Release Branch
2337 uses : actions/checkout@v4
2438 with :
39+ ref : ${{ github.ref_name }}
2540 fetch-depth : 0
26- ref : ${{ github.sha }}
2741 token : ${{ steps.create_token.outputs.token }}
2842
29- - name : Force correct branch on workflow sha
30- run : git checkout -B ${{ github.ref_name }} ${{ github.sha }}
31-
32- - name : Bump patch version
33- id : bump
43+ - name : Sync to latest remote
3444 run : |
35- CURRENT_VERSION=$(grep -oP '^version = "\K[^"]+' pyproject.toml)
36- IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
37- NEW_PATCH=$((PATCH + 1))
38- NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
39- sed -i "s/^version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" pyproject.toml
40- echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
41- echo "tag=v$NEW_VERSION" >> "$GITHUB_OUTPUT"
42- echo "Bumped version: $CURRENT_VERSION -> $NEW_VERSION"
45+ git fetch --prune origin
46+ git checkout ${{ github.ref_name }}
47+ git merge --ff-only origin/${{ github.ref_name }}
4348
4449 - name : Install uv
4550 uses : astral-sh/setup-uv@v5
4651
47- - name : Sync uv lockfile
48- run : uv lock
52+ - name : Set up Python
53+ uses : actions/setup-python@v5
54+ with :
55+ python-version-file : " pyproject.toml"
4956
50- - name : Get merged PR info
51- id : pr_info
52- env :
53- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
57+ - name : Install dependencies
58+ run : uv sync
59+
60+ - name : Action | Semantic Version Release
61+ id : release
62+ uses : python-semantic-release/python-semantic-release@v10.4.1
63+ with :
64+ github_token : ${{ secrets.GITHUB_TOKEN }}
65+ git_committer_name : " github-actions"
66+ git_committer_email : " actions@users.noreply.github.com"
67+ commit : " false"
68+ push : " false"
69+ tag : " false"
70+ changelog : " true"
71+ vcs_release : " false"
72+
73+ - name : Commit and push version changes
74+ if : steps.release.outputs.released == 'true'
5475 run : |
55- PR_NUMBER=$(gh pr list --state merged --search "${{ github.sha }}" --json number --jq '.[0].number' 2>/dev/null || echo "")
56- if [ -n "$PR_NUMBER" ]; then
57- PR_BODY=$(gh pr view "$PR_NUMBER" --json body --jq '.body')
58- echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
59- {
60- echo "notes<<EOF"
61- echo "$PR_BODY"
62- echo "EOF"
63- } >> "$GITHUB_OUTPUT"
64- else
65- echo "notes=Release ${{ steps.bump.outputs.tag }}" >> "$GITHUB_OUTPUT"
66- fi
67-
68- - name : Create GitHub release
76+ git config user.name "github-actions"
77+ git config user.email "actions@users.noreply.github.com"
78+ uv lock
79+ git add pyproject.toml CHANGELOG.md uv.lock
80+ git commit -m "chore: release ${{ steps.release.outputs.tag }} [skip ci]
81+
82+ Automatically generated by python-semantic-release"
83+ git tag ${{ steps.release.outputs.tag }}
84+ git push origin ${{ github.ref_name }} --tags
85+
86+ - name : Create GitHub Release
87+ if : steps.release.outputs.released == 'true'
88+ run : |
89+ gh release create ${{ steps.release.outputs.tag }} \
90+ --title "${{ steps.release.outputs.tag }}" \
91+ --generate-notes
6992 env :
7093 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
71- RELEASE_NOTES : ${{ steps.pr_info.outputs.notes }}
72- run : |
73- gh release create "${{ steps.bump.outputs.tag }}" \
74- --title "${{ steps.bump.outputs.tag }}" \
75- --notes "$RELEASE_NOTES"
76-
77- - name : Commit version bump
78- uses : stefanzweifel/git-auto-commit-action@v5
79- with :
80- commit_message : " chore: release ${{ steps.bump.outputs.tag }} [skip ci]"
81- branch : ${{ github.ref_name }}
82- file_pattern : " pyproject.toml uv.lock"
0 commit comments