Skip to content

Commit 19afe6d

Browse files
Merge branch '259-ci-for-javadoc-not-for-tags' into dev
2 parents 662d243 + 3340a23 commit 19afe6d

File tree

2 files changed

+58
-31
lines changed

2 files changed

+58
-31
lines changed

.gitlab-ci.yml

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,19 @@ variables:
2828
# Using multiple test stages to avoid running some things in parallel (see job notes).
2929
stages:
3030
- test
31-
- upload-to-internal
32-
- upload-to-central
31+
- publish-maven-internal
32+
- publish-maven-central
3333
- package-api-docs
3434
- triggers
3535

36+
workflow:
37+
rules:
38+
# Never create a pipeline when a tag is pushed (to simplify release checks in root build script)
39+
- if: $CI_COMMIT_TAG
40+
when: never
41+
# Otherwise, only create a pipeline when a branch is pushed
42+
- if: $CI_PIPELINE_SOURCE == "push"
43+
3644
test:
3745
stage: test
3846
tags: [ docker, linux, x64 ]
@@ -47,7 +55,9 @@ test:
4755
# "|| true" for an OK exit code if no file is found
4856
- rm **/hs_err_pid*.log || true
4957
script:
50-
- ./scripts/test-with-asan.sh $GITLAB_REPO_ARGS $VERSION_ARGS clean build
58+
# build to assemble, run tests and spotbugs
59+
# javadocForWeb to catch API docs errors before releasing
60+
- ./scripts/test-with-asan.sh $GITLAB_REPO_ARGS $VERSION_ARGS clean build javadocForWeb
5161
artifacts:
5262
when: always
5363
paths:
@@ -120,22 +130,32 @@ test-jdk-x86:
120130
TEST_WITH_JAVA_X86: "true"
121131
script: ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS clean build
122132

123-
upload-to-internal:
124-
stage: upload-to-internal
133+
# Publish Maven artifacts to internal Maven repo
134+
publish-maven-internal:
135+
stage: publish-maven-internal
125136
tags: [ docker, x64 ]
126-
except:
127-
- main # Do not upload duplicate release artifacts
128-
- pipelines # Do not upload artifacts if triggered by upstream project to save on disk space
129-
- schedules # Do not upload artifacts from scheduled jobs to save on disk space
130-
- tags # Only upload artifacts from branches
137+
rules:
138+
# Not from main branch, doing so may duplicate release artifacts (uploaded from publish branch)
139+
- if: $CI_COMMIT_BRANCH == "main"
140+
when: never
141+
# Not if triggered by upstream project to save on disk space
142+
- if: $CI_PIPELINE_SOURCE == "pipeline"
143+
when: never
144+
# Not from scheduled pipelines to save on disk space
145+
- if: $CI_PIPELINE_SOURCE == "schedule"
146+
when: never
147+
# Otherwise, only on push to branch
148+
- if: $CI_PIPELINE_SOURCE == "push"
131149
script:
132150
- ./gradlew $GITLAB_REPO_ARGS $GITLAB_PUBLISH_ARGS $VERSION_ARGS publishMavenJavaPublicationToGitLabRepository
133151

134-
upload-to-central:
135-
stage: upload-to-central
152+
# Publish Maven artifacts to public Maven repo at Central
153+
publish-maven-central:
154+
stage: publish-maven-central
136155
tags: [ docker, x64 ]
137-
only:
138-
- publish
156+
rules:
157+
# Only on publish branch
158+
- if: $CI_COMMIT_BRANCH == "publish"
139159
before_script:
140160
- 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)..."
141161
script:
@@ -146,11 +166,13 @@ upload-to-central:
146166
- ci/send-to-gchat.sh "$GOOGLE_CHAT_WEBHOOK_JAVA_CI" --thread $CI_COMMIT_SHA "*Releasing Java library:* *$CI_JOB_STATUS* for $CI_JOB_NAME"
147167
- 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."
148168

169+
# Create Java API docs archive
149170
package-api-docs:
150171
stage: package-api-docs
151172
tags: [ docker, x64 ]
152-
only:
153-
- publish
173+
rules:
174+
# Only on publish branch
175+
- if: $CI_COMMIT_BRANCH == "publish"
154176
script:
155177
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS :objectbox-java:packageJavadocForWeb
156178
after_script:
@@ -159,14 +181,18 @@ package-api-docs:
159181
paths:
160182
- "objectbox-java/build/dist/objectbox-java-web-api-docs.zip"
161183

184+
# Trigger Gradle plugin build to test new Maven snapshots of this project
162185
trigger-plugin:
163186
stage: triggers
164-
except:
165-
- schedules # Do not trigger when run on schedule, e.g. integ tests have own schedule.
166-
- publish
187+
rules:
188+
# Do not trigger publishing of plugin
189+
- if: $CI_COMMIT_BRANCH == "publish"
190+
when: never
191+
# Otherwise, only on push to branch (also set allow_failure in case branch does not exist downstream)
192+
- if: $CI_PIPELINE_SOURCE == "push"
167193
inherit:
168194
variables: false
169-
allow_failure: true # Branch might not exist, yet, in plugin project.
195+
allow_failure: true # Branch might not exist in plugin project
170196
trigger:
171197
project: objectbox/objectbox-plugin
172198
branch: $CI_COMMIT_BRANCH

build.gradle.kts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ buildscript {
3535
}
3636
val obxJniLibVersion by extra("io.objectbox:objectbox-$objectboxPlatform:$nativeVersion")
3737

38+
println("version=$obxJavaVersion")
39+
println("objectboxNativeDependency=$obxJniLibVersion")
40+
41+
// To avoid duplicate release artifacts on the internal repository,
42+
// prevent publishing from branches other than publish, and main (for which publishing is turned off).
43+
val isCI = System.getenv("CI") == "true"
44+
val branchOrTag = System.getenv("CI_COMMIT_REF_NAME")
45+
if (isCI && isRelease && !("publish" == branchOrTag || "main" == branchOrTag)) {
46+
throw GradleException("isRelease = true only allowed on publish or main branch, but is $branchOrTag")
47+
}
48+
49+
// Versions for third party dependencies and plugins
3850
val essentialsVersion by extra("3.1.0")
3951
val junitVersion by extra("4.13.2")
4052
val mockitoVersion by extra("3.8.0")
@@ -47,17 +59,6 @@ buildscript {
4759
val coroutinesVersion by extra("1.7.3")
4860
val dokkaVersion by extra("1.8.20")
4961

50-
println("version=$obxJavaVersion")
51-
println("objectboxNativeDependency=$obxJniLibVersion")
52-
53-
// To avoid duplicate release artifacts on the internal repository,
54-
// prevent uploading from branches other than publish, and main (for which uploading is turned off).
55-
val isCI = System.getenv("CI") == "true"
56-
val branchOrTag = System.getenv("CI_COMMIT_REF_NAME")
57-
if (isCI && isRelease && !("publish" == branchOrTag || "main" == branchOrTag)) {
58-
throw GradleException("isRelease = true is only allowed on branch publish or main")
59-
}
60-
6162
repositories {
6263
mavenCentral()
6364
maven {

0 commit comments

Comments
 (0)