Skip to content

Commit 45126c8

Browse files
Build: merge-resistant way of enabling release versions on main branch
1 parent 99aaf32 commit 45126c8

2 files changed

Lines changed: 29 additions & 26 deletions

File tree

.gitlab-ci.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ image: objectboxio/buildenv-core:2025-07-03 # With JDK 21
1616
# - ORG_GRADLE_PROJECT_signingPassword
1717

1818
variables:
19-
OBX_RELEASE:
19+
OBX_PUBLISH_RELEASE:
2020
value: "false"
2121
options: [ "false", "true" ]
22-
description: "Turns on the release flag in the Gradle root build script, which triggers building and publishing a
23-
release of Java libraries to the internal GitLab repository and Maven Central.
22+
description: "If enabled, builds and depends on release versions and triggers publishing a
23+
release of the Java library artifacts to the internal GitLab repository and Maven Central.
24+
Don't run multiple times to avoid duplicate artifacts in the GitLab repository.
2425
Consult the release checklist before turning this on."
26+
# If enabled, builds and depends on release versions. Doesn't publish a release.
27+
# See the root Gradle build script for details.
28+
OBX_RELEASE: "false"
2529

2630
# Disable the Gradle daemon. Gradle may run in a Docker container with a shared
2731
# Docker volume containing GRADLE_USER_HOME. If the container is stopped after a job
@@ -50,6 +54,14 @@ workflow:
5054
# Never create a pipeline when a tag is pushed (to simplify version computation in root build script)
5155
- if: $CI_COMMIT_TAG
5256
when: never
57+
# On main branch, always use release versions as old snapshots of dependencies are deleted
58+
- if: $CI_COMMIT_REF_NAME == "main"
59+
variables:
60+
OBX_RELEASE: "true"
61+
# To publish a release must use release versions
62+
- if: $OBX_PUBLISH_RELEASE == "true"
63+
variables:
64+
OBX_RELEASE: "true"
5365
# In all other cases, create a pipeline
5466
- when: always
5567

@@ -166,8 +178,9 @@ publish-maven-internal:
166178
- linux
167179
- x64
168180
rules:
169-
# Not for main branch, doing so may duplicate release artifacts (uploaded from publish branch)
170-
- if: $CI_COMMIT_BRANCH == "main"
181+
# Not when using release versions and not publishing a release to avoid duplicate artifacts
182+
# (GitLab would allow to upload duplicates for a release version)
183+
- if: $OBX_RELEASE == "true" && $OBX_PUBLISH_RELEASE != "true"
171184
when: never
172185
# Not if triggered by upstream project to save on disk space
173186
- if: $CI_PIPELINE_SOURCE == "pipeline"
@@ -188,8 +201,8 @@ publish-maven-central:
188201
- linux
189202
- x64
190203
rules:
191-
# Only if release mode is on, only if no previous stages failed
192-
- if: $OBX_RELEASE == "true"
204+
# Only if publishing a release, only if no previous stages failed
205+
- if: $OBX_PUBLISH_RELEASE == "true"
193206
when: on_success
194207
before_script:
195208
- 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)..."
@@ -209,8 +222,8 @@ package-api-docs:
209222
- linux
210223
- x64
211224
rules:
212-
# Only if release mode is on, only if no previous stages failed
213-
- if: $OBX_RELEASE == "true"
225+
# Only if publishing a release, only if no previous stages failed
226+
- if: $OBX_PUBLISH_RELEASE == "true"
214227
when: on_success
215228
script:
216229
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS :objectbox-java:packageJavadocForWeb
@@ -225,7 +238,7 @@ trigger-plugin:
225238
stage: triggers
226239
rules:
227240
# Not when publishing a release
228-
- if: $OBX_RELEASE == "true"
241+
- if: $OBX_PUBLISH_RELEASE == "true"
229242
when: never
230243
# Do not trigger publishing of plugin
231244
- if: $CI_COMMIT_BRANCH == "publish"

build.gradle.kts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
// - sonatypeUsername: Maven Central credential used by Nexus publishing.
66
// - sonatypePassword: Maven Central credential used by Nexus publishing.
77
// This script supports the following environment variables:
8-
// - OBX_RELEASE: If set to "true" builds release versions without version postfix.
9-
// Otherwise, will build snapshot versions.
8+
// - OBX_RELEASE: If set to "true" builds and depends on release versions, without branch name and snapshot suffix.
109

1110
plugins {
1211
// https://github.com/ben-manes/gradle-versions-plugin/releases
@@ -22,12 +21,11 @@ buildscript {
2221
// Should only be changed as part of the release process, see the release checklist in the objectbox repo
2322
val versionNumber = "5.4.1"
2423

25-
// Release mode should only be enabled when manually triggering a CI pipeline,
26-
// see the release checklist in the objectbox repo.
27-
// If true won't build snapshots and removes version post fix (e.g. "-dev-SNAPSHOT"),
28-
// uses release versions of dependencies.
29-
// val isRelease = System.getenv("OBX_RELEASE") == "true"
30-
val isRelease = true // On (public) main branch don't use snapshots (publishing is disabled in CI for main branch)
24+
// If OBX_RELEASE is set, build and depend on release versions. Doesn't publish a release.
25+
// See the release checklist in the objectbox repo on how to publish a release.
26+
// If true, Maven artifacts use a release version, so without branch name and snapshot suffix
27+
// (such as "-dev-SNAPSHOT"), including for dependencies (such as objectbox-java).
28+
val isRelease = System.getenv("OBX_RELEASE") == "true"
3129

3230
// version post fix: "-<value>" or "" if not defined; e.g. used by CI to pass in branch name
3331
val versionPostFixValue = project.findProperty("versionPostFix")
@@ -49,14 +47,6 @@ buildscript {
4947
println("version=$obxJavaVersion")
5048
println("objectboxNativeDependency=$obxJniLibVersion")
5149

52-
// To avoid duplicate release artifacts on the internal repository,
53-
// prevent publishing from branches other than publish, and main (for which publishing is turned off).
54-
val isCI = System.getenv("CI") == "true"
55-
val branchOrTag = System.getenv("CI_COMMIT_REF_NAME")
56-
if (isCI && isRelease && !("publish" == branchOrTag || "main" == branchOrTag)) {
57-
throw GradleException("isRelease = true only allowed on publish or main branch, but is $branchOrTag")
58-
}
59-
6050
// Versions for third party dependencies and plugins
6151
val essentialsVersion by extra("3.1.0")
6252
val junitVersion by extra("4.13.2")

0 commit comments

Comments
 (0)