Skip to content

ci(publish): fail loudly on missing credentials, and pin the tag to the pom - #12

Merged
edridudi merged 2 commits into
mainfrom
ci/harden-publish
Sep 23, 2026
Merged

edridudi merged 2 commits into
mainfrom
ci/harden-publish

Conversation

@edridudi

Copy link
Copy Markdown
Member

The workflow has never published anything

Evidence, not inference:

  • No v1.1.0 or v1.2.0 tags exist, yet both versions are on Maven Central
  • publish.yml last ran for v1.0.4 on 2026-08-01, and its most recent attempt failed
  • None of the four secrets it needs are configured — absent at repo level, and the org has zero secrets (total_count: 0; this repo is public, so org secrets would reach it if any existed)

So 1.1.0 and 1.2.0 were published by hand. That is how main drifted behind Central and lost getAssetHolders, which #10 just spent a merge reconciling.

What changes

Fail loudly when credentials are missing. A missing GPG_PRIVATE_KEY currently surfaces as gpg --batch --import failing on empty input — a message that says nothing about the cause. The new preflight names exactly which secrets are absent and prints the gh secret set command. Presence is tested with a length check, so no secret value is ever echoed, compared, or written to the log.

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. v1.3.0 could silently publish 1.4.0, or republish an existing version. That is precisely the ambiguity this repo just spent a release untangling, so it now fails instead of guessing.

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 with "drifted/absent test sources" — stale, since 44 tests pass on main.

Say that green means staged, not live. autoPublish is false in the release profile, so a successful run leaves the deployment validated and staged in the Central portal, awaiting a manual release. A green check currently reads as "it is on Central" when it is not. The job summary now says so and gives the verification command.

Plus workflow_dispatch, so a release can be re-driven without cutting a new tag.

Verified

Both guards were exercised against real inputs rather than eyeballed:

all four unset      -> missing: CENTRAL_TOKEN_USERNAME CENTRAL_TOKEN_PASSWORD GPG_PRIVATE_KEY GPG_PASSPHRASE
two set             -> missing: CENTRAL_TOKEN_PASSWORD GPG_PRIVATE_KEY
all four set        -> missing: []

mvn help:evaluate   -> 1.4.0
  vs tag v1.4.0     -> MATCH
  vs tag v1.3.0     -> MISMATCH (correctly refuses)

Still needs a maintainer

This makes the failure legible; it cannot make it go away. The four secrets have to be set by someone who holds them:

gh secret set CENTRAL_TOKEN_USERNAME --repo Gero-Labs/nexus-java-client
gh secret set CENTRAL_TOKEN_PASSWORD --repo Gero-Labs/nexus-java-client
gh secret set GPG_PRIVATE_KEY        --repo Gero-Labs/nexus-java-client
gh secret set GPG_PASSPHRASE         --repo Gero-Labs/nexus-java-client

gh secret set prompts for the value, so nothing lands in shell history.

Until then, tagging v1.4.0 fails at the preflight with a clear message instead of dying at the GPG import — which is the intended behaviour, not a regression.

🤖 Generated with Claude Code

dudiedri and others added 2 commits September 23, 2026 13:18
…he 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 <noreply@anthropic.com>
…ret 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 <noreply@anthropic.com>
@edridudi

Copy link
Copy Markdown
Member Author

Pushed a841744, replacing the GPG_PASSPHRASE presence check with a functional one — the workflow now imports the key and makes it produce a real signature before anything is uploaded.

Two reasons. A presence check rejected a legitimately unprotected release key, and more importantly it proved nothing: a wrong passphrase passes a non-empty check and then fails part-way through the deploy.

Found the hard way while writing a local passphrase checker for this repo's key. It reported CORRECT for a passphrase I knew was wrong, because gpg-agent caches an unlocked key — total-garbage-xyz signed successfully until the agent cache was flushed with gpg-connect-agent reloadagent /bye. A fresh CI runner has no agent cache, so the same test is trustworthy there. That caveat is recorded in the commit message so nobody reuses the check locally and draws a false conclusion.

All four secrets are now configured on this repo, so the next tag exercises the real path.

@edridudi
edridudi merged commit 4660c7d into main Sep 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant