-
Notifications
You must be signed in to change notification settings - Fork 0
223 lines (220 loc) · 7.55 KB
/
release-app.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: Release of application
defaults:
run:
shell: bash
on:
workflow_dispatch:
inputs:
releaseVersion:
description: "Default version to use when preparing a release."
required: true
default: "X.Y.Z"
developmentVersion:
description: "Default version to use for new local working copy."
required: true
default: "X.Y.Z-SNAPSHOT"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
setup_new_version:
name: Update version to ${{ github.event.inputs.releaseVersion }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Update pom.xml to releaseVersion
run: |
mvn -B versions:set -DnewVersion=${{ github.event.inputs.releaseVersion }} -DgenerateBackupPoms=false -f ./code/pom.xml
- name: Update frontend version
working-directory: ./code/gms-frontend
run: |
npm version ${{github.event.inputs.releaseVersion}}
- name: Commit version change
run: |
git config --global user.name ${{ secrets.GH_USERNAME }}
git config --global user.email ${{ secrets.GH_EMAIL }}
git commit -am "[ci-skip] Version updated to ${{ github.event.inputs.releaseVersion }}"
git push
analize_backend:
name: Backend code analysis
runs-on: ubuntu-latest
needs: [setup_new_version]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Pull recent changes
run: |
git pull
- name: Maven verify
working-directory: ./code/gms-backend
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn clean verify
analize_frontend:
name: Frontend code analysis
runs-on: ubuntu-latest
needs: [setup_new_version]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Pull recent changes
run: |
git pull
- name: Build with NPM
working-directory: ./code/gms-frontend
run: npm install
- name: Run tests
working-directory: ./code/gms-frontend
run: npm run test
build:
name: Build production artifact
runs-on: ubuntu-latest
# if: false
needs: [analize_backend, analize_frontend]
env:
working-directory: ./code
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Pull recent changes
run: |
git pull
- name: Build
run: mvn clean install -Pbuild-prod --file pom.xml -DskipTests=true
working-directory: ${{env.working-directory}}
- name: Temporarily save jar artifact
uses: actions/upload-artifact@v4
with:
name: gms-app
path: ${{ github.workspace }}/code/gms-backend/target/gms-app.jar
retention-days: 1
- name: Temporarily save Dockerfile
uses: actions/upload-artifact@v4
with:
name: Dockerfile
path: ${{ github.workspace }}/code/gms-backend/Dockerfile
retention-days: 1
- name: Temporarily save entrypoint.sh
uses: actions/upload-artifact@v4
with:
name: entrypointSh
path: ${{ github.workspace }}/code/gms-backend/entrypoint.sh
retention-days: 1
deploy:
name: 'Deploy to GHCR'
runs-on : ubuntu-latest
needs: build
# if: false
steps:
- name: Log in to the Container registry
uses: docker/login-action@master
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@master
with:
images: ${{ env.REGISTRY }}/peter-szrnka/give-my-secret
- uses: actions/[email protected]
with:
name: gms-app
path: ./
- uses: actions/[email protected]
with:
name: Dockerfile
path: ./
- uses: actions/[email protected]
with:
name: entrypointSh
path: ./
- name: Build Docker by Dockerfile
run: docker build --build-arg JAR_FILE=./gms-app.jar -t peter-szrnka/give-my-secret -f ./Dockerfile .
- name: Tag the image
run: docker image tag peter-szrnka/give-my-secret ${{ env.REGISTRY }}/peter-szrnka/give-my-secret:${{ github.event.inputs.releaseVersion }}
- name: Tag the latest image
run: docker image tag peter-szrnka/give-my-secret ${{ env.REGISTRY }}/peter-szrnka/give-my-secret:latest
- name: Docker push ${{ github.event.inputs.releaseVersion }}
run: docker push ${{ env.REGISTRY }}/peter-szrnka/give-my-secret:${{ github.event.inputs.releaseVersion }}
- name: Docker push latest
run: docker push ${{ env.REGISTRY }}/peter-szrnka/give-my-secret:latest
update_version:
name: Update version to ${{ github.event.inputs.developmentVersion }}
runs-on: ubuntu-latest
# if: false
needs: [deploy]
env:
working-directory: ./code
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Pull recent changes
run: |
git pull
- name: Update backend version to ${{ github.event.inputs.developmentVersion }}
run: |
mvn -B versions:set -DnewVersion=${{ github.event.inputs.developmentVersion }} -DgenerateBackupPoms=false -f ${{ github.workspace }}/code/pom.xml
- name: Update frontend version to ${{ github.event.inputs.developmentVersion }}
working-directory: ./code/gms-frontend
run: |
npm version ${{github.event.inputs.developmentVersion}}
- name: Commit version change
run: |
git config --global user.name ${{ secrets.GH_USERNAME }}
git config --global user.email ${{ secrets.GH_EMAIL }}
git commit -am "[ci-skip] Version updated to ${{ github.event.inputs.developmentVersion }}"
git push