Skip to content

Commit 517db0a

Browse files
committed
fix(ci): create release tag when missing instead of only on version change
Auto Release now checks whether the tag for the current package.json version exists on the remote; if not, it creates and pushes the tag. This fixes the case where a version bump and other changes are pushed in separate commits (e.g. version then changelog), so both HEAD and HEAD~1 had the same version and no tag was created.
1 parent c5301cd commit 517db0a

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

.github/workflows/auto-release.yml

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,36 @@ on:
99

1010
jobs:
1111
check-version:
12-
name: Check Version Change
12+
name: Check Version and Tag
1313
runs-on: ubuntu-latest
1414
outputs:
15-
version_changed: ${{ steps.check.outputs.changed }}
16-
new_version: ${{ steps.check.outputs.version }}
15+
current_version: ${{ steps.check.outputs.version }}
16+
tag_exists: ${{ steps.check.outputs.tag_exists }}
1717
steps:
1818
- uses: actions/checkout@v4
1919
with:
2020
fetch-depth: 2
2121

22-
- name: Check for version change
22+
- name: Get version and check if tag exists
2323
id: check
2424
run: |
25-
PREV_VERSION=$(git show HEAD~1:package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf8')).version")
2625
CURRENT_VERSION=$(node -p "require('./package.json').version")
27-
echo "Previous version: $PREV_VERSION"
2826
echo "Current version: $CURRENT_VERSION"
27+
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
2928
30-
if [ "$PREV_VERSION" != "$CURRENT_VERSION" ]; then
31-
echo "Version changed from $PREV_VERSION to $CURRENT_VERSION"
32-
echo "changed=true" >> $GITHUB_OUTPUT
33-
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
29+
TAG_NAME="v${CURRENT_VERSION}"
30+
if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME"; then
31+
echo "Tag $TAG_NAME already exists"
32+
echo "tag_exists=true" >> $GITHUB_OUTPUT
3433
else
35-
echo "Version unchanged"
36-
echo "changed=false" >> $GITHUB_OUTPUT
34+
echo "Tag $TAG_NAME does not exist"
35+
echo "tag_exists=false" >> $GITHUB_OUTPUT
3736
fi
3837
3938
create-tag:
4039
name: Create Tag
4140
needs: check-version
42-
if: needs.check-version.outputs.version_changed == 'true'
41+
if: needs.check-version.outputs.tag_exists == 'false'
4342
runs-on: ubuntu-latest
4443
permissions:
4544
contents: write
@@ -48,22 +47,9 @@ jobs:
4847
with:
4948
token: ${{ secrets.RELEASE_TOKEN }}
5049

51-
- name: Check if tag exists
52-
id: tag-check
53-
run: |
54-
TAG_NAME="v${{ needs.check-version.outputs.new_version }}"
55-
if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME"; then
56-
echo "Tag $TAG_NAME already exists"
57-
echo "exists=true" >> $GITHUB_OUTPUT
58-
else
59-
echo "Tag $TAG_NAME does not exist"
60-
echo "exists=false" >> $GITHUB_OUTPUT
61-
fi
62-
6350
- name: Create and push tag
64-
if: steps.tag-check.outputs.exists == 'false'
6551
run: |
66-
TAG_NAME="v${{ needs.check-version.outputs.new_version }}"
52+
TAG_NAME="v${{ needs.check-version.outputs.current_version }}"
6753
git config user.name "github-actions[bot]"
6854
git config user.email "github-actions[bot]@users.noreply.github.com"
6955
git tag -a "$TAG_NAME" -m "Release $TAG_NAME"

0 commit comments

Comments
 (0)