From 487e3a4cff83218d9a64ea2f9975daf5b688a15a Mon Sep 17 00:00:00 2001 From: Joris Mancini Date: Mon, 7 Oct 2024 15:33:57 +0200 Subject: [PATCH] chore: integrate automated release in github workflows Signed-off-by: Joris Mancini --- .github/workflows/maven.yml | 15 +----- .github/workflows/release.yml | 99 +++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9b60eb4..9e5ca26 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -4,8 +4,6 @@ on: push: branches: - 'main' - tags: - - 'v[0-9]*' pull_request: jobs: @@ -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: > @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..068020a --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }}