Skip to content

Commit 48f4883

Browse files
authored
Create release.yml
1 parent 8362a51 commit 48f4883

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

.github/workflows/release.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Generate a New Tag for Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
BUG_OR_FEAT: |
10+
${{ endsWith(github.event.head_commit.message, '[tag-bug]') && 1 ||
11+
(endsWith(github.event.head_commit.message, '[tag-feat]') && 1 || 0) }}
12+
13+
jobs:
14+
build:
15+
name: Release to GitHub releases
16+
runs-on: ubuntu-latest
17+
18+
if: ${{ bug_or_feat }}
19+
steps:
20+
21+
- name: Set the Git config
22+
run: |
23+
git config --global user.name "github-actions[bot]"
24+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
25+
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: '0'
30+
31+
- name: Generate tag
32+
run: |
33+
VERSION_MAJOR="1"
34+
VERSION_MINOR=$(git tag --list "${VERSION_MAJOR}.[0-9]*.[0-9]*" --sort=-version:refname | head -n 1 | grep -oE '[0-9]+\.[0-9]+$' | grep -oE '^[0-9]+')
35+
VERSION_PATCH=$(git tag --list "${VERSION_MAJOR}.[0-9]*.[0-9]*" --sort=-version:refname | head -n 1 | grep -oE '[0-9]+$')
36+
37+
if [ "$BUG_OR_FEAT" -eq 1 ]; then
38+
NEW_VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.$((VERSION_PATCH + 1))"
39+
elif [ "$BUG_OR_FEAT" -eq 2 ]; then
40+
NEW_VERSION="${VERSION_MAJOR}.$((VERSION_MINOR + 1)).0"
41+
else
42+
echo "Critical error..!"
43+
fi
44+
echo "Generated new version: $NEW_VERSION"
45+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
46+
47+
- name: Push Git Tag
48+
run: |
49+
git tag $NEW_TAG
50+
git tag -a $NEW_VERSION -m "v$NEW_VERSION"
51+
git push origin $NEW_VERSION
52+
53+
- name: Update the v1 tag with the latest code
54+
run: |
55+
git tag -fa v1 -m "Update the v1 tag with the latest code"
56+
git push origin v1 --force

0 commit comments

Comments
 (0)