Skip to content

Commit 83ab6f4

Browse files
authored
Merge pull request #7 from arielszmerla/feat/add-semver
Feat/add semver
2 parents 5b08ee9 + 30c0862 commit 83ab6f4

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

.github/workflows/tag-version.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Semantic Version Tagging
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write # 👈 THIS IS REQUIRED TO PUSH TAGS
10+
11+
jobs:
12+
bump-version:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repo
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Get source branch name
21+
id: get_branch
22+
run: |
23+
echo "PR_BRANCH=unknown" >> $GITHUB_OUTPUT
24+
if [ "${{ github.event_name }}" == "pull_request" ]; then
25+
echo "PR_BRANCH=${{ github.event.pull_request.head.ref }}" >> $GITHUB_OUTPUT
26+
else
27+
BRANCH_NAME=$(git log -1 --pretty=%B | grep -oP '(feat|fix|rel)/[^\s]+')
28+
echo "PR_BRANCH=${BRANCH_NAME:-unknown}" >> $GITHUB_OUTPUT
29+
fi
30+
31+
- name: Decide bump type
32+
id: bump_type
33+
run: |
34+
BRANCH=${{ steps.get_branch.outputs.PR_BRANCH }}
35+
if [[ "$BRANCH" == feat/* ]]; then
36+
echo "BUMP=minor" >> $GITHUB_ENV
37+
elif [[ "$BRANCH" == fix/* ]]; then
38+
echo "BUMP=patch" >> $GITHUB_ENV
39+
elif [[ "$BRANCH" == rel/* ]]; then
40+
echo "BUMP=major" >> $GITHUB_ENV
41+
else
42+
echo "BUMP=patch" >> $GITHUB_ENV
43+
fi
44+
45+
- name: Get latest version
46+
id: current_version
47+
run: |
48+
TAG=$(git tag --sort=-v:refname | head -n1)
49+
echo "CURRENT_VERSION=${TAG:-v0.0.0}" >> $GITHUB_OUTPUT
50+
51+
- name: Bump version
52+
id: bump
53+
run: |
54+
VERSION=${{ steps.current_version.outputs.CURRENT_VERSION }}
55+
VERSION=${VERSION#v} # Strip leading v
56+
57+
# Split version manually
58+
MAJOR=$(echo "$VERSION" | cut -d. -f1)
59+
MINOR=$(echo "$VERSION" | cut -d. -f2)
60+
PATCH=$(echo "$VERSION" | cut -d. -f3)
61+
62+
echo "Current: $MAJOR.$MINOR.$PATCH, bump type: $BUMP"
63+
64+
# Increment according to bump type
65+
if [[ "$BUMP" == "major" ]]; then
66+
MAJOR=$((MAJOR + 1))
67+
MINOR=0
68+
PATCH=0
69+
elif [[ "$BUMP" == "minor" ]]; then
70+
MINOR=$((MINOR + 1))
71+
PATCH=0
72+
else
73+
PATCH=$((PATCH + 1))
74+
fi
75+
76+
NEW_VERSION="v$MAJOR.$MINOR.$PATCH"
77+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
78+
echo "Bumping version to $NEW_VERSION"
79+
80+
- name: Create and push tag
81+
run: |
82+
git config user.name "github-actions"
83+
git config user.email "github-actions@github.com"
84+
git tag -a ${{ steps.bump.outputs.NEW_VERSION }} -m "Release ${{ steps.get_branch.outputs.PR_BRANCH }}"
85+
git push origin ${{ steps.bump.outputs.NEW_VERSION }}

0 commit comments

Comments
 (0)