11name : Release
22
33on :
4- pull_request_target :
5- types : [closed]
4+ push :
5+ branches :
6+ - main
67
78permissions :
89 contents : write
910
1011concurrency :
11- group : release-${{ github.event.pull_request.base.ref }}
12+ group : release-${{ github.ref_name }}
1213 cancel-in-progress : false
1314
1415jobs :
1516 release :
16- if : >
17- github.event.pull_request.merged == true &&
18- github.event.pull_request.base.ref == 'main'
1917 runs-on : ubuntu-latest
2018
2119 steps :
22- - name : Check out merged commit
20+ - name : Check out pushed commit
2321 uses : actions/checkout@v4
2422 with :
25- ref : ${{ github.event.pull_request.merge_commit_sha }}
23+ ref : ${{ github.sha }}
2624 fetch-depth : 0
2725
2826 - name : Fetch tags
@@ -31,13 +29,12 @@ jobs:
3129 - name : Determine CalVer tag
3230 id : calver
3331 env :
34- MERGE_COMMIT_SHA : ${{ github.event.pull_request.merge_commit_sha }}
35- MERGED_AT : ${{ github.event.pull_request.merged_at }}
32+ RELEASE_COMMIT_SHA : ${{ github.sha }}
3633 run : |
3734 set -euo pipefail
3835
3936 existing_tag="$(
40- git tag --points-at "$MERGE_COMMIT_SHA " |
37+ git tag --points-at "$RELEASE_COMMIT_SHA " |
4138 grep -E '^v[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]+$' |
4239 sort -V |
4340 tail -n 1 || true
4643 if [ -n "$existing_tag" ]; then
4744 tag="$existing_tag"
4845 else
49- base="$(date -u -d "$MERGED_AT" +'%y.%m.%d')"
46+ commit_timestamp="$(git show -s --format=%cI "$RELEASE_COMMIT_SHA")"
47+ base="$(date -u -d "$commit_timestamp" +'%y.%m.%d')"
5048 max_suffix=0
5149
5250 while IFS= read -r existing; do
@@ -67,31 +65,36 @@ jobs:
6765
6866 - name : Create and push tag
6967 env :
70- MERGE_COMMIT_SHA : ${{ github.event.pull_request.merge_commit_sha }}
68+ RELEASE_COMMIT_SHA : ${{ github.sha }}
7169 TAG : ${{ steps.calver.outputs.tag }}
7270 run : |
7371 set -euo pipefail
7472
7573 if git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null 2>&1; then
76- remote_sha="$(git rev-list -n 1 "$TAG")"
77- if [ "$remote_sha" = "$MERGE_COMMIT_SHA" ]; then
74+ remote_refs="$(git ls-remote --tags origin "refs/tags/$TAG" "refs/tags/$TAG^{}")"
75+ remote_sha="$(printf '%s\n' "$remote_refs" | awk '$2 ~ /\^\{\}$/ { print $1; exit }')"
76+ if [ -z "$remote_sha" ]; then
77+ remote_sha="$(printf '%s\n' "$remote_refs" | awk 'NF { print $1; exit }')"
78+ fi
79+
80+ if [ "$remote_sha" = "$RELEASE_COMMIT_SHA" ]; then
7881 echo "Tag $TAG already exists on origin and points to the expected commit"
7982 exit 0
8083 fi
8184
82- echo "Error: Tag $TAG already exists on origin but points to $remote_sha instead of $MERGE_COMMIT_SHA "
85+ echo "Error: Tag $TAG already exists on origin but points to $remote_sha instead of $RELEASE_COMMIT_SHA "
8386 exit 1
8487 fi
8588
8689 git config user.name "github-actions[bot]"
8790 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
88- git tag -a "$TAG" "$MERGE_COMMIT_SHA " -m "Release $TAG"
91+ git tag -a "$TAG" "$RELEASE_COMMIT_SHA " -m "Release $TAG"
8992 git push origin "refs/tags/$TAG"
9093
9194 - name : Create GitHub release
9295 env :
9396 GH_TOKEN : ${{ github.token }}
94- MERGE_COMMIT_SHA : ${{ github.event.pull_request.merge_commit_sha }}
97+ RELEASE_COMMIT_SHA : ${{ github.sha }}
9598 TAG : ${{ steps.calver.outputs.tag }}
9699 run : |
97100 set -euo pipefail
@@ -102,6 +105,6 @@ jobs:
102105 fi
103106
104107 gh release create "$TAG" \
105- --target "$MERGE_COMMIT_SHA " \
108+ --target "$RELEASE_COMMIT_SHA " \
106109 --generate-notes \
107110 --title "$TAG"
0 commit comments