Skip to content

Commit 791c14e

Browse files
authored
Introducing a version bump logic with release.yml
1 parent f6735ea commit 791c14e

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

.github/workflows/release.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Versioning & Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main # Only auto-increment when committing to main
7+
8+
jobs:
9+
versioning:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout Repository
14+
uses: actions/checkout@v4
15+
16+
- name: Read Current Version
17+
id: get_version
18+
run: echo "CURRENT_VERSION=$(grep '__version__' cli_monitor.py | cut -d'=' -f2 | tr -d ' \"')" >> $GITHUB_ENV
19+
20+
- name: Determine Version Increment
21+
id: version_bump
22+
run: |
23+
CURRENT_VERSION=${{ env.CURRENT_VERSION }}
24+
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
25+
MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
26+
PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
27+
28+
COMMIT_MSG=$(git log -1 --pretty=%B)
29+
30+
if [[ "$COMMIT_MSG" == *"MAJOR"* ]]; then
31+
MAJOR=$((MAJOR + 1))
32+
MINOR=0
33+
PATCH=0
34+
elif [[ "$COMMIT_MSG" == *"MINOR"* ]]; then
35+
MINOR=$((MINOR + 1))
36+
PATCH=0
37+
elif [[ "$COMMIT_MSG" == *"PATCH"* ]]; then
38+
PATCH=$((PATCH + 1))
39+
fi
40+
41+
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
42+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
43+
echo "Version updated to $NEW_VERSION"
44+
45+
- name: Update Version in `cli_monitor.py`
46+
run: sed -i "s/^__version__ = .*/__version__ = \"${{ env.NEW_VERSION }}\"/" cli_monitor.py
47+
48+
- name: Commit & Push Version Update
49+
run: |
50+
git config --global user.name "github-actions[bot]"
51+
git config --global user.email "github-actions@users.noreply.github.com"
52+
git add cli_monitor.py
53+
git commit -m "chore: bump version to ${{ env.NEW_VERSION }}"
54+
git push
55+
56+
- name: Create GitHub Release
57+
uses: softprops/action-gh-release@v2
58+
with:
59+
tag_name: v${{ env.NEW_VERSION }}
60+
name: Release v${{ env.NEW_VERSION }}
61+
body: "Automated release for version ${{ env.NEW_VERSION }}"
62+
draft: false
63+
prerelease: false
64+
files: cli_monitor.py

0 commit comments

Comments
 (0)