Skip to content

Commit ce484e1

Browse files
Use Gitlab CI, also test on macOS, spotbugs HTML report.
1 parent 9765fac commit ce484e1

File tree

6 files changed

+189
-3
lines changed

6 files changed

+189
-3
lines changed

.gitlab-ci.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Default image for linux builds
2+
image: objectboxio/buildenv:21.11.11-centos7
3+
4+
# Assumes these environment variables are configured in GitLab CI/CD Settings:
5+
# - SONATYPE_USER
6+
# - SONATYPE_PWD
7+
# - GOOGLE_CHAT_WEBHOOK_JAVA_CI
8+
# Additionally, Gradle scripts assume these Gradle project properties are set:
9+
# https://docs.gradle.org/current/userguide/build_environment.html#sec:project_properties
10+
# - ORG_GRADLE_PROJECT_signingKeyFile
11+
# - ORG_GRADLE_PROJECT_signingKeyId
12+
# - ORG_GRADLE_PROJECT_signingPassword
13+
14+
variables:
15+
# Disable the Gradle daemon for Continuous Integration servers as correctness
16+
# is usually a priority over speed in CI environments. Using a fresh
17+
# runtime for each build is more reliable since the runtime is completely
18+
# isolated from any previous builds.
19+
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
20+
GITLAB_REPO_ARGS: "-PgitlabUrl=$CI_SERVER_URL -PgitlabTokenName=Job-Token -PgitlabPrivateToken=$CI_JOB_TOKEN"
21+
CENTRAL_REPO_ARGS: "-PsonatypeUsername=$SONATYPE_USER -PsonatypePassword=$SONATYPE_PWD"
22+
# CI_COMMIT_REF_SLUG is the branch or tag name, but web-safe (only 0-9, a-z)
23+
VERSION_ARGS: "-PversionPostFix=$CI_COMMIT_REF_SLUG"
24+
25+
# Using multiple test stages to avoid running some things in parallel (see job notes).
26+
stages:
27+
- test
28+
- test-2
29+
- test-3
30+
- upload-to-internal
31+
- upload-to-central
32+
- package-api-docs
33+
- integ-tests
34+
35+
test:
36+
stage: test
37+
tags: [ docker, x64 ]
38+
before_script:
39+
# Print Gradle and JVM version info
40+
- ./gradlew -version
41+
# Remove any previous JVM (Hotspot) crash log.
42+
# "|| true" for an OK exit code if no file is found
43+
- rm **/hs_err_pid*.log || true
44+
script:
45+
- ./ci/test-with-asan.sh $GITLAB_REPO_ARGS $VERSION_ARGS clean build
46+
artifacts:
47+
when: always
48+
paths:
49+
- "**/hs_err_pid*.log" # Only on JVM (Hotspot) crash.
50+
- "**/build/reports/spotbugs/*.html"
51+
reports:
52+
junit: "**/build/test-results/**/TEST-*.xml"
53+
54+
.test-template:
55+
before_script:
56+
# Remove any previous JVM (Hotspot) crash log.
57+
# "|| true" for an OK exit code if no file is found
58+
- rm **/hs_err_pid*.log || true
59+
artifacts:
60+
when: always
61+
paths:
62+
- "**/hs_err_pid*.log" # Only on JVM (Hotspot) crash.
63+
reports:
64+
junit: "**/build/test-results/**/TEST-*.xml"
65+
66+
test-windows:
67+
extends: .test-template
68+
stage: test-2
69+
tags: [ windows ]
70+
script: ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS clean build
71+
72+
test-macos:
73+
extends: .test-template
74+
stage: test-2
75+
tags: [mac11+, x64]
76+
script: ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS clean build
77+
78+
# Address sanitizer is only available on Linux runners (see script).
79+
.test-asan-template:
80+
extends: .test-template
81+
tags: [ docker, x64 ]
82+
script:
83+
# Note: do not run check task as it includes SpotBugs.
84+
- ./ci/test-with-asan.sh $GITLAB_REPO_ARGS $VERSION_ARGS clean :tests:objectbox-java-test:test
85+
86+
# Test oldest supported and a recent JDK.
87+
# Note: can not run these in parallel using a matrix configuration as Gradle would step over itself.
88+
test-jdk-8:
89+
extends: .test-asan-template
90+
stage: test-2
91+
variables:
92+
TEST_JDK: 8
93+
94+
test-jdk-16:
95+
extends: .test-asan-template
96+
stage: test-3
97+
variables:
98+
TEST_JDK: 16
99+
100+
test-jdk-x86:
101+
extends: .test-template
102+
stage: test-3
103+
tags: [ windows ]
104+
variables:
105+
# TEST_WITH_JAVA_X86 makes objectbox-java-test use 32-bit java executable and therefore
106+
# 32-bit ObjectBox to run tests (see build.gradle file).
107+
# Note: assumes JAVA_HOME_X86 is set to 32-bit JDK path.
108+
TEST_WITH_JAVA_X86: "true"
109+
script: ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS clean build
110+
111+
upload-to-internal:
112+
stage: upload-to-internal
113+
tags: [ docker, x64 ]
114+
script:
115+
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS publishMavenJavaPublicationToGitLabRepository
116+
117+
upload-to-central:
118+
stage: upload-to-central
119+
tags: [ docker, x64 ]
120+
only:
121+
- publish
122+
before_script:
123+
- ci/send-to-gchat.sh "$GOOGLE_CHAT_WEBHOOK_JAVA_CI" --thread $CI_COMMIT_SHA "*Releasing Java library:* job $CI_JOB_NAME from branch $CI_COMMIT_BRANCH ($CI_COMMIT_SHORT_SHA)..."
124+
script:
125+
# Note: supply internal repo as tests use native dependencies that might not be published, yet.
126+
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS $CENTRAL_REPO_ARGS publishMavenJavaPublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository
127+
after_script:
128+
# Also runs on failure, so show CI_JOB_STATUS.
129+
- ci/send-to-gchat.sh "$GOOGLE_CHAT_WEBHOOK_JAVA_CI" --thread $CI_COMMIT_SHA "*Releasing Java library:* *$CI_JOB_STATUS* for $CI_JOB_NAME"
130+
- 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."
131+
132+
package-api-docs:
133+
stage: package-api-docs
134+
tags: [ docker, x64 ]
135+
only:
136+
- publish
137+
script:
138+
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS :objectbox-java:packageJavadocForWeb
139+
after_script:
140+
- 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"
141+
artifacts:
142+
paths:
143+
- "objectbox-java/build/dist/objectbox-java-web-api-docs.zip"
144+
145+
trigger-integ-tests:
146+
stage: integ-tests
147+
except:
148+
- schedules # Do not trigger when run on schedule, integ tests have own schedule.
149+
inherit:
150+
variables: false
151+
allow_failure: true # Branch might not exist in integ test project.
152+
trigger:
153+
project: objectbox/objectbox-integration-test
154+
branch: $CI_COMMIT_BRANCH

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ configure(subprojects.findAll { projectNamesToPublish.contains(it.name) }) {
9595
println "GitLab repository set to $url."
9696

9797
credentials(HttpHeaderCredentials) {
98-
name = "Private-Token"
98+
name = project.hasProperty("gitlabTokenName") ? gitlabTokenName : "Private-Token"
9999
value = gitlabPrivateToken
100100
}
101101
authentication {

ci/send-to-gchat.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
if [[ "$#" -lt "2" ]]; then
5+
echo "Please supply at least 2 parameters: gchat-webhook-url [--thread threadID] text"
6+
echo "Text formatting: https://developers.google.com/chat/reference/message-formats/basic"
7+
exit 1
8+
fi
9+
10+
gchat_url=$1
11+
shift
12+
13+
if [[ "$1" == "--thread" ]]; then
14+
if [[ "$#" -lt "3" ]]; then
15+
echo "Not enough parameters supplied"
16+
exit 1
17+
fi
18+
#https://developers.google.com/chat/reference/rest/v1/spaces.messages/create
19+
gchat_url="$gchat_url&threadKey=$2"
20+
shift 2
21+
fi
22+
23+
#https://developers.google.com/chat/reference/rest/v1/spaces.messages
24+
gchat_json="{\"text\": \"$*\"}"
25+
26+
curl -X POST -H 'Content-Type: application/json' "$gchat_url" -d "${gchat_json}" || true

objectbox-java/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ spotbugs {
2525
excludeFilter = file("spotbugs-exclude.xml")
2626
}
2727

28+
tasks.spotbugsMain {
29+
reports.create("html") {
30+
required.set(true)
31+
}
32+
}
33+
2834
javadoc {
2935
// Hide internal API from javadoc artifact.
3036
exclude("**/io/objectbox/Cursor.java")

tests/objectbox-java-test/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ repositories {
2626
url "$gitlabUrl/api/v4/groups/objectbox/-/packages/maven"
2727
name "GitLab"
2828
credentials(HttpHeaderCredentials) {
29-
name = 'Private-Token'
29+
name = project.hasProperty("gitlabTokenName") ? gitlabTokenName : "Private-Token"
3030
value = gitlabPrivateToken
3131
}
3232
authentication {

tests/test-proguard/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repositories {
1616
url "$gitlabUrl/api/v4/groups/objectbox/-/packages/maven"
1717
name "GitLab"
1818
credentials(HttpHeaderCredentials) {
19-
name = 'Private-Token'
19+
name = project.hasProperty("gitlabTokenName") ? gitlabTokenName : "Private-Token"
2020
value = gitlabPrivateToken
2121
}
2222
authentication {

0 commit comments

Comments
 (0)