Skip to content

Commit

Permalink
chore: integrate automated release in github workflows (#2)
Browse files Browse the repository at this point in the history
Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
  • Loading branch information
TheMaskedTurtle authored Oct 7, 2024
1 parent ba26e85 commit 520c76b
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 13 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
branches:
- 'main'
tags:
- 'v[0-9]*'
pull_request:

jobs:
Expand All @@ -23,7 +21,7 @@ jobs:
uses: actions/checkout@v1

- name: Build with Maven
run: mvn --batch-mode -P jacoco verify
run: mvn --batch-mode -Pjacoco verify

- name: Run SonarCloud analysis
run: >
Expand All @@ -43,16 +41,7 @@ jobs:
-Djib.to.image=docker.io/gridsuite/spreadsheet-config-server
-Djib.to.auth.username=gridsuiteci
-Djib.to.auth.password=${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker image - Tag
if: startsWith(github.ref, 'refs/tags/')
run: >
mvn --batch-mode deploy -DskipTests -Dmaven.install.skip -Dmaven.deploy.skip -Dpowsybl.docker.deploy
-Djib.httpTimeout=60000
-Djib.to.image=docker.io/gridsuite/spreadsheet-config-server:${GITHUB_REF_NAME#v}
-Djib.to.auth.username=gridsuiteci
-Djib.to.auth.password=${{ secrets.DOCKERHUB_TOKEN }}
- name: Broadcast update event
if: github.ref == 'refs/heads/main'
uses: gridsuite/broadcast-event@main
Expand Down
99 changes: 99 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Release

on:
push:
tags:
- 'v[0-9]*'

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17

- name: Checkout sources
uses: actions/checkout@v1

- name: Remove original tag
run: |
git tag -d ${{ github.ref_name }}
git push origin :refs/tags/${{ github.ref_name }}
- name: Extract tag versions
run: |
regex="v([0-9]+).([0-9]+).([0-9]+)"
if [[ $1 =~ $regex ]]
then
echo "GITHUB_MAJOR_VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
echo "GITHUB_MINOR_VERSION=${BASH_REMATCH[2]}" >> $GITHUB_ENV
echo "GITHUB_PATCH_VERSION=${BASH_REMATCH[3]}" >> $GITHUB_ENV
fi
- name: Change Maven version to release version
run: mvn --batch-mode versions:set -DgenerateBackupPoms=false -DnewVersion=${{ env.GITHUB_MAJOR_VERSION }}.${{ env.GITHUB_MINOR_VERSION }}.${{ env.GITHUB_PATCH_VERSION }}

- name: Commit and tag release version
uses: stefanzweifel/git-auto-commit-action@v5.0.1
with:
branch: release-${{ github.ref_name }}
create_branch: true
commit_message: Prepare release ${{ github.ref_name }}
tagging_message: ${{ github.ref_name }}

- name: Build with Maven
run: mvn --batch-mode -Pjacoco verify

- name: Run SonarCloud analysis
run: >
mvn --batch-mode -DskipTests sonar:sonar
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.organization=gridsuite
-Dsonar.projectKey=gridsuite_spreadsheet-config-server
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: Build Docker image
run: >
mvn --batch-mode deploy -DskipTests -Dmaven.install.skip -Dmaven.deploy.skip -Dpowsybl.docker.deploy
-Djib.httpTimeout=60000
-Djib.to.image=docker.io/gridsuite/spreadsheet-config-server:${GITHUB_REF_NAME#v}
-Djib.to.auth.username=gridsuiteci
-Djib.to.auth.password=${{ secrets.DOCKERHUB_TOKEN }}
- name: Increment minor version
run: |
minor=${{ env.GITHUB_MINOR_VERSION }}
((minor++))
echo "GITHUB_MINOR_VERSION=${minor}" >> $GITHUB_ENV
- name: Change Maven version to next version
run: mvn --batch-mode versions:set -DgenerateBackupPoms=false -DnewVersion=${{ env.GITHUB_MAJOR_VERSION }}.${{ env.GITHUB_MINOR_VERSION }}.${{ env.GITHUB_PATCH_VERSION }}-SNAPSHOT

- name: Commit next version
uses: stefanzweifel/git-auto-commit-action@v5.0.1
with:
branch: release-${{ github.ref_name }}
commit_message: Prepare next release v${{ env.GITHUB_MAJOR_VERSION }}.${{ env.GITHUB_MINOR_VERSION }}.${{ env.GITHUB_PATCH_VERSION }}
skip_fetch: true
skip_checkout: true

- name: Merge automatically into main branch
uses: devmasx/merge-branch@v1.4.0
with:
type: now
from_branch: release-${{ github.ref_name }}
target_branch: main
message: Automatic merge after release ${{ github.ref_name }}
github_token: ${{ secrets.REPO_ACCESS_TOKEN }}

- name: Delete merged branch
uses: dawidd6/action-delete-branch@v3.1.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branches: release-${{ github.ref_name }}

0 comments on commit 520c76b

Please sign in to comment.