Skip to content

Commit 6f57f18

Browse files
authored
fix(ci): sign auto-tags via GitHub API and handle missing seed tag
Two fixes for the Release Auto-Tag workflow: 1. Bootstrap support: when no v*.*.* tags exist, seed from v0.0.0 so the first auto-tag creates v0.0.1 instead of failing. 2. Signed tags: replace lightweight `git tag` + `git push` with GitHub's Git database API (gh api git/tags + git/refs), which creates annotated tag objects signed by the token identity. Tags now show as "Verified" in the GitHub UI.
1 parent 9c8d6c7 commit 6f57f18

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

.github/workflows/release-auto-tag.yml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ jobs:
2929
run: |
3030
latest=$(git tag -l 'v*.*.*' --sort=-v:refname | head -1)
3131
if [ -z "$latest" ]; then
32-
echo "::error::No existing v*.*.* tags found"
33-
exit 1
32+
echo "No existing tags — seeding from v0.0.0"
33+
latest="v0.0.0"
3434
fi
3535
echo "Latest tag: $latest"
3636
37-
# Skip if no new commits since the latest tag
38-
commit_count=$(git rev-list "${latest}..HEAD" --count)
37+
# Skip if no new commits since the latest tag (unless seeding)
38+
if git rev-parse "$latest" >/dev/null 2>&1; then
39+
commit_count=$(git rev-list "${latest}..HEAD" --count)
40+
else
41+
commit_count=$(git rev-list HEAD --count)
42+
fi
3943
echo "Commits since $latest: $commit_count"
4044
if [ "$commit_count" -eq 0 ]; then
4145
echo "No new commits since $latest — skipping tag creation"
@@ -56,17 +60,34 @@ jobs:
5660
echo "next=$next" >> "$GITHUB_OUTPUT"
5761
echo "Next tag: $next"
5862
59-
- name: Create and push tag
63+
- name: Create signed tag via GitHub API
6064
if: steps.version.outputs.skip != 'true'
65+
env:
66+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
TAG: ${{ steps.version.outputs.next }}
6168
run: |
62-
git tag ${{ steps.version.outputs.next }}
63-
git push origin ${{ steps.version.outputs.next }}
69+
SHA=$(git rev-parse HEAD)
70+
71+
# Create annotated tag object (GitHub signs it with the token identity)
72+
gh api "repos/${{ github.repository }}/git/tags" \
73+
-f tag="$TAG" \
74+
-f message="Release $TAG" \
75+
-f object="$SHA" \
76+
-f type=commit
77+
78+
# Create the ref pointing to the tag object
79+
gh api "repos/${{ github.repository }}/git/refs" \
80+
-f ref="refs/tags/$TAG" \
81+
-f sha="$SHA"
82+
83+
echo "Created verified tag $TAG at $SHA"
6484
6585
- name: Trigger Release Tag workflow
6686
if: steps.version.outputs.skip != 'true'
6787
env:
6888
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
TAG: ${{ steps.version.outputs.next }}
6990
run: |
7091
gh workflow run release-tag.yml \
7192
--ref main \
72-
-f tag=${{ steps.version.outputs.next }}
93+
-f tag="$TAG"

0 commit comments

Comments
 (0)