Skip to content

Commit 1323cda

Browse files
saibulususaibulusu
andauthored
Auto-increment version (#311)
* Shell script and yml file. * 2 different shell scripts for windows and linux. * Using a single version file, and using virtualclient-ms for the updates. * Comment to explain. * Adding name to action yml file. --------- Co-authored-by: saibulusu <[email protected]>
1 parent 8bbc60b commit 1323cda

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This action is used to automatically increment the version within the VERSION file whenever it's not manually incremented.
2+
name: Increment Version
3+
4+
on:
5+
pull_request:
6+
branches:
7+
- main
8+
types:
9+
- closed
10+
11+
jobs:
12+
if_merged:
13+
if: github.event.pull_request.merged == true
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@main
20+
with:
21+
fetch-depth: 3
22+
- name: Run-Script
23+
run: |
24+
chmod +x ./increment-version.sh
25+
./increment-version.sh

VERSION

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

increment-version.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
calculate_new_version(){
2+
patch=$(echo $1 | cut -d '.' -f3 | cut -d '"' -f1)
3+
minor=$(echo $1 | cut -d '.' -f2)
4+
major=$(echo $1 | cut -d '.' -f1 | cut -d '"' -f2)
5+
6+
((patch++))
7+
8+
echo "$major.$minor.$patch"
9+
}
10+
11+
current_version=$(<VERSION)
12+
echo "current version: $current_version"
13+
14+
git config --global advice.detachedHead false
15+
16+
git stash
17+
git checkout HEAD~1
18+
previous_version=$(<VERSION)
19+
echo "previous version: $previous_version"
20+
21+
git checkout main
22+
23+
if [ "$previous_version" == "$current_version" ]; then
24+
echo "versions match, have to update now"
25+
new_version=$(calculate_new_version $current_version)
26+
echo "new version: $new_version"
27+
28+
echo "$new_version" > VERSION
29+
30+
git config user.email "[email protected]"
31+
git config user.name "virtualclient-ms"
32+
git add -f VERSION
33+
git commit -m "Updating to $new_version"
34+
git push
35+
else
36+
echo "version already updated, no need to update further"
37+
fi

0 commit comments

Comments
 (0)