Skip to content

Commit 501a72a

Browse files
committed
feat: Add tag-after-merge workflow
This commit introduces a new GitHub Actions workflow that automatically creates a tag after a merge to the main branch.
1 parent 2fd51f0 commit 501a72a

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Tag After Merge
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
create-tag:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Get new version from package.json
18+
run: |
19+
VERSION=$(jq -r .version package.json)
20+
echo "version=$VERSION" >> $GITHUB_ENV
21+
22+
- name: Get last tag (if exists)
23+
run: |
24+
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
25+
# strip leading "v" if present
26+
LAST_TAG_STRIPPED=${LAST_TAG#v}
27+
echo "last_tag=$LAST_TAG_STRIPPED" >> $GITHUB_ENV
28+
29+
- name: Check release type (skip patch)
30+
run: |
31+
NEW=${{ env.version }}
32+
OLD=${{ env.last_tag }}
33+
34+
NEW_MAJOR=$(echo $NEW | cut -d. -f1)
35+
NEW_MINOR=$(echo $NEW | cut -d. -f2)
36+
NEW_PATCH=$(echo $NEW | cut -d. -f3)
37+
38+
OLD_MAJOR=$(echo $OLD | cut -d. -f1)
39+
OLD_MINOR=$(echo $OLD | cut -d. -f2)
40+
OLD_PATCH=$(echo $OLD | cut -d. -f3)
41+
42+
if [ "$NEW_MAJOR" -gt "$OLD_MAJOR" ]; then
43+
echo "release_type=major" >> $GITHUB_ENV
44+
elif [ "$NEW_MINOR" -gt "$OLD_MINOR" ]; then
45+
echo "release_type=minor" >> $GITHUB_ENV
46+
else
47+
echo "release_type=patch" >> $GITHUB_ENV
48+
fi
49+
50+
- name: Skip if patch
51+
if: env.release_type == 'patch'
52+
run: echo "Patch release detected → no tag will be created."
53+
54+
- name: Create and push git tag
55+
if: env.release_type != 'patch'
56+
run: |
57+
git config user.name "github-actions[bot]"
58+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
59+
git tag v${{ env.version }}
60+
git push origin v${{ env.version }}

0 commit comments

Comments
 (0)