1+ name : Release Pipeline
2+
3+ on :
4+ push :
5+ branches :
6+ - ' release/**'
7+
8+ jobs :
9+ release :
10+ runs-on : ubuntu-latest
11+
12+ steps :
13+ - name : Checkout code
14+ uses : actions/checkout@v3
15+ with :
16+ fetch-depth : 0 # Needed to push tags & branches
17+
18+ - name : Set up JDK 21
19+ uses : actions/setup-java@v3
20+ with :
21+ java-version : ' 21'
22+ distribution : ' temurin'
23+
24+ - name : Extract release version from branch name
25+ id : vars
26+ run : |
27+ # Assuming branch name like release/1.2.3
28+ echo "RELEASE_VERSION=${GITHUB_REF#refs/heads/release/}" >> $GITHUB_OUTPUT
29+
30+ - name : Build with Maven
31+ run : mvn clean package -DskipTests
32+
33+ - name : Create and push Git tag for release
34+ env :
35+ RELEASE_VERSION : ${{ steps.vars.outputs.RELEASE_VERSION }}
36+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
37+ run : |
38+ git config user.name "github-actions[bot]"
39+ git config user.email "github-actions[bot]@users.noreply.github.com"
40+ git tag -a "v$RELEASE_VERSION" -m "Release $RELEASE_VERSION"
41+ git push origin "v$RELEASE_VERSION"
42+
43+ - name : Checkout master branch
44+ run : git checkout master
45+
46+ - name : Update master branch to latest release tag
47+ env :
48+ RELEASE_VERSION : ${{ steps.vars.outputs.RELEASE_VERSION }}
49+ run : |
50+ git reset --hard "v$RELEASE_VERSION"
51+ git push origin master --force
52+
53+ - name : Checkout develop branch
54+ run : git checkout develop
55+
56+ - name : Bump develop version to next SNAPSHOT
57+ env :
58+ RELEASE_VERSION : ${{ steps.vars.outputs.RELEASE_VERSION }}
59+ run : |
60+ # Extract major.minor.patch, then increment patch + add SNAPSHOT
61+ IFS='.' read -r major minor patch <<< "${RELEASE_VERSION}"
62+ next_patch=$((patch + 1))
63+ next_snapshot="${major}.${minor}.${next_patch}-SNAPSHOT"
64+
65+ echo "Next develop version: $next_snapshot"
66+
67+ # Update version in pom.xml or your version file
68+ mvn versions:set -DnewVersion=$next_snapshot
69+ mvn versions:commit
70+
71+ git config user.name "github-actions[bot]"
72+ git config user.email "github-actions[bot]@users.noreply.github.com"
73+
74+ git add pom.xml
75+ git commit -m "Bump develop version to $next_snapshot"
76+ git push origin develop
77+
78+ - name : Build and push Docker images
79+ env :
80+ RELEASE_VERSION : ${{ steps.vars.outputs.RELEASE_VERSION }}
81+ GHCR_TOKEN : ${{ secrets.GHCR_TOKEN }}
82+ run : |
83+ echo "${GHCR_TOKEN}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
84+
85+ for service in user-service order-service product-service; do
86+ docker build -t ghcr.io/${{ github.repository_owner }}/$service:$RELEASE_VERSION ./$service
87+ docker push ghcr.io/${{ github.repository_owner }}/$service:$RELEASE_VERSION
88+ done
0 commit comments