Skip to content

Commit 1f718a4

Browse files
committed
chore(publish): restore Maven Central publishing in GitLab CI
The publish_maven_central job passed no credentials, so it could only ever have produced unsigned artifacts and a 401 at upload; being manual and allow_failure, it had never run. Map the project's SONATYPE_* variables onto the ORG_GRADLE_PROJECT_* names Gradle reads, decoding the base64 file variable SONATYPE_GPG_KEY_BASE64 into signingInMemoryKey, and guard the decode so a malformed key fails with a clear message. Run the job automatically on tags, as the GitHub Actions pipeline did before the migration; a clean X.Y.Z tag still only stages a deployment in the Central Portal for release by hand. Restore the pre-release-to-SNAPSHOT mapping the migration dropped, which keeps X.Y.Z-rcN tags out of Maven Central's monthly release quota. It is now gated behind -PpreReleasesAsSnapshot=true, passed only by the Central job, because Artifactory routes rc tags to caplin-rc off the literal tag version.
1 parent 49f530a commit 1f718a4

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

‎.gitlab-ci.yml‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,30 @@ publish_libraries:
7878
- job: "test_libraries"
7979
artifacts: false
8080

81-
# Maven Central publishing, kept but not wired up: no signing/Sonatype credentials are configured
82-
# in this project yet, so this only runs when triggered manually.
81+
# Maven Central publishing. A clean X.Y.Z tag uploads a deployment that stays staged in the Central
82+
# Portal until released there by hand; an X.Y.Z-rcN tag uploads an overwriting X.Y.Z-SNAPSHOT.
83+
# SONATYPE_GPG_KEY_BASE64 is a file variable holding the base64-encoded armoured private key.
8384
publish_maven_central:
8485
stage: publish
8586
image: registry.access.redhat.com/ubi9/openjdk-17
87+
variables:
88+
ORG_GRADLE_PROJECT_signingInMemoryKeyId: "BD2A1230"
89+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: "$SONATYPE_GPG_PASSWORD"
90+
ORG_GRADLE_PROJECT_mavenCentralUsername: "$SONATYPE_USERNAME"
91+
ORG_GRADLE_PROJECT_mavenCentralPassword: "$SONATYPE_PASSWORD"
8692
script:
87-
- ./gradlew --console=colored --no-configuration-cache publishToMavenCentral
93+
- export ORG_GRADLE_PROJECT_signingInMemoryKey="$(base64 --decode "$SONATYPE_GPG_KEY_BASE64")"
94+
- |
95+
case "$ORG_GRADLE_PROJECT_signingInMemoryKey" in
96+
"-----BEGIN PGP PRIVATE KEY BLOCK-----"*) ;;
97+
*) echo "SONATYPE_GPG_KEY_BASE64 did not decode to an armoured PGP private key"; exit 1 ;;
98+
esac
99+
- ./gradlew --console=colored --no-configuration-cache -PpreReleasesAsSnapshot=true publishToMavenCentral
88100
cache:
89101
<<: *gradle_cache
90102
policy: pull
91103
rules:
92104
- if: $CI_COMMIT_TAG
93-
when: manual
94-
allow_failure: true
95105
needs:
96106
- job: "build_libraries"
97107
- job: "test_libraries"

‎buildSrc/src/main/kotlin/common-maven.gradle.kts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,22 @@ group = "com.caplin.integration.datasourcex"
55
val configuredVersion =
66
System.getenv("CI_COMMIT_TAG") ?: System.getenv("CI_COMMIT_REF_SLUG") ?: "dev"
77

8-
version = configuredVersion
8+
// Maven Central counts releases and files against a monthly quota, so pre-release tags (X.Y.Z-rcN)
9+
// publish there as an overwriting X.Y.Z-SNAPSHOT to the quota-exempt snapshot repository. Artifactory
10+
// takes the literal tag version, which is what routes an rc tag to caplin-rc; only the
11+
// publish_maven_central job passes -PpreReleasesAsSnapshot=true.
12+
val preReleasesAsSnapshot = providers.gradleProperty("preReleasesAsSnapshot").orNull.toBoolean()
13+
14+
version =
15+
if (preReleasesAsSnapshot && configuredVersion.contains('-')) {
16+
"${configuredVersion.substringBefore('-')}-SNAPSHOT"
17+
} else {
18+
configuredVersion
19+
}
920

1021
mavenPublishing {
11-
// Kept registered but not run by default CI — Artifactory is the active publish target.
12-
// See the manual, tag-gated publish_maven_central job in .gitlab-ci.yml.
22+
// Release deployments land staged in the Central Portal and need releasing there by hand;
23+
// snapshots upload straight to the snapshot repository. See the publish_maven_central job.
1324
publishToMavenCentral()
1425

1526
// Only sign when a signing key is configured (as CI does via ORG_GRADLE_PROJECT_signingInMemoryKey).

0 commit comments

Comments
 (0)