From 9b37c5fe3fc4c61e2f9f3e1f5d1a9355a33ebd97 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Sat, 17 Oct 2026 10:46:45 -0300 Subject: [PATCH] ci: build the Central bundle ourselves and upload it with the Portal API The central-publishing plugin staged maven-metadata-local.xml and _remote.repositories into the bundle and Central rejected it ("Bundle has content that does NOT have a .pom file"). Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/publish.yml | 33 ++++++++++++++++++++++++++++----- pom.xml | 12 +----------- scripts/central-bundle.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 16 deletions(-) create mode 100755 scripts/central-bundle.sh diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b3b9fe6..3cb0e82 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,8 +6,8 @@ name: Publish to Maven Central # 2. Create a Central user token and add the repository secrets CENTRAL_USERNAME and CENTRAL_PASSWORD. # 3. Create a GPG key (gpg --full-generate-key), publish its public key to keyserver.ubuntu.com, # and add the secrets GPG_PRIVATE_KEY (gpg --armor --export-secret-keys ) and GPG_PASSPHRASE. -# The deployment is uploaded to Central and waits for you to release it in the portal -# (autoPublish is off in the pom's release profile). +# The bundle is built by scripts/central-bundle.sh and uploaded with the Central Portal API as a +# user-managed deployment: it waits for you to click Publish in the portal. on: push: tags: ["v*"] @@ -38,9 +38,32 @@ jobs: - name: Test run: mvn -B verify - - name: Deploy - run: mvn -B -DskipTests -Prelease deploy + - name: Sign and build the artifacts + run: mvn -B -DskipTests -Prelease verify + env: + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + + - name: Build the Central bundle + run: scripts/central-bundle.sh + + - name: Upload the bundle to Central and wait for validation env: CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }} CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }} - GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + run: | + TOKEN=$(printf '%s:%s' "$CENTRAL_USERNAME" "$CENTRAL_PASSWORD" | base64 | tr -d '\n') + ID=$(curl --fail-with-body -sS -X POST \ + "https://central.sonatype.com/api/v1/publisher/upload?name=corvo-nfse-${GITHUB_REF_NAME}&publishingType=USER_MANAGED" \ + -H "Authorization: Bearer $TOKEN" -F "bundle=@target/central-bundle.zip") + echo "Deployment id: $ID" + for i in $(seq 1 40); do + STATUS=$(curl -sS -X POST "https://central.sonatype.com/api/v1/publisher/status?id=$ID" -H "Authorization: Bearer $TOKEN") + STATE=$(printf '%s' "$STATUS" | python3 -c 'import sys,json; print(json.load(sys.stdin).get("deploymentState",""))') + echo "state: $STATE" + case "$STATE" in + VALIDATED|PUBLISHING|PUBLISHED) echo "Validated. Release it in https://central.sonatype.com/publishing/deployments"; exit 0 ;; + FAILED) echo "$STATUS"; exit 1 ;; + esac + sleep 10 + done + echo "Timed out waiting for validation"; exit 1 diff --git a/pom.xml b/pom.xml index 3fc37ee..147e3d7 100644 --- a/pom.xml +++ b/pom.xml @@ -94,7 +94,7 @@ - + release @@ -148,16 +148,6 @@ - - org.sonatype.central - central-publishing-maven-plugin - 0.6.0 - true - - central - false - - diff --git a/scripts/central-bundle.sh b/scripts/central-bundle.sh new file mode 100755 index 0000000..b6959bb --- /dev/null +++ b/scripts/central-bundle.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Builds the Maven Central bundle (target/central-bundle.zip) from the signed artifacts that +# `mvn -Prelease verify` leaves in target/. The layout is the plain Maven repository layout with +# an .asc signature and md5/sha1 checksums for every file, and nothing else (the Central publishing +# plugin also staged maven-metadata-local.xml and _remote.repositories, which Central rejects). +set -euo pipefail + +GROUP_PATH="tech/corvo" +ARTIFACT="corvo-nfse" +VERSION="$(mvn -q -B help:evaluate -Dexpression=project.version -DforceStdout)" +DIR="target/central-bundle/${GROUP_PATH}/${ARTIFACT}/${VERSION}" + +rm -rf target/central-bundle target/central-bundle.zip +mkdir -p "$DIR" + +cp pom.xml "${DIR}/${ARTIFACT}-${VERSION}.pom" +for suffix in "" "-sources" "-javadoc"; do + cp "target/${ARTIFACT}-${VERSION}${suffix}.jar" "${DIR}/" +done + +# Detached signatures made by the maven-gpg-plugin (jar, sources, javadoc and pom). +cp target/${ARTIFACT}-${VERSION}*.asc "${DIR}/" + +for f in "${DIR}"/*; do + openssl dgst -md5 -r "$f" | cut -d' ' -f1 | tr -d '\n' > "${f}.md5" + openssl dgst -sha1 -r "$f" | cut -d' ' -f1 | tr -d '\n' > "${f}.sha1" +done + +(cd target/central-bundle && zip -qr ../central-bundle.zip .) +echo "Bundle:"; unzip -l target/central-bundle.zip | awk '{print $4}' | grep -v '^$' | sed '1,2d'