11name : Semantic Release
22
33on :
4- push :
4+ pull_request :
55 branches :
66 - main
7+ types :
8+ - closed
79 workflow_dispatch :
810
911permissions :
@@ -15,30 +17,87 @@ concurrency:
1517
1618jobs :
1719 release :
18- if : github.actor != 'github-actions[bot]'
20+ if : >-
21+ ${{
22+ github.event_name == 'workflow_dispatch' ||
23+ (
24+ github.event_name == 'pull_request' &&
25+ github.event.pull_request.merged == true &&
26+ github.event.pull_request.base.ref == 'main' &&
27+ github.event.pull_request.head.ref == 'dev'
28+ )
29+ }}
1930 runs-on : ubuntu-latest
2031 steps :
32+ - name : Log trigger context
33+ run : |
34+ echo "event=${GITHUB_EVENT_NAME}"
35+ echo "ref=${GITHUB_REF}"
36+ echo "actor=${GITHUB_ACTOR}"
37+ echo "pr_merged=${{ github.event.pull_request.merged }}"
38+ echo "pr_base=${{ github.event.pull_request.base.ref }}"
39+ echo "pr_head=${{ github.event.pull_request.head.ref }}"
40+
41+ - name : Ensure release push token exists
42+ env :
43+ RELEASE_PUSH_TOKEN : ${{ secrets.RELEASE_PUSH_TOKEN }}
44+ run : |
45+ if [ -z "${RELEASE_PUSH_TOKEN}" ]; then
46+ echo "::error::Missing RELEASE_PUSH_TOKEN secret."
47+ exit 1
48+ fi
49+
2150 - uses : actions/checkout@v4
2251 with :
52+ ref : main
2353 fetch-depth : 0
2454 submodules : recursive
55+ persist-credentials : false
2556
2657 - uses : actions/setup-python@v5
2758 with :
2859 python-version : " 3.12"
2960
3061 - uses : astral-sh/setup-uv@v5
3162
63+ - name : Configure authenticated remote
64+ env :
65+ RELEASE_PUSH_TOKEN : ${{ secrets.RELEASE_PUSH_TOKEN }}
66+ run : git remote set-url origin "https://x-access-token:${RELEASE_PUSH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
67+
3268 - name : Configure git identity
3369 run : |
3470 git config user.name "github-actions[bot]"
3571 git config user.email "github-actions[bot]@users.noreply.github.com"
3672
73+ - name : Capture release baseline
74+ id : baseline
75+ run : |
76+ echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
77+ echo "tag=$(git describe --tags --abbrev=0 2>/dev/null || true)" >> "$GITHUB_OUTPUT"
78+
3779 - name : Run semantic release
3880 env :
39- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
40- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
81+ GH_TOKEN : ${{ secrets.RELEASE_PUSH_TOKEN }}
82+ GITHUB_TOKEN : ${{ secrets.RELEASE_PUSH_TOKEN }}
4183 run : uv run --no-project --with python-semantic-release==9.21.1 semantic-release version
4284
4385 - name : Push release commit and tags
4486 run : git push --follow-tags origin HEAD:main
87+
88+ - name : Summarize release outcome
89+ run : |
90+ set -euo pipefail
91+ after_sha=$(git rev-parse HEAD)
92+ after_tag=$(git describe --tags --abbrev=0 2>/dev/null || true)
93+
94+ echo "before_sha=${{ steps.baseline.outputs.sha }}"
95+ echo "after_sha=${after_sha}"
96+ echo "before_tag=${{ steps.baseline.outputs.tag }}"
97+ echo "after_tag=${after_tag}"
98+
99+ if [ "${after_sha}" = "${{ steps.baseline.outputs.sha }}" ] && [ "${after_tag}" = "${{ steps.baseline.outputs.tag }}" ]; then
100+ echo "No new release generated from this merge."
101+ else
102+ echo "Release generated. Latest tag: ${after_tag:-none}"
103+ fi
0 commit comments