Skip to content

Commit 319ac27

Browse files
chore: automated release with version commits
Signed-off-by: Joris Mancini <[email protected]>
1 parent ba26e85 commit 319ac27

File tree

3 files changed

+235
-13
lines changed

3 files changed

+235
-13
lines changed

.github/workflows/maven.yml renamed to .github/workflows/build.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ on:
44
push:
55
branches:
66
- 'main'
7-
tags:
8-
- 'v[0-9]*'
97
pull_request:
108

119
jobs:
@@ -23,7 +21,7 @@ jobs:
2321
uses: actions/checkout@v1
2422

2523
- name: Build with Maven
26-
run: mvn --batch-mode -P jacoco verify
24+
run: mvn --batch-mode -Pjacoco verify
2725

2826
- name: Run SonarCloud analysis
2927
run: >
@@ -43,16 +41,7 @@ jobs:
4341
-Djib.to.image=docker.io/gridsuite/spreadsheet-config-server
4442
-Djib.to.auth.username=gridsuiteci
4543
-Djib.to.auth.password=${{ secrets.DOCKERHUB_TOKEN }}
46-
47-
- name: Build Docker image - Tag
48-
if: startsWith(github.ref, 'refs/tags/')
49-
run: >
50-
mvn --batch-mode deploy -DskipTests -Dmaven.install.skip -Dmaven.deploy.skip -Dpowsybl.docker.deploy
51-
-Djib.httpTimeout=60000
52-
-Djib.to.image=docker.io/gridsuite/spreadsheet-config-server:${GITHUB_REF_NAME#v}
53-
-Djib.to.auth.username=gridsuiteci
54-
-Djib.to.auth.password=${{ secrets.DOCKERHUB_TOKEN }}
55-
44+
5645
- name: Broadcast update event
5746
if: github.ref == 'refs/heads/main'
5847
uses: gridsuite/broadcast-event@main

.github/workflows/patch.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Patch
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
releaseVersion:
7+
description: Patch version (vX.X)
8+
required: true
9+
10+
jobs:
11+
patch:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Set up JDK 17
15+
uses: actions/setup-java@v1
16+
with:
17+
java-version: 17
18+
19+
- uses: actions/create-github-app-token@v1
20+
id: app-token
21+
name: Generate app token
22+
with:
23+
app-id: ${{ vars.GRIDSUITE_ACTIONS_APPID }}
24+
private-key: ${{ secrets.GRIDSUITE_ACTIONS_SECRET }}
25+
26+
- name: Checkout sources
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
token: ${{ steps.app-token.outputs.token }}
31+
32+
- name: Extract tag versions
33+
run: |
34+
regex="^v([0-9]+)\.([0-9]+)$"
35+
if [[ ${{ github.event.inputs.releaseVersion }} =~ $regex ]]
36+
then
37+
echo Release version matches vX.X format
38+
else
39+
echo ERROR: release version should match the format vX.X
40+
exit 1
41+
fi
42+
43+
- name: Check if release already exists
44+
run: |
45+
if git ls-remote --quiet --exit-code origin refs/heads/release-${{ github.event.inputs.releaseVersion }} >/dev/null 2>&1
46+
then
47+
echo "Release ${{ github.event.inputs.releaseVersion }} already exists, patch will be perfomed"
48+
else
49+
echo "Release ${{ github.event.inputs.releaseVersion }} doesn't exist, patch cannot be performed"
50+
exit 1
51+
fi
52+
53+
- name: Checkout on existing release branch
54+
run: |
55+
git checkout release-${{ github.event.inputs.releaseVersion }}
56+
57+
- name: Extract tag versions
58+
run: |
59+
lastTag=$(git describe --tags --abbrev=0)
60+
regex="^v([0-9]+)\.([0-9]+)\.([0-9]+)$"
61+
if [[ $lastTag =~ $regex ]]
62+
then
63+
major=${BASH_REMATCH[1]}
64+
minor=${BASH_REMATCH[2]}
65+
patch=${BASH_REMATCH[3]}
66+
((++patch))
67+
echo "GITHUB_MAJOR_VERSION=$major" >> $GITHUB_ENV
68+
echo "GITHUB_MINOR_VERSION=$minor" >> $GITHUB_ENV
69+
echo "GITHUB_PATCH_VERSION=$patch" >> $GITHUB_ENV
70+
echo "GITHUB_SHORT_VERSION=$major.$minor.$patch" >> $GITHUB_ENV
71+
else
72+
echo "ERROR: last tag $lastTag does not match required format vX.X.X"
73+
exit 1
74+
fi
75+
76+
- name: Change Maven version to release version
77+
run: mvn --batch-mode versions:set -DgenerateBackupPoms=false -DnewVersion=${{ env.GITHUB_SHORT_VERSION }}
78+
79+
- name: Build with Maven
80+
run: mvn --batch-mode -Pjacoco verify
81+
82+
- name: Run SonarCloud analysis
83+
run: >
84+
mvn --batch-mode -DskipTests sonar:sonar
85+
-Dsonar.host.url=https://sonarcloud.io
86+
-Dsonar.organization=gridsuite
87+
-Dsonar.projectKey=gridsuite_spreadsheet-config-server
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
91+
92+
- name: Build Docker image
93+
run: >
94+
mvn --batch-mode deploy -DskipTests -Dmaven.install.skip -Dmaven.deploy.skip -Dpowsybl.docker.deploy
95+
-Djib.httpTimeout=60000
96+
-Djib.to.image=docker.io/gridsuite/spreadsheet-config-server:${{ env.GITHUB_SHORT_VERSION }}
97+
-Djib.to.auth.username=gridsuiteci
98+
-Djib.to.auth.password=${{ secrets.DOCKERHUB_TOKEN }}
99+
100+
- name: Commit and tag release version
101+
run: |
102+
git config --global user.name "github-actions[bot]"
103+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
104+
git add .
105+
git commit -m "Patched release v${{ env.GITHUB_SHORT_VERSION }}"
106+
git tag v${{ env.GITHUB_SHORT_VERSION }}
107+
git push origin release-v${{ env.GITHUB_MAJOR_VERSION }}.${{ env.GITHUB_MINOR_VERSION }}
108+
git push origin v${{ env.GITHUB_SHORT_VERSION }}

.github/workflows/release.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
releaseVersion:
7+
description: Release version (vX.X)
8+
required: true
9+
commitSha:
10+
description: SHA of the commit from where to release
11+
required: true
12+
13+
jobs:
14+
release:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v1
19+
with:
20+
java-version: 17
21+
22+
- uses: actions/create-github-app-token@v1
23+
id: app-token
24+
name: Generate app token
25+
with:
26+
app-id: ${{ vars.GRIDSUITE_ACTIONS_APPID }}
27+
private-key: ${{ secrets.GRIDSUITE_ACTIONS_SECRET }}
28+
29+
- name: Checkout sources
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
token: ${{ steps.app-token.outputs.token }}
34+
35+
- name: Extract tag versions
36+
run: |
37+
regex="^v([0-9]+)\.([0-9]+)$"
38+
if [[ ${{ github.event.inputs.releaseVersion }} =~ $regex ]]
39+
then
40+
echo "GITHUB_MAJOR_VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
41+
echo "GITHUB_MINOR_VERSION=${BASH_REMATCH[2]}" >> $GITHUB_ENV
42+
echo "GITHUB_SHORT_VERSION=${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.0" >> $GITHUB_ENV
43+
else
44+
echo ERROR: release version should match the format vX.X
45+
exit 1
46+
fi
47+
48+
- name: Check if release already exists
49+
run: |
50+
if git ls-remote --quiet --exit-code origin refs/heads/release-${{ github.event.inputs.releaseVersion }} >/dev/null 2>&1
51+
then
52+
echo "ERROR: Release ${{ github.event.inputs.releaseVersion }} already exists"
53+
exit 1
54+
else
55+
echo "Release ${{ github.event.inputs.releaseVersion }} doesn't exist, it will be performed"
56+
fi
57+
58+
- name: Checkout with new branch
59+
run: |
60+
git checkout -b release-v${{ env.GITHUB_MAJOR_VERSION }}.${{ env.GITHUB_MINOR_VERSION }} ${{ github.event.inputs.commitSha }}
61+
62+
- name: Change Maven version to release version
63+
run: mvn --batch-mode versions:set -DgenerateBackupPoms=false -DnewVersion=${{ env.GITHUB_SHORT_VERSION }}
64+
65+
- name: Build with Maven
66+
run: mvn --batch-mode -Pjacoco verify
67+
68+
- name: Run SonarCloud analysis
69+
run: >
70+
mvn --batch-mode -DskipTests sonar:sonar
71+
-Dsonar.host.url=https://sonarcloud.io
72+
-Dsonar.organization=gridsuite
73+
-Dsonar.projectKey=gridsuite_spreadsheet-config-server
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
77+
78+
- name: Build Docker image
79+
run: >
80+
mvn --batch-mode deploy -DskipTests -Dmaven.install.skip -Dmaven.deploy.skip -Dpowsybl.docker.deploy
81+
-Djib.httpTimeout=60000
82+
-Djib.to.image=docker.io/gridsuite/spreadsheet-config-server:${{ env.GITHUB_SHORT_VERSION }}
83+
-Djib.to.auth.username=gridsuiteci
84+
-Djib.to.auth.password=${{ secrets.DOCKERHUB_TOKEN }}
85+
86+
- name: Commit and tag release version
87+
run: |
88+
git config --global user.name "github-actions[bot]"
89+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
90+
git add .
91+
git commit -m "Release v${{ env.GITHUB_SHORT_VERSION }}"
92+
git tag v${{ env.GITHUB_SHORT_VERSION }}
93+
git push origin release-v${{ env.GITHUB_MAJOR_VERSION }}.${{ env.GITHUB_MINOR_VERSION }}
94+
git push origin v${{ env.GITHUB_SHORT_VERSION }}
95+
96+
- name: Checkout main
97+
run: |
98+
git checkout main
99+
git pull
100+
101+
- name: Get current maven version
102+
run: |
103+
echo "CURRENT_MAVEN_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
104+
105+
- name: Extract tag versions
106+
run: |
107+
regex="(.*)-SNAPSHOT"
108+
if [[ ${{ env.CURRENT_MAVEN_VERSION }} =~ $regex ]]
109+
then
110+
echo "CURRENT_RELEASE_VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
111+
fi
112+
113+
- name: Increment minor version
114+
run: |
115+
minor=${{ env.GITHUB_MINOR_VERSION }}
116+
((minor++))
117+
echo "GITHUB_MINOR_VERSION=${minor}" >> $GITHUB_ENV
118+
119+
- name: Update SNAPSHOT version on main
120+
if: env.CURRENT_RELEASE_VERSION == env.GITHUB_SHORT_VERSION
121+
run: |
122+
mvn --batch-mode versions:set -DgenerateBackupPoms=false -DnewVersion=${{ env.GITHUB_MAJOR_VERSION }}.${{ env.GITHUB_MINOR_VERSION }}.0-SNAPSHOT
123+
git add .
124+
git commit -m "Update SNAPSHOT version to v${{ env.GITHUB_MAJOR_VERSION }}.${{ env.GITHUB_MINOR_VERSION }}.0"
125+
git push

0 commit comments

Comments
 (0)