Skip to content

Commit 20017ee

Browse files
GitLab CI: convert to rules
- Also rename upload tasks. "Upload task" is the no longer used Gradle mechanism, using the Gradle publishing mechanism since a while now. - Also trigger Gradle plugin for scheduled builds. It has tests that benefit from running and the plugin project will not schedule integration tests if triggered by a scheduled pipeline.
1 parent 662d243 commit 20017ee

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

.gitlab-ci.yml

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ 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

@@ -120,22 +120,35 @@ test-jdk-x86:
120120
TEST_WITH_JAVA_X86: "true"
121121
script: ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS clean build
122122

123-
upload-to-internal:
124-
stage: upload-to-internal
123+
# Publish Maven artifacts to internal Maven repo
124+
publish-maven-internal:
125+
stage: publish-maven-internal
125126
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
127+
rules:
128+
# Not from main branch, doing so may duplicate release artifacts (uploaded from publish branch)
129+
- if: $CI_COMMIT_BRANCH == "main"
130+
when: never
131+
# Not if triggered by upstream project to save on disk space
132+
- if: $CI_PIPELINE_SOURCE == "pipeline"
133+
when: never
134+
# Not from scheduled pipelines to save on disk space
135+
- if: $CI_PIPELINE_SOURCE == "schedule"
136+
when: never
137+
# Not from tags
138+
- if: $CI_COMMIT_TAG == null
139+
when: never
140+
# Otherwise, only on push to branch
141+
- if: $CI_PIPELINE_SOURCE == "push"
131142
script:
132143
- ./gradlew $GITLAB_REPO_ARGS $GITLAB_PUBLISH_ARGS $VERSION_ARGS publishMavenJavaPublicationToGitLabRepository
133144

134-
upload-to-central:
135-
stage: upload-to-central
145+
# Publish Maven artifacts to public Maven repo at Central
146+
publish-maven-central:
147+
stage: publish-maven-central
136148
tags: [ docker, x64 ]
137-
only:
138-
- publish
149+
rules:
150+
# Only on publish branch
151+
- if: $CI_COMMIT_BRANCH == "publish"
139152
before_script:
140153
- 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)..."
141154
script:
@@ -146,11 +159,13 @@ upload-to-central:
146159
- ci/send-to-gchat.sh "$GOOGLE_CHAT_WEBHOOK_JAVA_CI" --thread $CI_COMMIT_SHA "*Releasing Java library:* *$CI_JOB_STATUS* for $CI_JOB_NAME"
147160
- 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."
148161

162+
# Create Java API docs archive
149163
package-api-docs:
150164
stage: package-api-docs
151165
tags: [ docker, x64 ]
152-
only:
153-
- publish
166+
rules:
167+
# Only on publish branch
168+
- if: $CI_COMMIT_BRANCH == "publish"
154169
script:
155170
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS :objectbox-java:packageJavadocForWeb
156171
after_script:
@@ -159,14 +174,18 @@ package-api-docs:
159174
paths:
160175
- "objectbox-java/build/dist/objectbox-java-web-api-docs.zip"
161176

177+
# Trigger Gradle plugin build to test new Maven snapshots of this project
162178
trigger-plugin:
163179
stage: triggers
164-
except:
165-
- schedules # Do not trigger when run on schedule, e.g. integ tests have own schedule.
166-
- publish
180+
rules:
181+
# Do not trigger publishing of plugin
182+
- if: $CI_COMMIT_BRANCH == "publish"
183+
when: never
184+
# Otherwise, only on push to branch (also set allow_failure in case branch does not exist downstream)
185+
- if: $CI_PIPELINE_SOURCE == "push"
167186
inherit:
168187
variables: false
169-
allow_failure: true # Branch might not exist, yet, in plugin project.
188+
allow_failure: true # Branch might not exist in plugin project
170189
trigger:
171190
project: objectbox/objectbox-plugin
172191
branch: $CI_COMMIT_BRANCH

0 commit comments

Comments
 (0)