-
Notifications
You must be signed in to change notification settings - Fork 2
279 lines (279 loc) · 9.99 KB
/
build.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: organisaatio
on:
workflow_dispatch:
push:
branches: [master]
pull_request:
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12.14
ports:
- 5433:5432
env:
POSTGRES_USER: postgres
POSTGRES_DB: organisaatio
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: organisaatio-ui/package-lock.json
- uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "corretto"
- uses: szenius/[email protected]
with:
timezoneLinux: "Europe/Helsinki"
- name: Build frontend
working-directory: organisaatio-ui
run: |
npm ci
npm run lint
npm run prettier
CI=true npm run test
npm run build
- uses: gradle/actions/wrapper-validation@v3
- uses: gradle/actions/setup-gradle@v3
- name: Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew clean build
- uses: actions/upload-artifact@v4
with:
name: organisaatio-service-jar
path: organisaatio-service/build/libs/organisaatio-service.jar
cypress:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Cypress coverrage cache
uses: actions/cache@v4
env:
cache-name: cache-cypress-coverage
with:
path: organisaatio-ui/cypress-coverage
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.sha }}
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: organisaatio-ui/package-lock.json
- uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "corretto"
- name: pre scripts
run: |
PGPASSWORD=postgres psql -c 'CREATE DATABASE organisaatio;' -h localhost -U postgres
cd mock-api && npm install && cd -
cd organisaatio-ui && npm ci --force && cd -
- uses: gradle/actions/wrapper-validation@v3
- uses: gradle/actions/setup-gradle@v3
- name: Build backend with no tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew clean build -x test
- name: Run Cypress
run: |
cd mock-api && npm run mock-api &
cd organisaatio-ui && npm run start &
java -jar -Xms2g -Xmx2g -Dspring.config.location=classpath:application.properties,classpath:application-test-envs.properties -Dspring.profiles.active=dev -Dspring.flyway.enabled=true -Durl-virkailija=http://localhost:9000 -Dhost.virkailija=localhost:9000 -Durl-ytj=http://localhost:9000/ytj -Durl-oidservice=http://localhost:9000/oidservice -Dcas.service.organisaatio-service=http://localhost:8080/organisaatio-service-not-available organisaatio-service/build/libs/organisaatio-service.jar &
cd organisaatio-ui && npm run cypress:ci
kill $(jobs -p) || true
playwright:
timeout-minutes: 60
runs-on: ubuntu-latest
services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: organisaatio-ui/package-lock.json
- uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "corretto"
- name: pre scripts
run: |
PGPASSWORD=postgres psql -c 'CREATE DATABASE organisaatio;' -h localhost -U postgres
cd mock-api && npm ci && cd -
cd organisaatio-ui && npm ci --force && cd -
cd playwright && npm ci && npx playwright install --with-deps && cd -
- uses: gradle/actions/wrapper-validation@v3
- uses: gradle/actions/setup-gradle@v3
- name: Build backend with no tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew clean build -x test
- name:
run: |
cd mock-api && npm run mock-api &
cd organisaatio-ui && npm run start &
java -jar -Xms2g -Xmx2g -Dspring.config.location=classpath:application.properties,classpath:application-test-envs.properties -Dspring.profiles.active=dev -Dspring.flyway.enabled=true -Durl-virkailija=http://localhost:9000 -Dhost.virkailija=localhost:9000 -Durl-ytj=http://localhost:9000/ytj -Durl-oidservice=http://localhost:9000/oidservice -Dcas.service.organisaatio-service=http://localhost:8080/organisaatio-service-not-available organisaatio-service/build/libs/organisaatio-service.jar &
while ! nc -z localhost 3003; do
sleep 1; echo "Sleeping 3003"
done
while ! nc -z localhost 8080; do
sleep 1; echo "Sleeping 8080"
done
cd playwright && npx playwright test
kill $(jobs -p) || true
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright/playwright-report/
retention-days: 30
sonarcloud:
needs: [cypress, playwright]
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12.14
ports:
- 5433:5432
env:
POSTGRES_USER: postgres
POSTGRES_DB: organisaatio
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set timezone
uses: szenius/[email protected]
with:
timezoneLinux: "Europe/Helsinki"
- name: Cypress coverrage cache
uses: actions/cache@v4
env:
cache-name: cache-cypress-coverage
with:
path: organisaatio-ui/cypress-coverage
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.sha }}
- uses: actions/setup-java@v4
with:
java-version: 21
distribution: "corretto"
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew build sonarqube
deploy-container:
needs: [cypress, build, playwright]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download organisaatio-service-jar
uses: actions/download-artifact@v4
with:
name: organisaatio-service-jar
- name: Build Docker Conainer
shell: bash
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
git clone https://github.com/Opetushallitus/ci-tools.git
source ci-tools/common/setup-tools.sh
export BASE_IMAGE="baseimage-fatjar-openjdk21:master"
export ARTIFACT_NAME="organisaatio"
cp organisaatio-service.jar $DOCKER_BUILD_DIR/artifact/$ARTIFACT_NAME.jar
cp -vr src/main/resources/oph-configuration $DOCKER_BUILD_DIR/config/
./ci-tools/common/pull-image.sh
./ci-tools/github-build/build-fatjar.sh $ARTIFACT_NAME
./ci-tools/github-build/upload-image.sh $ARTIFACT_NAME
deploy-artifacts:
needs: [build, cypress, playwright]
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "corretto"
- uses: gradle/actions/wrapper-validation@v3
- uses: gradle/actions/setup-gradle@v3
- name: Publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ORG_GRADLE_PROJECT_sadeRepositoryUsername: ${{ secrets.ARTIFACTORY_USERNAME }}
ORG_GRADLE_PROJECT_sadeRepositoryPassword: ${{ secrets.ARTIFACTORY_PASSWORD }}
run: ./gradlew publish -PversionSuffix=.RELEASE
deploy-artifacts-snapshot:
needs: [build, cypress, playwright]
if: github.ref != 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "corretto"
- uses: gradle/actions/wrapper-validation@v3
- uses: gradle/actions/setup-gradle@v3
- name: Publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ORG_GRADLE_PROJECT_sadeRepositoryUsername: ${{ secrets.ARTIFACTORY_USERNAME }}
ORG_GRADLE_PROJECT_sadeRepositoryPassword: ${{ secrets.ARTIFACTORY_PASSWORD }}
run: ./gradlew publish