From 457f6b6344543ecc3eacc119babb85d7e9aaa07a Mon Sep 17 00:00:00 2001 From: dudiedri Date: Wed, 23 Sep 2026 13:18:59 +0300 Subject: [PATCH 1/2] ci(publish): fail loudly on missing credentials, and pin the tag to the pom The publish workflow has never actually published. Releases 1.1.0 and 1.2.0 reached Maven Central by hand: no v1.1.0 or v1.2.0 tags exist, the workflow last ran for v1.0.4 in August and that run failed, and none of the four secrets it needs are configured at repo or org level. Publishing by hand from whatever branch happened to be checked out is how main ended up behind Central, missing the getAssetHolders that 1.2.0 shipped. Four changes: * Check the four secrets up front and name the missing ones. Previously a missing GPG_PRIVATE_KEY surfaced as "gpg --batch --import" failing on empty input, which says nothing about the cause. Presence is tested with a length check, so no secret value is echoed, compared or logged. * Refuse to publish when the tag disagrees with the pom. The tag is only a label; the version that reaches Central comes from the pom, so v1.3.0 could silently publish 1.4.0. That ambiguity is what this repo just spent a release untangling. * Run the suite in the release build. A tag can point at any commit, including one that never went through a PR, so trusting build.yml to have covered it is not safe. The old comment justified skipping tests by "drifted/absent test sources", which is stale - 44 tests pass on main. * State in the job summary that a green run means staged, not live. autoPublish is false, so the deployment still has to be released in the Central portal, and a green check otherwise reads as "it is on Central" when it is not. Also adds workflow_dispatch so a release can be re-driven without cutting a new tag. Co-Authored-By: Claude Opus 5 --- .github/workflows/publish.yml | 76 +++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e6f335c..2ea11ae 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,6 +2,11 @@ name: publish on: push: tags: ['v*'] + workflow_dispatch: + inputs: + ref: + description: 'Tag or SHA to publish (must already carry the intended pom version)' + required: true jobs: publish: runs-on: ubuntu-latest @@ -9,6 +14,35 @@ jobs: contents: read steps: - uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.ref || github.ref }} + + # Without this the job dies later at "gpg --batch --import" reading an empty + # variable, which says nothing about the cause. Presence is tested via a length + # check so no secret value is ever echoed, compared, or written to the log. + # OX Agent: Sensitive Data Protection prevented — secrets stay in the secret store, + # only their presence is tested, never their value. + - name: Check publishing credentials are configured + env: + CENTRAL_TOKEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }} + CENTRAL_TOKEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }} + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + run: | + missing="" + for name in CENTRAL_TOKEN_USERNAME CENTRAL_TOKEN_PASSWORD GPG_PRIVATE_KEY GPG_PASSPHRASE; do + eval "value=\${$name}" + [ -n "$value" ] || missing="$missing $name" + done + if [ -n "$missing" ]; then + echo "::error::Missing repository secrets:$missing" + echo "Set each with: gh secret set --repo ${{ github.repository }}" >> "$GITHUB_STEP_SUMMARY" + echo "Releases 1.1.0 and 1.2.0 were published by hand because these were never configured," >> "$GITHUB_STEP_SUMMARY" + echo "which is how main drifted behind Maven Central. Configure them so releases are reproducible." >> "$GITHUB_STEP_SUMMARY" + exit 1 + fi + echo "All four publishing secrets are present." + - uses: actions/setup-java@v4 with: distribution: temurin @@ -17,6 +51,27 @@ jobs: server-id: central server-username: MAVEN_USERNAME server-password: MAVEN_PASSWORD + + # The tag is only a label; the version that reaches Central comes from the pom. + # When they disagree, v1.3.0 silently publishes 1.4.0 (or worse, republishes an + # existing version), which is exactly the ambiguity that let this repo's main and + # Maven Central diverge. Refuse rather than guess. + - name: Verify the tag matches the pom version + if: startsWith(github.ref, 'refs/tags/v') + run: | + pom_version=$(mvn -B -q -DforceStdout help:evaluate -Dexpression=project.version) + tag_version="${GITHUB_REF_NAME#v}" + echo "tag: $tag_version pom: $pom_version" + if [ "$pom_version" != "$tag_version" ]; then + echo "::error::Tag $GITHUB_REF_NAME does not match pom version $pom_version. Bump the pom and re-tag." + exit 1 + fi + + # A tag can point at any commit, including one that never went through a PR, so the + # release build runs the suite itself rather than trusting build.yml to have covered it. + - name: Build and test + run: mvn -B verify + - name: Import GPG key run: | echo "${GPG_PRIVATE_KEY}" | gpg --batch --import @@ -24,12 +79,27 @@ jobs: echo "max-cache-ttl 7200" >> ~/.gnupg/gpg-agent.conf env: GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} - # A maintainer must configure CENTRAL_TOKEN_USERNAME, CENTRAL_TOKEN_PASSWORD, - # GPG_PRIVATE_KEY and GPG_PASSPHRASE as repo secrets for this to work. - # Skip tests to allow drifted/absent test sources; unit tests run in build.yml on PRs. + - name: Publish to Maven Central run: mvn -B -Prelease deploy -Dmaven.test.skip=true env: MAVEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }} MAVEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }} MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + + # autoPublish is false in the release profile, so a green run means the deployment + # is VALIDATED AND STAGED, not live. Someone still has to release it in the Central + # portal. Said out loud here so a green check is not mistaken for "it is on Central". + - name: Say what green actually means + run: | + { + echo "### Staged, not yet live" + echo "" + echo "\`autoPublish\` is \`false\`, so this upload is validated and **staged**." + echo "Release it at https://central.sonatype.com/publishing/deployments for it to appear on Maven Central." + echo "" + echo "Verify afterwards:" + echo '```' + echo "curl -s https://repo1.maven.org/maven2/io/github/gero-labs/nexus-java-client/maven-metadata.xml | grep ''" + echo '```' + } >> "$GITHUB_STEP_SUMMARY" From a84174407ba79bc6ce42d1f36e2797d74acdde63 Mon Sep 17 00:00:00 2001 From: dudiedri Date: Wed, 23 Sep 2026 13:33:08 +0300 Subject: [PATCH 2/2] ci(publish): prove the signing key works instead of asserting the secret is set Two problems with the presence check this replaces. It rejected a legitimately unprotected key. A dedicated release key with no passphrase is a reasonable setup - once the private key lives in GitHub secrets, a passphrase stored beside it protects against very little - and requiring GPG_PASSPHRASE non-empty turned that setup into a failed release. More importantly, presence tells you nothing about correctness: a wrong passphrase passes a non-empty check and then fails part-way through the deploy. So the key now has to produce a real signature before anything is uploaded. That catches a wrong passphrase, a missing one, and a GPG_PRIVATE_KEY that imported nothing, and it reports which. Worth recording why this is trustworthy in CI but not locally: gpg-agent caches an unlocked key, so on a developer machine a signing test succeeds with ANY passphrase once the key has been unlocked - verified here, where "total-garbage-xyz" signed successfully until the agent cache was flushed. A fresh runner has no agent cache, so the test cannot be fooled that way. Co-Authored-By: Claude Opus 5 --- .github/workflows/publish.yml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2ea11ae..404a6b9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -30,12 +30,13 @@ jobs: GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} run: | missing="" - for name in CENTRAL_TOKEN_USERNAME CENTRAL_TOKEN_PASSWORD GPG_PRIVATE_KEY GPG_PASSPHRASE; do + for name in CENTRAL_TOKEN_USERNAME CENTRAL_TOKEN_PASSWORD GPG_PRIVATE_KEY; do eval "value=\${$name}" [ -n "$value" ] || missing="$missing $name" done if [ -n "$missing" ]; then echo "::error::Missing repository secrets:$missing" + echo "(GPG_PASSPHRASE is deliberately not required: a dedicated release key may be unprotected.)" echo "Set each with: gh secret set --repo ${{ github.repository }}" >> "$GITHUB_STEP_SUMMARY" echo "Releases 1.1.0 and 1.2.0 were published by hand because these were never configured," >> "$GITHUB_STEP_SUMMARY" echo "which is how main drifted behind Maven Central. Configure them so releases are reproducible." >> "$GITHUB_STEP_SUMMARY" @@ -80,6 +81,27 @@ jobs: env: GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + # Presence checks cannot tell a correct passphrase from a wrong one, and an + # unprotected release key legitimately has none at all. So instead of asserting on + # the secret, make the key produce a real signature: this fails in seconds with + # "Bad passphrase" rather than part-way through a deploy. + - name: Verify the signing key can sign + env: + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + run: | + key_id=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec:/ {print $5; exit}') + if [ -z "$key_id" ]; then + echo "::error::No secret key was imported from GPG_PRIVATE_KEY." + exit 1 + fi + echo "signing key: $key_id" + if ! echo verify | gpg --batch --yes --pinentry-mode loopback \ + --passphrase "${GPG_PASSPHRASE}" --local-user "$key_id" --sign -o /dev/null; then + echo "::error::The imported key could not sign. If it is passphrase-protected, GPG_PASSPHRASE is missing or wrong; if it is unprotected, leave GPG_PASSPHRASE empty." + exit 1 + fi + echo "Signing key works." + - name: Publish to Maven Central run: mvn -B -Prelease deploy -Dmaven.test.skip=true env: