Skip to content

Commit a879ae2

Browse files
chore: make workflows generic
Signed-off-by: Joris Mancini <[email protected]>
1 parent b70457c commit a879ae2

File tree

6 files changed

+377
-245
lines changed

6 files changed

+377
-245
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
sonarOrganization:
5+
required: true
6+
type: string
7+
sonarProjectKey:
8+
required: true
9+
type: string
10+
dockerImage:
11+
required: true
12+
type: string
13+
dockerUsername:
14+
required: true
15+
type: string
16+
eventType:
17+
required: true
18+
type: string
19+
secrets:
20+
sonar-token:
21+
required: true
22+
docker-token:
23+
required: true
24+
repo-token:
25+
required: true
26+
27+
jobs:
28+
build:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Set up JDK 17
32+
uses: actions/setup-java@v1
33+
with:
34+
java-version: 17
35+
36+
- name: Checkout sources
37+
uses: actions/checkout@v1
38+
39+
- name: Build with Maven
40+
run: mvn --batch-mode -Pjacoco verify
41+
42+
- name: Run SonarCloud analysis
43+
run: >
44+
mvn --batch-mode -DskipTests sonar:sonar
45+
-Dsonar.host.url=https://sonarcloud.io
46+
-Dsonar.organization=${{ inputs.sonarOrganization }}
47+
-Dsonar.projectKey=${{ inputs.sonarProjectKey }}
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
SONAR_TOKEN: ${{ secrets.sonar-token }}
51+
52+
- name: Build Docker image - Main
53+
if: github.ref == 'refs/heads/main'
54+
run: >
55+
mvn --batch-mode deploy -DskipTests -Dmaven.install.skip -Dmaven.deploy.skip -Dpowsybl.docker.deploy
56+
-Djib.httpTimeout=60000
57+
-Djib.to.image=${{ inputs.dockerImage }}
58+
-Djib.to.auth.username=${{ inputs.dockerUsername }}
59+
-Djib.to.auth.password=${{ secrets.docker-token }}
60+
61+
- name: Broadcast update event
62+
if: github.ref == 'refs/heads/main'
63+
uses: gridsuite/broadcast-event@main
64+
with:
65+
token: ${{ secrets.repo-token }}
66+
event-type: ${{ inputs.eventType }}

.github/workflows/build.yml

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,14 @@ on:
88

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

.github/workflows/patch.yml

Lines changed: 13 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -8,101 +8,17 @@ on:
88
required: true
99

1010
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
11+
run-patch:
12+
uses: ./.github/workflows/patch-generic.yml
13+
with:
14+
githubappId: ${{ vars.GRIDSUITE_ACTIONS_APPID }}
15+
sonarOrganization: gridsuite
16+
sonarProjectKey: gridsuite_spreadsheet-config-server
17+
dockerImage: docker.io/gridsuite/spreadsheet-config-server
18+
dockerUsername: gridsuiteci
19+
releaseVersion: ${{ github.event.inputs.releaseVersion }}
20+
secrets:
21+
githubappPrivateKey: ${{ secrets.GRIDSUITE_ACTIONS_SECRET }}
22+
sonar-token: ${{ secrets.SONAR_TOKEN }}
23+
docker-token: ${{ secrets.DOCKERHUB_TOKEN }}
1824

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: Parse release version
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 }}

0 commit comments

Comments
 (0)