Skip to content

Commit

Permalink
chore: automated release with version commits
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 committed Oct 16, 2024
1 parent ba26e85 commit e4895d2
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 13 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/maven.yml → .github/workflows/build.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
84 changes: 84 additions & 0 deletions .github/workflows/patch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Patch

on:
workflow_dispatch:
inputs:
releaseVersion:
description: Patch version (vX.X)
required: true

jobs:
patch:
runs-on: ubuntu-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17

- uses: actions/create-github-app-token@v1
id: app-token
name: Generate app token
with:
app-id: ${{ vars.GRIDSUITE_ACTIONS_APPID }}
private-key: ${{ secrets.GRIDSUITE_ACTIONS_SECRET }}

- name: Checkout sources
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}

- name: Checkout on existing release branch
run: |
git checkout release/${{ github.event.inputs.releaseVersion }}
- name: Extract tag versions
run: |
lastTag=$(git describe --tags --abbrev=0)
regex="v([0-9]+).([0-9]+).([0-9]+)"
if [[ $lastTag =~ $regex ]]
then
major=${BASH_REMATCH[1]}
minor=${BASH_REMATCH[2]}
patch=${BASH_REMATCH[3]}
((++patch))
echo "GITHUB_MAJOR_VERSION=$major" >> $GITHUB_ENV
echo "GITHUB_MINOR_VERSION=$minor" >> $GITHUB_ENV
echo "GITHUB_PATCH_VERSION=$patch" >> $GITHUB_ENV
echo "GITHUB_SHORT_VERSION=$major.$minor.$patch" >> $GITHUB_ENV
fi
- name: Change Maven version to release version
run: mvn --batch-mode versions:set -DgenerateBackupPoms=false -DnewVersion=${{ env.GITHUB_SHORT_VERSION }}

- 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:${{ env.GITHUB_SHORT_VERSION }}
-Djib.to.auth.username=gridsuiteci
-Djib.to.auth.password=${{ secrets.DOCKERHUB_TOKEN }}
- name: Commit and tag release version
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Patched release v${{ env.GITHUB_SHORT_VERSION }}"
git tag v${{ env.GITHUB_SHORT_VERSION }}
git push origin release/v${{ env.GITHUB_MAJOR_VERSION }}.${{ env.GITHUB_MINOR_VERSION }}
git push origin v${{ env.GITHUB_SHORT_VERSION }}
96 changes: 96 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Release

on:
workflow_dispatch:
inputs:
releaseVersion:
description: Release version (vX.X)
required: true
commitSha:
description: SHA of the commit from where to release
required: true

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17

- uses: actions/create-github-app-token@v1
id: app-token
name: Generate app token
with:
app-id: ${{ vars.GRIDSUITE_ACTIONS_APPID }}
private-key: ${{ secrets.GRIDSUITE_ACTIONS_SECRET }}

- name: Checkout sources
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}

- name: Extract tag versions
run: |
regex="v([0-9]+).([0-9]+)"
if [[ ${{ github.event.inputs.releaseVersion }} =~ $regex ]]
then
echo "GITHUB_MAJOR_VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
echo "GITHUB_MINOR_VERSION=${BASH_REMATCH[2]}" >> $GITHUB_ENV
echo "GITHUB_SHORT_VERSION=${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.0" >> $GITHUB_ENV
fi
- name: Checkout with new branch
run: |
git checkout -b release/v${{ env.GITHUB_MAJOR_VERSION }}.${{ env.GITHUB_MINOR_VERSION }} ${{ github.event.inputs.commitSha }}
- name: Change Maven version to release version
run: mvn --batch-mode versions:set -DgenerateBackupPoms=false -DnewVersion=${{ env.GITHUB_SHORT_VERSION }}

- 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:${{ env.GITHUB_SHORT_VERSION }}
-Djib.to.auth.username=gridsuiteci
-Djib.to.auth.password=${{ secrets.DOCKERHUB_TOKEN }}
- name: Commit and tag release version
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Release v${{ env.GITHUB_SHORT_VERSION }}"
git tag v${{ env.GITHUB_SHORT_VERSION }}
git push origin release/v${{ env.GITHUB_MAJOR_VERSION }}.${{ env.GITHUB_MINOR_VERSION }}
git push origin v${{ env.GITHUB_SHORT_VERSION }}
- name: Increment minor version
run: |
minor=${{ env.GITHUB_MINOR_VERSION }}
((minor++))
echo "GITHUB_MINOR_VERSION=${minor}" >> $GITHUB_ENV
- name: Update SNAPSHOT version on main
run: |
git checkout main
git pull
mvn --batch-mode versions:set -DgenerateBackupPoms=false -DnewVersion=${{ env.GITHUB_MAJOR_VERSION }}.${{ env.GITHUB_MINOR_VERSION }}.0-SNAPSHOT
git add .
git commit -m "Update SNAPSHOT version to v${{ env.GITHUB_MAJOR_VERSION }}.${{ env.GITHUB_MINOR_VERSION }}.0"
git push

0 comments on commit e4895d2

Please sign in to comment.