|
| 1 | +# This workflow will build a Java project with Maven and publish it to Maven Central Repository |
| 2 | +# ref: https://github.com/actions/setup-java/blob/v3.11.0/docs/advanced-usage.md#Publishing-using-Apache-Maven |
| 3 | + |
| 4 | +# Secrets required: |
| 5 | +# - MAVEN_USERNAME: Username for Maven Central Repository |
| 6 | +# - MAVEN_CENTRAL_TOKEN: Token/password for Maven Central Repository |
| 7 | +# - MAVEN_GPG_PRIVATE_KEY: GPG private key to sign the artifacts (string) |
| 8 | +# - MAVEN_GPG_PASSPHRASE: Passphrase for the GPG private key |
| 9 | + |
| 10 | +name: Publish library to Maven Central Repository |
| 11 | + |
| 12 | +on: |
| 13 | + release: |
| 14 | + types: [ created ] |
| 15 | + secrets: |
| 16 | + MAVEN_USERNAME: |
| 17 | + required: true |
| 18 | + MAVEN_CENTRAL_TOKEN: |
| 19 | + required: true |
| 20 | + MAVEN_GPG_PRIVATE_KEY: |
| 21 | + required: true |
| 22 | + MAVEN_GPG_PASSPHRASE: |
| 23 | + required: true |
| 24 | + workflow_dispatch: ~ |
| 25 | + |
| 26 | +jobs: |
| 27 | + release: |
| 28 | + runs-on: ubuntu-20.04 |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + |
| 35 | + - name: Install JDK |
| 36 | + uses: actions/setup-java@v3 |
| 37 | + with: |
| 38 | + distribution: "zulu" |
| 39 | + java-version: "22" # Always use the latest JDK |
| 40 | + server-id: "ossrh" |
| 41 | + # define environmental variable names |
| 42 | + server-username: MAVEN_USERNAME |
| 43 | + server-password: MAVEN_CENTRAL_TOKEN |
| 44 | + gpg-passphrase: MAVEN_GPG_PASSPHRASE |
| 45 | + gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} |
| 46 | + |
| 47 | + - name: Clean, build and publish to Apache Maven Central |
| 48 | + run: make publish pass=${{ secrets.MAVEN_GPG_PASSPHRASE }} |
| 49 | + env: |
| 50 | + MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} |
| 51 | + MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }} |
| 52 | + MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} |
| 53 | + |
| 54 | + - name: Upload output files to release |
| 55 | + |
| 56 | + with: |
| 57 | + files: "target/*.jar;target/*.pom;target/*.asc" |
| 58 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments