diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..c3df9a9 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,46 @@ +name: Publish to Maven Central + +# Runs when a version tag is pushed (git tag v0.1.1 && git push origin v0.1.1). +# One-time setup: +# 1. Verify the namespace "technology.corvo" at https://central.sonatype.com (Namespaces). +# 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). +on: + push: + tags: ["v*"] + +jobs: + publish: + runs-on: ubuntu-latest + environment: maven-central + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "17" + cache: maven + server-id: central + server-username: CENTRAL_USERNAME + server-password: CENTRAL_PASSWORD + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: GPG_PASSPHRASE + + - name: The tag must match the project version + run: | + VERSION=$(mvn -q -B help:evaluate -Dexpression=project.version -DforceStdout) + test "v$VERSION" = "$GITHUB_REF_NAME" || { echo "Tag $GITHUB_REF_NAME does not match version $VERSION"; exit 1; } + + - name: Test + run: mvn -B verify + + - name: Deploy + run: mvn -B -DskipTests -Prelease deploy + env: + CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }} + CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} diff --git a/pom.xml b/pom.xml index 222043b..1ccdf37 100644 --- a/pom.xml +++ b/pom.xml @@ -93,4 +93,73 @@ + + + + release + + + + org.apache.maven.plugins + maven-source-plugin + 3.3.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.10.1 + + none + + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.2.7 + + + sign-artifacts + verify + + sign + + + + --pinentry-mode + loopback + + + + + + + org.sonatype.central + central-publishing-maven-plugin + 0.6.0 + true + + central + false + + + + + +