-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.gitlab-ci.yml
339 lines (313 loc) · 8.23 KB
/
.gitlab-ci.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
workflow:
auto_cancel:
on_new_commit: interruptible
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_PIPELINE_SOURCE == "push"
- if: $CI_PIPELINE_SOURCE == "schedule"
stages:
- changelog
- prepare-build
- build
- test
- security
- publish-snapshot
- publish
- website
variables:
GRADLE_OPTS: -Dorg.gradle.daemon=false
GRADLE_USER_HOME: $CI_PROJECT_DIR/.gradle
KONAN_DATA_DIR: $CI_PROJECT_DIR/.konan
KOTLIN_DATA_DIR: $CI_PROJECT_DIR/.kotlin
BUILD_LINUX_IMAGE_NAME: registry.gitlab.com/trixnity/kmp-dockerfiles/kmp-dockerfiles-base:latest
.cache-linux: &cache-linux
- key: global-trixnity-cache-linux
policy: pull-push
paths:
- $GRADLE_USER_HOME
- $KONAN_DATA_DIR
- $KOTLIN_DATA_DIR
.push-cache-linux: &push-cache-linux
- key: "$CI_COMMIT_REF_NAME-linux"
policy: push
paths:
- $GRADLE_USER_HOME
- $KONAN_DATA_DIR
- $KOTLIN_DATA_DIR
.pull-cache-linux: &pull-cache-linux
- key: "$CI_COMMIT_REF_NAME-linux"
fallback_keys: [ "global-trixnity-cache-linux" ]
policy: pull
paths:
- $GRADLE_USER_HOME
- $KONAN_DATA_DIR
- $KOTLIN_DATA_DIR
.cache-mac: &cache-mac
- key: global-trixnity-cache-mac
policy: pull-push
paths:
- $GRADLE_USER_HOME
- $KONAN_DATA_DIR
- $KOTLIN_DATA_DIR
.push-cache-mac: &push-cache-mac
- key: "$CI_COMMIT_REF_NAME-mac"
policy: push
paths:
- $GRADLE_USER_HOME
- $KONAN_DATA_DIR
- $KOTLIN_DATA_DIR
.pull-cache-mac: &pull-cache-mac
- key: "$CI_COMMIT_REF_NAME-mac"
fallback_keys: [ "global-trixnity-cache-mac" ]
policy: pull
paths:
- $GRADLE_USER_HOME
- $KONAN_DATA_DIR
- $KOTLIN_DATA_DIR
.docker-variables: &docker-variables
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
.artifact-reports: &artifact-reports
name: reports
when: always
paths: [ "**/build/reports" ]
reports:
junit: "**/build/test-results/**/TEST-*.xml"
.if-merge-request: &if-merge-request
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != $CI_DEFAULT_BRANCH
when: never
- if: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
.if-release: &if-release
- if: '$CI_COMMIT_TAG =~ /^v\d+.\d+.\d+.*/'
.if-main: &if-main
- if: '$CI_COMMIT_TAG =~ /^v\d+.\d+.\d+.*/'
when: never
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
build:mac:
stage: build
interruptible: true
tags: [ "trixnity-mac-internal" ]
cache:
- *cache-mac
- *push-cache-mac
rules:
- *if-merge-request
script:
- ./gradlew
compileKotlin{IosArm64,IosSimulatorArm64,IosX64,MacosArm64,MacosX64}
compileTestKotlin{IosSimulatorArm64,IosX64,MacosArm64,MacosX64}
linkDebugTest{IosX64,MacosX64}
--stacktrace
build:linux:
stage: build
interruptible: true
tags: [ "saas-linux-large-amd64" ]
image: $BUILD_LINUX_IMAGE_NAME
cache:
- *cache-linux
- *push-cache-linux
rules:
- *if-merge-request
script:
- ./gradlew
compileKotlin{Jvm,Js,LinuxX64,MingwX64}
compileReleaseKotlinAndroid
compileTestKotlin{Jvm,Js,LinuxX64,MingwX64}
linkDebugTest{LinuxX64,MingwX64}
compileReleaseUnitTestKotlinAndroid
--stacktrace
test:mac:
stage: test
interruptible: true
timeout: 1h
needs: [ "build:mac" ]
tags: [ "trixnity-mac-internal" ]
cache:
- *pull-cache-mac
artifacts: *artifact-reports
rules:
- *if-merge-request
script:
- ./gradlew
{iosSimulatorArm64,iosX64,macosArm64,macosX64}Test
--stacktrace
test:linux:
stage: test
interruptible: true
timeout: 1h
needs: [ "build:linux" ]
tags: [ "saas-linux-large-amd64" ]
image: $BUILD_LINUX_IMAGE_NAME
cache:
- *pull-cache-linux
artifacts: *artifact-reports
rules:
- *if-merge-request
script:
- ./gradlew
{jvm,js,linuxX64,mingwX64,testReleaseUnit}Test -x :trixnity-client:integration-tests:jvmTest
--stacktrace
test:integration-test:
stage: test
interruptible: true
timeout: 30m
needs: [ "build:linux" ]
tags: [ "saas-linux-medium-amd64" ]
image: $BUILD_LINUX_IMAGE_NAME
services:
- name: docker:dind
command: [ "--tls=false" ]
cache:
- *pull-cache-linux
variables: *docker-variables
artifacts: *artifact-reports
rules:
- *if-merge-request
script:
- ./gradlew
:trixnity-client:integration-tests:jvmTest
--stacktrace
security:dependencies:
stage: security
interruptible: true
timeout: 30m
needs: [ ]
tags: [ "saas-linux-small-amd64" ]
image:
name: "aquasec/trivy"
entrypoint: [ "" ]
variables:
TRIVY_CACHE_DIR: ".trivycache/"
WITH_LOCK: true
cache:
paths:
- .trivycache/
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
allow_failure: true
- if: '$CI_COMMIT_TAG =~ /^v\d+.\d+.\d+.*/'
allow_failure: false
- if: $CI_PIPELINE_SOURCE == "schedule"
allow_failure: false
artifacts:
when: always
reports:
dependency_scanning: report.json
before_script:
- apk add openjdk17
- ./gradlew dependenciesForAll --write-locks --no-parallel > dependencies.txt
script:
- trivy repo ./ --exit-code 0
- trivy repo ./ --exit-code 0 --format template --template "@/contrib/gitlab.tpl" --output report.json
- trivy repo ./ --exit-code 1 --severity CRITICAL
changelog:
stage: changelog
interruptible: true
timeout: 5m
tags: [ "saas-linux-small-amd64" ]
rules:
- *if-merge-request
script:
- git fetch origin main
- |
if git diff --name-only HEAD origin/main | grep "CHANGELOG.md"; then
echo "CHANGELOG.md has changed"
else
echo "CHANGELOG.md has not changed"
exit 1
fi
publish-snapshot:mac:
stage: publish-snapshot
tags: [ "trixnity-mac-internal" ]
cache:
- *cache-mac
rules:
- *if-main
script:
- ./gradlew
publish{IosArm64,IosSimulatorArm64,IosX64,MacosArm64,MacosX64}PublicationToSnapshotRepository
--stacktrace
publish-snapshot:linux:
stage: publish-snapshot
tags: [ "saas-linux-medium-amd64" ]
image: $BUILD_LINUX_IMAGE_NAME
cache:
- *cache-linux
rules:
- *if-main
artifacts:
paths:
- website/static/api/
script:
- ./gradlew
publish{KotlinMultiplatform,Jvm,Js,LinuxX64,MingwX64,AndroidRelease,TrixnityPlatform}PublicationToSnapshotRepository
dokkaHtmlToWebsite
--stacktrace
publish:create-nexus-staging-repo:
stage: publish
tags: [ "saas-linux-small-amd64" ]
image: ubuntu:latest
rules:
- *if-release
artifacts:
paths: [ "./OSSRH_REPOSITORY_ID" ]
script:
- apt-get update && apt-get install -y curl jq
- >
jsonOutput=$(curl -s
--request POST -u "$OSSRH_USERNAME:$OSSRH_PASSWORD"
--url https://oss.sonatype.org/service/local/staging/profiles/65b35e28422b2/start
--header 'Accept: application/json'
--header 'Content-Type: application/json'
--data '{ "data": {"description" : "'"$CI_COMMIT_TAG"'"} }'
)
- OSSRH_REPOSITORY_ID=$(echo "$jsonOutput" | jq -r '.data.stagedRepositoryId')
- >
if [ -z "$OSSRH_REPOSITORY_ID" ]; then
echo "Error while creating the staging repository. Response: $jsonOutput";
exit 1;
fi
- echo -n $OSSRH_REPOSITORY_ID > ./OSSRH_REPOSITORY_ID
publish:mac:
stage: publish
needs: [ "publish:create-nexus-staging-repo" ]
tags: [ "trixnity-mac-internal" ]
cache:
- *cache-mac
rules:
- *if-release
script:
- export OSSRH_REPOSITORY_ID=$(cat ./OSSRH_REPOSITORY_ID)
- ./gradlew
publish{IosArm64,IosSimulatorArm64,IosX64,MacosArm64,MacosX64}PublicationToReleaseRepository
--stacktrace
publish:linux:
stage: publish
needs: [ "publish:create-nexus-staging-repo" ]
tags: [ "saas-linux-medium-amd64" ]
image: $BUILD_LINUX_IMAGE_NAME
cache:
- *cache-linux
rules:
- *if-release
script:
- export OSSRH_REPOSITORY_ID=$(cat ./OSSRH_REPOSITORY_ID)
- ./gradlew
publish{KotlinMultiplatform,Jvm,Js,LinuxX64,MingwX64,AndroidRelease,TrixnityPlatform}PublicationToReleaseRepository
--stacktrace
pages:
stage: website
image: node:lts
rules:
- *if-main
script:
- cd website
- yarn install --force
- yarn build
- mv ./build ../public
artifacts:
paths:
- public