Skip to content

Commit 825fbee

Browse files
committed
ci: add automatic semantic version bumping for feat/fix commits
1 parent d5af7a2 commit 825fbee

4 files changed

Lines changed: 52 additions & 1 deletion

File tree

.github/workflows/version-bump.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Version Bump
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
bump-version:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
15+
- name: Set up Git
16+
run: |
17+
git config --global user.name "github-actions"
18+
git config --global user.email "github-actions@github.com"
19+
20+
- name: Bump version if needed
21+
run: bash scripts/bump-version.sh

build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ plugins {
55
}
66

77
group = 'com.blockcloud'
8-
version = '0.0.1-SNAPSHOT'
8+
9+
def props = new Properties()
10+
file("version.properties").withInputStream { props.load(it) }
11+
version = props['version']
912

1013
java {
1114
toolchain {

bump-version.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -e
3+
4+
version=$(grep 'version=' version.properties | cut -d'=' -f2)
5+
IFS='.' read -r major minor patch <<< "$version"
6+
7+
if git log -1 --pretty=%B | grep -q "^feat:"; then
8+
minor=$((minor + 1))
9+
patch=0
10+
elif git log -1 --pretty=%B | grep -q "^fix:"; then
11+
patch=$((patch + 1))
12+
else
13+
echo "No version bump needed."
14+
exit 0
15+
fi
16+
17+
new_version="$major.$minor.$patch"
18+
echo "Bumping version to $new_version"
19+
20+
echo "version=$new_version" > version.properties
21+
22+
git config user.name "github-actions"
23+
git config user.email "github-actions@github.com"
24+
git commit -am "chore: bump version to $new_version"
25+
git tag "v$new_version"
26+
git push origin HEAD --tags

version.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version=0.1.0

0 commit comments

Comments
 (0)