@@ -3,16 +3,16 @@ name: 🏷️ Auto Versioning
33on :
44 pull_request :
55 types :
6- - synchronize # XXX Temporary to test the workflow
7- # - closed # Runs when PR is merged
6+ - labeled # Runs when labels are added to the PR
87
98jobs :
109 versioning :
11- # if: github.event.pull_request.merged == true # Only run if PR is merged
1210 runs-on : ubuntu-latest
1311 steps :
1412 - name : Checkout Repository
1513 uses : actions/checkout@v4
14+ with :
15+ fetch-depth : 0 # Fetch full history to enable merging
1616
1717 - name : Set up Git
1818 run : |
2828 console.log("PR Labels:", labels);
2929 return labels;
3030
31+ - name : Check if Version Label Exists
32+ id : check_version_label
33+ run : |
34+ if echo "${{ steps.labels.outputs.result }}" | grep -Eq "version:(major|minor|patch)"; then
35+ echo "run_versioning=true" >> $GITHUB_ENV
36+ else
37+ echo "No versioning label found. Skipping workflow."
38+ exit 0
39+ fi
40+
41+ - name : Merge `dev` into PR Branch
42+ run : |
43+ git fetch origin dev
44+ git checkout ${{ github.head_ref }}
45+ if git merge --no-edit origin/dev; then
46+ echo "Merge successful."
47+ else
48+ echo "::error::Merge conflict detected! Resolve conflicts manually."
49+ exit 1
50+ fi
51+ continue-on-error : false
52+
53+ - name : Get Current Version from `dev`
54+ run : |
55+ git checkout origin/dev -- CMakeLists.txt
56+ VERSION=$(sed -nE 's/project\(atta VERSION ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' CMakeLists.txt)
57+
58+ if [[ -z "$VERSION" ]]; then
59+ echo "::error::Failed to extract version from CMakeLists.txt"
60+ exit 1
61+ fi
62+
63+ echo "::notice::Current Version (from dev): $VERSION"
64+ echo "VERSION=$VERSION" >> $GITHUB_ENV
65+
3166 - name : Determine Version Increment
32- id : version_type
3367 run : |
3468 echo "::notice::PR Labels Found: ${{ steps.labels.outputs.result }}"
3569 if echo "${{ steps.labels.outputs.result }}" | grep -q "version:major"; then
4377 echo "::notice::Version Increment: patch"
4478 fi
4579
46- - name : Read and Increment Version
47- id : update_version
80+ - name : Increment Version
4881 run : |
49- VERSION=$(sed -nE 's/project\(atta VERSION ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' CMakeLists.txt)
50-
51- if [[ -z "$VERSION" ]]; then
52- echo "::error::Failed to extract version from CMakeLists.txt"
53- exit 1
54- fi
55-
56- echo "::notice::Current Version: $VERSION"
57-
5882 IFS='.' read -r major minor patch <<< "$VERSION"
5983
6084 case "$increment" in
@@ -67,15 +91,29 @@ jobs:
6791 echo "::notice::New Version: $NEW_VERSION"
6892
6993 sed -i -E "s/(project\(atta VERSION) [0-9]+\.[0-9]+\.[0-9]+/\1 $NEW_VERSION/" CMakeLists.txt
70- echo "version =$NEW_VERSION" >> $GITHUB_ENV
94+ echo "NEW_VERSION =$NEW_VERSION" >> $GITHUB_ENV
7195
72- - name : Commit and Push Updated Version
96+ - name : Commit Updated Version (If Changed)
7397 run : |
7498 git add CMakeLists.txt
75- git commit --allow-empty -m "Chore: Bump version to ${{ env.version }}"
76- git push
99+ if git diff --staged --quiet; then
100+ echo "No changes to commit."
101+ else
102+ git commit -m "Chore: Bump version to $NEW_VERSION"
103+ git push origin ${{ github.head_ref }}
104+ fi
105+
106+ - name : Delete Old Tag (If Exists)
107+ run : |
108+ if git rev-parse "v$NEW_VERSION" >/dev/null 2>&1; then
109+ git push --delete origin "v$NEW_VERSION"
110+ git tag -d "v$NEW_VERSION"
111+ echo "Deleted existing tag v$NEW_VERSION."
112+ else
113+ echo "No existing tag v$NEW_VERSION found."
114+ fi
77115
78- - name : Create Git Tag
116+ - name : Create and Push New Git Tag
79117 run : |
80- git tag "v${{ env.version }} "
81- git push origin "v${{ env.version }} "
118+ git tag "v$NEW_VERSION "
119+ git push origin "v$NEW_VERSION "
0 commit comments