-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy path.gitlab-ci.yml
231 lines (216 loc) · 6.93 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
# SPDX-FileCopyrightText: The openTCS Authors
# SPDX-License-Identifier: MIT
default:
image: eclipse-temurin:21-jdk-jammy
tags:
- opentcs-runner
before_script:
# Put GRADLE_USER_HOME into the cache directory so the wrapper and dependencies are not
# re-downloaded for every job.
- export GRADLE_USER_HOME=`pwd`/.gradle
timeout: 15 minutes
include: '.gitlab/docker/codequality/version.yml'
workflow:
rules:
- if: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_PIPELINE_SOURCE == "web"
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
DO_BUILD_CODEQUALITY_IMAGE:
value: "false"
description: "Whether ('true') or not ('false') to (re-)build the Docker image for code quality jobs."
DO_DEPLOY_PRIVATE:
value: "false"
description: "Whether ('true') or not ('false') to deploy artifacts to private (GitLab) repository."
DO_DEPLOY_OSSRH:
value: "false"
description: "Whether ('true') or not ('false') to deploy artifacts to the public OSSRH repository, e.g. for release builds."
NO_BUILD_NUMBER:
value: "false"
description: "Whether ('true') or not ('false') to exclude the build number in the artifacts' version number, e.g. for release builds."
SIGNING_KEY:
value: ""
description: "The key to use for signing artifacts."
SIGNING_PASSWORD:
value: ""
description: "The password to use for signing artifacts."
DEPLOY_REPO_OSSRH_USERNAME:
value: ""
description: "User name for logging in with the public OSSRH repository."
DEPLOY_REPO_OSSRH_PASSWORD:
value: ""
description: "Password for logging in with the public OSSRH repository."
stages:
- build
- test
- deploy
.touch-gradle-build-results: &touch-gradle-build-results
- echo "Touching build results to prevent Gradle rebuilding them..."
- find .gradle | xargs touch
- find . -regex '\./opentcs-[^/]+/build/.*' | xargs touch
build_code_quality_image:
stage: build
rules:
- if: $DO_BUILD_CODEQUALITY_IMAGE == "true"
image:
name: gcr.io/kaniko-project/executor:v1.9.1-debug
entrypoint: [""]
dependencies: []
script:
- echo "Building code quality image with tag ${CODEQUALITY_IMAGE_TAG}..."
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"${CI_REGISTRY}\":{\"auth\":\"$(printf "%s:%s" "${CI_REGISTRY_USER}" "${CI_REGISTRY_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
- '/kaniko/executor
--context "${CI_PROJECT_DIR}/.gitlab/docker/codequality"
--dockerfile "${CI_PROJECT_DIR}/.gitlab/docker/codequality/Dockerfile"
--destination "${CI_REGISTRY_IMAGE}/codequality:${CODEQUALITY_IMAGE_TAG}"'
build:
stage: build
interruptible: true
dependencies: []
script:
- ./gradlew -x check release testClasses -PNO_BUILD_NUMBER="$NO_BUILD_NUMBER"
artifacts:
name: 'opentcs-build-b$CI_PIPELINE_IID'
paths:
- .gradle
- opentcs-*/build/classes/
- opentcs-*/build/generated/
- opentcs-*/build/libs/
- opentcs-*/build/resources/
- opentcs-*/build/tmp/
exclude:
- .gradle/.tmp/**/*
- .gradle/caches/**/*
- .gradle/wrapper/**/*
expire_in: 1 week
cache:
key: build_test_deploy-$(date +%Y-%m)
paths:
- .gradle
test:
stage: test
interruptible: true
dependencies:
- build
script:
- *touch-gradle-build-results
- echo "Running unit tests..."
- ./gradlew test jacocoLogAggregatedCoverage -PNO_BUILD_NUMBER="$NO_BUILD_NUMBER"
coverage: '/Branch Coverage: ([0-9.]+)%/'
artifacts:
name: 'opentcs-test-b$CI_PIPELINE_IID'
paths:
# Results of (failed) approval tests.
- opentcs-*/**/*.received.txt
reports:
junit: opentcs-*/build/test-results/test/TEST-*.xml
when: always
expire_in: 1 week
cache:
key: build_test_deploy-$(date +%Y-%m)
paths:
- .gradle
lint-spotless:
stage: test
interruptible: true
dependencies: []
script:
- echo "Running Spotless check..."
- ./gradlew spotlessCheck
cache:
key: lint_spotless-$(date +%Y-%m)
paths:
- .gradle
lint-checkstyle:
stage: test
interruptible: true
image: ${CI_REGISTRY_IMAGE}/codequality:${CODEQUALITY_IMAGE_TAG}
variables:
CHANGELOG_FILE: opentcs-documentation/src/docs/release-notes/changelog.adoc
MALFORMED_HEADERS_FILE: malformed_section_headers.txt
CODE_CLIMATE_FILE: gl-code-quality-report.json
dependencies:
- build
script:
- *touch-gradle-build-results
- echo "Checking for changelog headers that do not match 'Version x.y.z (yyyy-mm-dd)'..."
- '( grep --extended-regexp "^==[^=]" $CHANGELOG_FILE
| grep --invert-match --extended-regexp "^== Version [0-9]+\.[0-9]+(\.[0-9]+)? +\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\)$"
> $MALFORMED_HEADERS_FILE )
|| true'
- 'if [ -s $MALFORMED_HEADERS_FILE -a $NO_BUILD_NUMBER = "true" ] ; then
echo "Found malformed changelog headers:" ;
cat $MALFORMED_HEADERS_FILE ;
exit 1 ;
fi'
- rm -f $MALFORMED_HEADERS_FILE
- echo "Running CheckStyle checks..."
- ./gradlew checkstyleMain checkstyleTest checkstyleGuiceConfig
- echo "Converting CheckStyle reports to CodeClimate report..."
- violations-command-line -cc $CODE_CLIMATE_FILE -print-violations false -diff-print-violations true -v "CHECKSTYLE" "." ".*checkstyle/.*\.xml$" "Checkstyle"
- sed -i.bak -e "s,$CI_PROJECT_DIR/,,g" $CODE_CLIMATE_FILE
artifacts:
reports:
codequality: $CODE_CLIMATE_FILE
when: always
expire_in: 1 week
cache:
key: lint_checkstyle-$(date +%Y-%m)
paths:
- .gradle
lint-reuse:
stage: test
interruptible: true
dependencies: []
image:
name: fsfe/reuse:4.0.3
entrypoint: [""]
script:
- reuse lint
deploy_private:
stage: deploy
rules:
- if: $DO_DEPLOY_PRIVATE == "true"
dependencies:
- build
script:
- *touch-gradle-build-results
- './gradlew -x check release publish
-PDO_DEPLOY_PRIVATE="true"
-PDO_DEPLOY_OSSRH="false"
-PNO_BUILD_NUMBER="$NO_BUILD_NUMBER"
-PSIGNING_KEY="$SIGNING_KEY"
-PSIGNING_PASSWORD="$SIGNING_PASSWORD"'
artifacts:
name: 'opentcs-deploy-b$CI_PIPELINE_IID'
paths:
- build/distributions/*.zip
expire_in: 1 week
cache:
key: build_test_deploy-$(date +%Y-%m)
paths:
- .gradle
policy: pull
deploy_ossrh:
stage: deploy
rules:
- if: $DO_DEPLOY_OSSRH == "true"
dependencies:
- build
script:
- *touch-gradle-build-results
- './gradlew -x check publishToSonatype closeAndReleaseStagingRepositories
-PDO_DEPLOY_PRIVATE="false"
-PDO_DEPLOY_OSSRH="true"
-PNO_BUILD_NUMBER="$NO_BUILD_NUMBER"
-PSIGNING_KEY="$SIGNING_KEY"
-PSIGNING_PASSWORD="$SIGNING_PASSWORD"
-PDEPLOY_REPO_OSSRH_USERNAME="$DEPLOY_REPO_OSSRH_USERNAME"
-PDEPLOY_REPO_OSSRH_PASSWORD="$DEPLOY_REPO_OSSRH_PASSWORD"'
cache:
key: build_test_deploy-$(date +%Y-%m)
paths:
- .gradle
policy: pull