1+ name : Scheduled version update
2+
3+ permissions :
4+ contents : write
5+ pull-requests : write
6+
7+ on :
8+ schedule :
9+ - cron : 30 7 * * 4
10+ workflow_dispatch :
11+
12+ jobs :
13+ update-version :
14+ runs-on : ubuntu-latest
15+ steps :
16+ - name : Checkout
17+ uses : actions/checkout@v5
18+ with :
19+ ref : main
20+ fetch-depth : 0
21+
22+ - name : Get last commit SHA
23+ id : current_sha
24+ run : |
25+ CURRENT_SHA=$(git log -n 1 --pretty=format:"%H")
26+ echo "last commit SHA : $CURRENT_SHA"
27+ echo "current_sha=$CURRENT_SHA" >> $GITHUB_OUTPUT
28+
29+ - name : Get last version tag and SHA
30+ id : last_tag
31+ run : |
32+ LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
33+ TAG_SHA=$(git rev-list -n 1 "$LAST_TAG")
34+ echo "Last version SHA : $TAG_SHA"
35+ echo "tag_sha=$TAG_SHA" >> $GITHUB_OUTPUT
36+ echo "Last version tag : $LAST_TAG"
37+ echo "last_tag=$LAST_TAG" >> $GITHUB_OUTPUT
38+
39+ - name : Compare SHAs
40+ id : compare
41+ run : |
42+ if [ "${{ steps.current_sha.outputs.current_sha }}" = "${{ steps.last_tag.outputs.tag_sha }}" ]; then
43+ echo "No new commit since version. Exiting."
44+ exit 0
45+ fi
46+
47+ - name : Get version from changelog
48+ id : changelog_version
49+ run : |
50+ FILE_VERSION=$(grep -m1 '^## ' CHANGELOG.md | sed -E 's/^## ([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
51+ echo "Last version in changelog : $FILE_VERSION"
52+ echo "file_version=$FILE_VERSION" >> $GITHUB_OUTPUT
53+
54+ - name : Determine version to use
55+ id : determine_version
56+ run : |
57+ RAW_TAG="${{ steps.last_tag.outputs.last_tag }}"
58+ RAW_TAG="${RAW_TAG#v}"
59+
60+ IFS='.' read -r MAJOR LAST_MINOR LAST_PATCH <<< "$RAW_TAG"
61+ IFS='.' read -r FILE_MAJOR FILE_MINOR FILE_PATCH <<< "${{ steps.changelog_version.outputs.file_version }}"
62+
63+ if [ "$FILE_MAJOR" -gt "$MAJOR" ] || \
64+ [ "$FILE_MAJOR" -eq "$MAJOR" -a "$FILE_MINOR" -gt "$LAST_MINOR" ] || \
65+ [ "$FILE_MAJOR" -eq "$MAJOR" -a "$FILE_MINOR" -eq "$LAST_MINOR" -a "$FILE_PATCH" -gt "$LAST_PATCH" ]; then
66+ NEW_VERSION="${{ steps.changelog_version.outputs.file_version }}"
67+ else
68+ PATCH=$((LAST_PATCH + 1))
69+ NEW_VERSION="$MAJOR.$LAST_MINOR.$PATCH"
70+ fi
71+ echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
72+
73+ - name : Update files and commit
74+ run : |
75+ #Update poms
76+ mvn versions:set -DnewVersion="${{ steps.determine_version.outputs.new_version }}" -DprocessAllModules
77+ mvn versions:commit
78+
79+ # Update TODO to today in changelog
80+ TODAY=$(date +%Y-%m-%d)
81+ if grep -q '\[TODO\]' CHANGELOG.md; then
82+ sed -i "0,/\[TODO\]/s/\[TODO\]/[$TODAY]/" CHANGELOG.md
83+ git add CHANGELOG.md
84+ else
85+ echo "No change done in changelog"
86+ fi
87+
88+ git config user.name 'github-actions'
89+ git config user.email 'github-actions@github.com'
90+ git commit -am "chore: update version to ${{ steps.determine_version.outputs.new_version }}" || echo "No changes to commit"
91+
92+ - name : Create Pull Request
93+ id : create_pr
94+ uses : peter-evans/create-pull-request@v7
95+ with :
96+ token : ${{ secrets.GITHUB_TOKEN }}
97+ base : " main"
98+ commit-message : " Update for release ${{ steps.determine_version.outputs.new_version }}"
99+ branch : " update-version-${{ steps.determine_version.outputs.new_version }}"
100+ branch-suffix : timestamp
101+ title : " Auto release ${{ steps.determine_version.outputs.new_version }}"
102+ body : " This PR updates the application to version ${{ steps.determine_version.outputs.new_version }}."
103+ labels : " Version Update - Prod"
104+
105+ - name : Merge pull request
106+ run : gh pr merge --merge --auto "${{ steps.create_pr.outputs.pull-request-number }}"
107+ env :
108+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
109+
110+ wait-for-merge :
111+ runs-on : ubuntu-latest
112+ needs : update-version
113+ steps :
114+ - uses : actions/checkout@v5
115+ - name : Wait for merged version commit
116+ run : |
117+ echo "Fetching main branch..."
118+ git fetch origin main
119+
120+ while true; do
121+ LAST_VERSION_COMMIT=$(git log origin/main --pretty=format:"%H %s" | grep -v 'Merge pull request' | grep 'chore: update version to' | head -n1 | awk '{print $1}')
122+ if [ -n "$LAST_VERSION_COMMIT" ]; then
123+ echo "Found version commit: $LAST_VERSION_COMMIT"
124+ break
125+ else
126+ echo "Version commit not yet merged, sleeping 10s..."
127+ sleep 10
128+ git fetch origin main
129+ fi
130+ done
131+
132+ launch-create-release-workflow :
133+ needs : wait-for-merge
134+ uses : ./.github/workflows/create-release.yaml
0 commit comments