-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
235 lines (217 loc) · 9.37 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
235 lines (217 loc) · 9.37 KB
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
# https://docs.gitlab.com/ci/yaml/
# Assumes these environment variables are configured in GitLab CI/CD Settings:
# - OBX_READ_PACKAGES_TOKEN
# - SONATYPE_USER
# - SONATYPE_PWD
# - GOOGLE_CHAT_WEBHOOK_JAVA_CI
# Additionally, these environment variables used by the objectbox-publish Gradle script:
# - ORG_GRADLE_PROJECT_signingKeyFile
# - ORG_GRADLE_PROJECT_signingKeyId
# - ORG_GRADLE_PROJECT_signingPassword
variables:
OBX_PUBLISH_RELEASE:
value: "false"
options: [ "false", "true" ]
description: "If enabled, builds and depends on release versions and triggers publishing a
release of the Java library artifacts to the internal GitLab repository and Maven Central.
Don't run multiple times to avoid duplicate artifacts in the GitLab repository.
Consult the release checklist before turning this on."
# If enabled, builds and depends on release versions. Doesn't publish a release.
# See the root Gradle build script for details.
OBX_RELEASE: "false"
# Disable the Gradle daemon. Gradle may run in a Docker container with a shared
# Docker volume containing GRADLE_USER_HOME. If the container is stopped after a job
# Gradle daemons may get killed, preventing proper clean-up of lock files in GRADLE_USER_HOME.
# Use low priority processes to avoid Gradle builds consuming all build machine resources.
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.priority=low"
GITLAB_REPO_ARGS: "-PgitlabUrl=$CI_SERVER_URL -PgitlabPrivateTokenName=Deploy-Token -PgitlabPrivateToken=$OBX_READ_PACKAGES_TOKEN"
GITLAB_PUBLISH_ARGS: "-PgitlabPublishTokenName=Job-Token -PgitlabPublishToken=$CI_JOB_TOKEN"
CENTRAL_PUBLISH_ARGS: "-PsonatypeUsername=$SONATYPE_USER -PsonatypePassword=$SONATYPE_PWD"
# CI_COMMIT_REF_SLUG is the branch or tag name, but web-safe (only 0-9, a-z)
VERSION_ARGS: "-PversionSuffix=$CI_COMMIT_REF_SLUG"
# Using multiple test stages to avoid running some things in parallel (see job notes).
stages:
- test
- publish-maven-internal
- publish-maven-central
- package-api-docs
- triggers
workflow:
rules:
# Disable merge request pipelines https://docs.gitlab.com/ci/jobs/job_rules/#ci_pipeline_source-predefined-variable
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: never
# Never create a pipeline when a tag is pushed (to simplify version computation in root build script)
- if: $CI_COMMIT_TAG
when: never
# On main branch, always use release versions as old snapshots of dependencies are deleted
- if: $CI_COMMIT_REF_NAME == "main"
variables:
OBX_RELEASE: "true"
# To publish a release must use release versions
- if: $OBX_PUBLISH_RELEASE == "true"
variables:
OBX_RELEASE: "true"
# In all other cases, create a pipeline
- when: always
.docker_linux_x64_android: &docker_linux_x64_android
tags:
- docker
- linux
- x64
image: objectboxio/buildenv-android:2024-12-09 # With JDK 21, Android build-tools;35.0.0 and platforms;android-35 pre-installed
variables:
# Image defaults to POSIX (ASCII), set a compatible locale so UTF-8 tests that interact with the file system work.
# Check with 'locale -a' for available locales.
LC_ALL: "C.UTF-8"
.test_base:
before_script:
# Print Gradle and JVM version info
- ./gradlew -version
# Remove any previous JVM (Hotspot) crash log.
# "|| true" for an OK exit code if no file is found
- rm **/hs_err_pid*.log || true
# By default, don't compile and test the Android APIs (only do in test job), there is currently no benefit to test
# them using multiple platforms or JDKs.
script: ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS clean build -PexcludeAndroid=true
artifacts:
when: always
paths:
- "**/hs_err_pid*.log" # Only on JVM (Hotspot) crash
reports:
junit: "**/build/test-results/**/TEST-*.xml"
test:
<<: *docker_linux_x64_android
extends: .test_base
stage: test
# Overwrite script key to run through ASAN script, compile and test Android APIs and test build of Web API docs.
# Note: Address sanitizer is only available on Linux runners (see script).
script:
# build to assemble, run tests and spotbugs
# javadocForWeb to catch API docs errors before releasing
# Temporarily disable testing with Address Sanitizer until buildenv images are modernized, see #273
# - ./scripts/test-with-asan.sh $GITLAB_REPO_ARGS $VERSION_ARGS clean build javadocForWeb
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS clean build javadocForWeb
# Overwrite artifacts key to archive spotbugs reports
artifacts:
when: always
paths:
- "**/hs_err_pid*.log" # Only on JVM (Hotspot) crash.
- "**/build/reports/spotbugs/*.html"
reports:
junit: "**/build/test-results/**/TEST-*.xml"
.test_jdks:
<<: *docker_linux_x64_android
extends: .test_base
# Overwrite script key to run through ASAN script and to run test task directly to avoid
# running SpotBugs (build runs check runs SpotBugs tasks).
# Note: Address sanitizer is only available on Linux runners (see script).
script:
# Temporarily disable testing with Address Sanitizer until buildenv images are modernized, see #273
# - ./scripts/test-with-asan.sh $GITLAB_REPO_ARGS $VERSION_ARGS clean :tests:objectbox-java-test:test
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS clean :tests:objectbox-java-test:test
# Test oldest supported and a recent JDK.
test-jdk-8:
extends: .test_jdks
needs: ["test"]
variables:
TEST_JDK: 8
# JDK 21 is the default of the current build image, so test the latest LTS JDK 25
test-jdk-25:
extends: .test_jdks
needs: ["test"]
variables:
TEST_JDK: 25
test-macos:
extends: .test_base
tags:
- jdk
- mac
test-windows:
extends: .test_base
tags:
- jdk
- windows
- x64
test-windows-jdk-x86:
extends: .test_base
tags:
- jdk-x86
- windows
variables:
# TEST_WITH_JAVA_X86 makes objectbox-java-test use 32-bit java executable and therefore
# 32-bit ObjectBox to run tests (see build.gradle file).
# Note: assumes JAVA_HOME_X86 is set to 32-bit JDK path.
TEST_WITH_JAVA_X86: "true"
# Publish Maven artifacts to internal Maven repo
publish-maven-internal:
<<: *docker_linux_x64_android
stage: publish-maven-internal
rules:
# Not when using release versions and not publishing a release to avoid duplicate artifacts
# (GitLab would allow to upload duplicates for a release version)
- if: $OBX_RELEASE == "true" && $OBX_PUBLISH_RELEASE != "true"
when: never
# Not if triggered by upstream project to save on disk space
- if: $CI_PIPELINE_SOURCE == "pipeline"
when: never
# Not for scheduled pipelines to save on disk space
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
# Otherwise, only if no previous stages failed
- when: on_success
script:
- ./gradlew $GITLAB_REPO_ARGS $GITLAB_PUBLISH_ARGS $VERSION_ARGS publishAllPublicationsToGitLabRepository
# Publish Maven artifacts to public Maven Central repo
publish-maven-central:
<<: *docker_linux_x64_android
stage: publish-maven-central
rules:
# Only if publishing a release, only if no previous stages failed
- if: $OBX_PUBLISH_RELEASE == "true"
when: on_success
before_script:
- ci/send-to-gchat.sh "$GOOGLE_CHAT_WEBHOOK_JAVA_CI" --thread $CI_COMMIT_SHA "*Releasing Java libraries to Maven Central:* job $CI_JOB_NAME from branch $CI_COMMIT_BRANCH ($CI_COMMIT_SHORT_SHA)..."
script:
# Note: supply internal repo as tests use native dependencies that might not be available publicly, yet.
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS $CENTRAL_PUBLISH_ARGS publishAllPublicationsToSonatypeRepository closeAndReleaseSonatypeStagingRepository
after_script:
# Also runs on failure, so show CI_JOB_STATUS.
- ci/send-to-gchat.sh "$GOOGLE_CHAT_WEBHOOK_JAVA_CI" --thread $CI_COMMIT_SHA "*Releasing Java libraries to Maven Central:* *$CI_JOB_STATUS* for $CI_JOB_NAME"
- ci/send-to-gchat.sh "$GOOGLE_CHAT_WEBHOOK_JAVA_CI" --thread $CI_COMMIT_SHA "Check https://repo1.maven.org/maven2/io/objectbox/ in a few minutes."
# Create Java API docs archive
package-api-docs:
<<: *docker_linux_x64_android
stage: package-api-docs
rules:
# Only if publishing a release, only if no previous stages failed
- if: $OBX_PUBLISH_RELEASE == "true"
when: on_success
script:
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS :objectbox-java:packageJavadocForWeb
after_script:
- ci/send-to-gchat.sh "$GOOGLE_CHAT_WEBHOOK_JAVA_CI" --thread $CI_COMMIT_SHA "API docs for web available as job artifact $CI_JOB_URL"
artifacts:
paths:
- "objectbox-java/build/dist/objectbox-java-web-api-docs.zip"
# Trigger Gradle plugin build to test new Maven snapshots of this project
trigger-plugin:
stage: triggers
rules:
# Not when publishing a release
- if: $OBX_PUBLISH_RELEASE == "true"
when: never
# Do not trigger publishing of plugin
- if: $CI_COMMIT_BRANCH == "publish"
when: never
# Not for scheduled pipelines where Maven snapshots of this project do not change
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
# Otherwise, only if no previous stages failed. Also set allow_failure in case branch does not exist downstream.
- when: on_success
inherit:
variables: false
allow_failure: true # Branch might not exist in plugin project
trigger:
project: objectbox/objectbox-plugin
branch: $CI_COMMIT_BRANCH