1- name : New Release Action
1+ name : Version Update Action
22
33on :
44 pull_request :
55 branches :
6- - main
6+ - main
77 types : [labeled]
88
99jobs :
10- upgrade-poms :
10+ update-pom-version :
1111 runs-on : ubuntu-latest
12- if : contains(github.event.pull_request.labels.*.name, 'New Release')
12+ if : >
13+ contains(github.event.pull_request.labels.*.name, 'Version Update - Staging') ||
14+ contains(github.event.pull_request.labels.*.name, 'Version Update - Prod')
1315 steps :
14- - name : Check out code
16+ - name : Checkout PR branch
1517 uses : actions/checkout@v4
1618 with :
1719 ref : ${{ github.head_ref }}
18- - name : Extract version number
20+
21+ - name : Get Short SHA
22+ id : sha
23+ run : echo "sha_short=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_OUTPUT
24+
25+ - name : Extract version from PR title
1926 id : extract_version
2027 run : |
21- VERSION_NUMBER=$(echo '${{ github.event.pull_request.title }}' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
22- echo "new_version=${VERSION_NUMBER}" >> $GITHUB_OUTPUT
28+ TITLE_VERSION=$(echo "${{ github.event.pull_request.title }}" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || true)
29+ echo "title_version=$TITLE_VERSION" >> $GITHUB_OUTPUT
30+ if [ -z "$TITLE_VERSION" ]; then
31+ echo "No version in PR title. Will increment patch."
32+ else
33+ echo "Detected version in PR title: $TITLE_VERSION"
34+ fi
35+
36+ - name : Get current version from pom.xml
37+ id : current_version
38+ run : |
39+ CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
40+ echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
41+ echo "Current POM version: $CURRENT_VERSION"
42+
43+ - name : Determine base version
44+ id : base_version
45+ env :
46+ TITLE_VERSION : ${{ steps.extract_version.outputs.title_version }}
47+ CUR_VERSION : ${{ steps.current_version.outputs.current_version }}
48+ run : |
49+ if [ -n "$TITLE_VERSION" ]; then
50+ BASE_VERSION="$TITLE_VERSION"
51+ else
52+ IFS='.' read -r MAJOR MINOR PATCH <<< "$CUR_VERSION"
53+ PATCH=$((PATCH + 1))
54+ BASE_VERSION="$MAJOR.$MINOR.$PATCH"
55+ echo "Auto-incremented patch version: $BASE_VERSION"
56+ fi
57+ echo "base_version=$BASE_VERSION" >> $GITHUB_OUTPUT
58+
59+ - name : Determine final version
60+ id : final_version
61+ env :
62+ BASE_VERSION : ${{ steps.base_version.outputs.base_version }}
63+ STAGING_LABEL : ${{ contains(github.event.pull_request.labels.*.name, 'Version Update - Staging') }}
64+ SHA_SHORT : ${{ steps.sha.outputs.sha_short }}
65+ run : |
66+ if [[ "$STAGING_LABEL" == "true" ]]; then
67+ FINAL_VERSION="${BASE_VERSION}-${SHA_SHORT}"
68+ else
69+ FINAL_VERSION="${BASE_VERSION}"
70+ fi
71+ echo "Final version to set: $FINAL_VERSION"
72+ echo "final_version=$FINAL_VERSION" >> $GITHUB_OUTPUT
2373
24- - name : Check for New Release label
74+ - name : Update Maven Version
2575 run : |
26- echo "New Release label detected on PR #${{ github.event.pull_request.number }}"
27- echo "Version number: ${{ steps.extract_version.outputs.new_version }}"
28-
29- # Mettez ici vos commandes ou scripts à exécuter
30- mvn versions:set -DnewVersion='${{ steps.extract_version.outputs.new_version }}' -DprocessAllModules
31- mvn versions:set-property -Dproperty=kraftwerk.version -DnewVersion='${{ steps.extract_version.outputs.new_version }}'
76+ mvn versions:set -DnewVersion="${{ steps.final_version.outputs.final_version }}" -DprocessAllModules
3277 mvn versions:commit
33- git config --global user.name 'github-actions'
34- git config --global user.email 'github-actions@github.com'
35- git commit -m "Update version - auto" --all
36- git push
78+
79+ - name : Commit and Push
80+ env :
81+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
82+ run : |
83+ git config user.name 'github-actions'
84+ git config user.email 'github-actions@github.com'
85+ git commit -am "chore: update version to ${{ steps.final_version.outputs.final_version }}" || echo "No changes to commit"
86+ git push
0 commit comments