Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <id>) 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*"]
Expand Down Expand Up @@ -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
12 changes: 1 addition & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
</plugins>
</build>
<profiles>
<!-- Used only to publish to Maven Central: mvn -B -Prelease deploy -->
<!-- Used only to publish to Maven Central: mvn -B -Prelease verify, then scripts/central-bundle.sh -->
<profile>
<id>release</id>
<build>
Expand Down Expand Up @@ -148,16 +148,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.6.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<autoPublish>false</autoPublish>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Expand Down
30 changes: 30 additions & 0 deletions scripts/central-bundle.sh
Original file line number Diff line number Diff line change
@@ -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'
Loading