Skip to content

Commit 270c244

Browse files
GitLab: use OBX_READ_PACKAGES_TOKEN to read packages repo
Therefore, introduces a separate gitlabPublishToken Gradle property to set the token to use for publishing to the packages repo
1 parent f050716 commit 270c244

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

.gitlab-ci.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
image: objectboxio/buildenv-core:2023-07-28
44

55
# Assumes these environment variables are configured in GitLab CI/CD Settings:
6+
# - OBX_READ_PACKAGES_TOKEN
67
# - SONATYPE_USER
78
# - SONATYPE_PWD
89
# - GOOGLE_CHAT_WEBHOOK_JAVA_CI
@@ -18,8 +19,9 @@ variables:
1819
# Configure file.encoding to always use UTF-8 when running Gradle.
1920
# Use low priority processes to avoid Gradle builds consuming all build machine resources.
2021
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dfile.encoding=UTF-8 -Dorg.gradle.priority=low"
21-
GITLAB_REPO_ARGS: "-PgitlabUrl=$CI_SERVER_URL -PgitlabTokenName=Job-Token -PgitlabPrivateToken=$CI_JOB_TOKEN"
22-
CENTRAL_REPO_ARGS: "-PsonatypeUsername=$SONATYPE_USER -PsonatypePassword=$SONATYPE_PWD"
22+
GITLAB_REPO_ARGS: "-PgitlabUrl=$CI_SERVER_URL -PgitlabPrivateTokenName=Deploy-Token -PgitlabPrivateToken=$OBX_READ_PACKAGES_TOKEN"
23+
GITLAB_PUBLISH_ARGS: "-PgitlabPublishTokenName=Job-Token -PgitlabPublishToken=$CI_JOB_TOKEN"
24+
CENTRAL_PUBLISH_ARGS: "-PsonatypeUsername=$SONATYPE_USER -PsonatypePassword=$SONATYPE_PWD"
2325
# CI_COMMIT_REF_SLUG is the branch or tag name, but web-safe (only 0-9, a-z)
2426
VERSION_ARGS: "-PversionPostFix=$CI_COMMIT_REF_SLUG"
2527

@@ -127,7 +129,7 @@ upload-to-internal:
127129
- schedules # Do not upload artifacts from scheduled jobs to save on disk space
128130
- tags # Only upload artifacts from branches
129131
script:
130-
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS publishMavenJavaPublicationToGitLabRepository
132+
- ./gradlew $GITLAB_REPO_ARGS $GITLAB_PUBLISH_ARGS $VERSION_ARGS publishMavenJavaPublicationToGitLabRepository
131133

132134
upload-to-central:
133135
stage: upload-to-central
@@ -138,7 +140,7 @@ upload-to-central:
138140
- 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)..."
139141
script:
140142
# Note: supply internal repo as tests use native dependencies that might not be published, yet.
141-
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS $CENTRAL_REPO_ARGS publishMavenJavaPublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository
143+
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS $CENTRAL_PUBLISH_ARGS publishMavenJavaPublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository
142144
after_script:
143145
# Also runs on failure, so show CI_JOB_STATUS.
144146
- ci/send-to-gchat.sh "$GOOGLE_CHAT_WEBHOOK_JAVA_CI" --thread $CI_COMMIT_SHA "*Releasing Java library:* *$CI_JOB_STATUS* for $CI_JOB_NAME"

buildSrc/src/main/kotlin/objectbox-publish.gradle.kts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//
55
// To publish artifacts to the internal GitLab repo set:
66
// - gitlabUrl
7-
// - gitlabPrivateToken
8-
// - gitlabTokenName: optional, if set used instead of "Private-Token". Use for CI to specify e.g. "Job-Token".
7+
// - gitlabPublishToken: a token with permission to publish to the GitLab Package Repository
8+
// - gitlabPublishTokenName: optional, if set used instead of "Private-Token". Use for CI to specify e.g. "Job-Token".
99
//
1010
// To sign artifacts using an ASCII encoded PGP key given via a file set:
1111
// - signingKeyFile
@@ -28,21 +28,21 @@ publishing {
2828
repositories {
2929
maven {
3030
name = "GitLab"
31-
if (project.hasProperty("gitlabUrl") && project.hasProperty("gitlabPrivateToken")) {
31+
if (project.hasProperty("gitlabUrl") && project.hasProperty("gitlabPublishToken")) {
3232
// "https://gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/maven"
3333
val gitlabUrl = project.property("gitlabUrl")
3434
url = uri("$gitlabUrl/api/v4/projects/14/packages/maven")
3535
println("GitLab repository set to $url.")
3636

3737
credentials(HttpHeaderCredentials::class) {
38-
name = project.findProperty("gitlabTokenName")?.toString() ?: "Private-Token"
39-
value = project.property("gitlabPrivateToken").toString()
38+
name = project.findProperty("gitlabPublishTokenName")?.toString() ?: "Private-Token"
39+
value = project.property("gitlabPublishToken").toString()
4040
}
4141
authentication {
4242
create<HttpHeaderAuthentication>("header")
4343
}
4444
} else {
45-
println("WARNING: Can not publish to GitLab: gitlabUrl or gitlabPrivateToken not set.")
45+
println("WARNING: Can not publish to GitLab: gitlabUrl or gitlabPublishToken not set.")
4646
}
4747
}
4848
// Note: Sonatype repo created by publish-plugin, see root build.gradle.kts.

tests/objectbox-java-test/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ repositories {
3030
url = uri("$gitlabUrl/api/v4/groups/objectbox/-/packages/maven")
3131
name = "GitLab"
3232
credentials(HttpHeaderCredentials::class) {
33-
name = project.findProperty("gitlabTokenName")?.toString() ?: "Private-Token"
33+
name = project.findProperty("gitlabPrivateTokenName")?.toString() ?: "Private-Token"
3434
value = project.property("gitlabPrivateToken").toString()
3535
}
3636
authentication {

tests/test-proguard/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repositories {
1717
url = uri("$gitlabUrl/api/v4/groups/objectbox/-/packages/maven")
1818
name = "GitLab"
1919
credentials(HttpHeaderCredentials::class) {
20-
name = project.findProperty("gitlabTokenName")?.toString() ?: "Private-Token"
20+
name = project.findProperty("gitlabPrivateTokenName")?.toString() ?: "Private-Token"
2121
value = project.property("gitlabPrivateToken").toString()
2222
}
2323
authentication {

0 commit comments

Comments
 (0)