|
| 1 | +name: Release |
| 2 | +# Required secrets / variables: |
| 3 | +# |
| 4 | +# Secrets are loaded from 1Password when both of the following are set: |
| 5 | +# - secrets.OP_SERVICE_ACCOUNT_TOKEN — 1Password service account token |
| 6 | +# - vars.ONE_PASSWORD_SECRET_REFERENCES — 1Password secret references for the variables below |
| 7 | +# |
| 8 | +# Without 1Password, set these GitHub repository secrets directly as a fallback: |
| 9 | +# - MAVEN_GPG_PRIVATE_KEY — armored GPG private key (used to sign artifacts) |
| 10 | +# - MAVEN_GPG_PASSPHRASE — passphrase for the GPG key |
| 11 | +# - MAVEN_CENTRAL_PORTAL_TOKEN_USERNAME — Maven Central portal token username |
| 12 | +# - MAVEN_CENTRAL_PORTAL_TOKEN_PASSWORD — Maven Central portal token password |
| 13 | + |
| 14 | +# Triggered when a GitHub release is published (released). |
| 15 | +# Builds, signs, and publishes all artifacts to Maven Central automatically. |
| 16 | +# The CLI fat jar is also uploaded to the GitHub release assets. |
| 17 | +# |
| 18 | +# The project version is derived from the git tag (e.g. v3.0.0 → 3.0.0) and applied to all |
| 19 | +# modules in-place via versions:set before building. No pom.xml version commits are needed. |
| 20 | +on: |
| 21 | + release: |
| 22 | + types: [released] |
| 23 | + |
| 24 | +env: |
| 25 | + java_version: '17' |
| 26 | + java_distribution: 'zulu' |
| 27 | + |
| 28 | +jobs: |
| 29 | + release: |
| 30 | + runs-on: ubuntu-24.04 |
| 31 | + permissions: |
| 32 | + contents: write |
| 33 | + env: |
| 34 | + HAS_1PASSWORD: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN != '' && vars.ONE_PASSWORD_SECRET_REFERENCES != '' }} |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v5 |
| 37 | + with: |
| 38 | + fetch-depth: 0 |
| 39 | + # Check out the exact tagged commit so the version is correctly resolved from the tag. |
| 40 | + ref: ${{ github.event.release.tag_name }} |
| 41 | + - name: Set up JDK ${{ env.java_version }}-${{ env.java_distribution }} |
| 42 | + uses: actions/setup-java@v5 |
| 43 | + with: |
| 44 | + java-version: ${{ env.java_version }} |
| 45 | + distribution: ${{ env.java_distribution }} |
| 46 | + - name: Print Java and Maven versions |
| 47 | + run: mvn --version |
| 48 | + - name: Cache Maven dependencies |
| 49 | + uses: actions/cache@v4 |
| 50 | + with: |
| 51 | + path: ~/.m2/repository |
| 52 | + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} |
| 53 | + restore-keys: | |
| 54 | + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} |
| 55 | + ${{ runner.os }}-maven- |
| 56 | + ${{ runner.os }}- |
| 57 | + - name: Load secrets from 1Password |
| 58 | + if: env.HAS_1PASSWORD == 'true' |
| 59 | + # Pinned to a specific tag for supply-chain safety. Update the tag in gtfs-validator if the action changes. |
| 60 | + uses: MobilityData/gtfs-validator/.github/actions/extract-1password-secret@USED_BY_GBFS_VALIDATOR_JAVA # 7bf2832 |
| 61 | + with: |
| 62 | + OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} |
| 63 | + VARIABLES_TO_EXTRACT: 'MAVEN_GPG_PASSPHRASE, MAVEN_GPG_PRIVATE_KEY, MAVEN_CENTRAL_PORTAL_TOKEN_USERNAME, MAVEN_CENTRAL_PORTAL_TOKEN_PASSWORD' |
| 64 | + ONE_PASSWORD_SECRET_REFERENCES: ${{ vars.ONE_PASSWORD_SECRET_REFERENCES }} |
| 65 | + - name: Load secrets from GitHub secrets (fallback for forks without 1Password) |
| 66 | + if: env.HAS_1PASSWORD != 'true' |
| 67 | + env: |
| 68 | + GPG_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} |
| 69 | + GPG_PASS: ${{ secrets.MAVEN_GPG_PASSPHRASE }} |
| 70 | + MVN_USER: ${{ secrets.MAVEN_CENTRAL_PORTAL_TOKEN_USERNAME }} |
| 71 | + MVN_PASS: ${{ secrets.MAVEN_CENTRAL_PORTAL_TOKEN_PASSWORD }} |
| 72 | + run: | |
| 73 | + { |
| 74 | + echo "MAVEN_GPG_PASSPHRASE=$GPG_PASS" |
| 75 | + echo "MAVEN_GPG_PRIVATE_KEY<<GPG_EOF" |
| 76 | + echo "$GPG_KEY" |
| 77 | + echo "GPG_EOF" |
| 78 | + echo "MAVEN_CENTRAL_PORTAL_TOKEN_USERNAME=$MVN_USER" |
| 79 | + echo "MAVEN_CENTRAL_PORTAL_TOKEN_PASSWORD=$MVN_PASS" |
| 80 | + } >> "$GITHUB_ENV" |
| 81 | + - name: Set release version from tag |
| 82 | + run: | |
| 83 | + TAG="${{ github.event.release.tag_name }}" |
| 84 | + VERSION="${TAG#v}" |
| 85 | + echo "Setting version: $VERSION" |
| 86 | + mvn --batch-mode -ntp versions:set -DnewVersion="$VERSION" -DprocessAllModules=true -DgenerateBackupPoms=false |
| 87 | + - name: Verify version is not placeholder |
| 88 | + run: | |
| 89 | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 90 | + if [[ "$VERSION" == *"placeholder"* || "$VERSION" == "0.0.0"* ]]; then |
| 91 | + echo "ERROR: Version is still '$VERSION' — aborting release." |
| 92 | + exit 1 |
| 93 | + fi |
| 94 | + echo "Version OK: $VERSION" |
| 95 | + - name: Stage artifacts |
| 96 | + run: mvn deploy -Ppublication -Dprettier.skip=true -ntp |
| 97 | + - name: Upload CLI fat jar to GitHub release |
| 98 | + run: | |
| 99 | + gh release upload "${{ github.event.release.tag_name }}" \ |
| 100 | + gbfs-validator-java-cli/target/gbfs-validator-cli.jar \ |
| 101 | + --clobber |
| 102 | + env: |
| 103 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + - name: Deploy to Maven Central |
| 105 | + env: |
| 106 | + JRELEASER_GPG_PASSPHRASE: ${{ env.MAVEN_GPG_PASSPHRASE }} |
| 107 | + JRELEASER_GPG_SECRET_KEY: ${{ env.MAVEN_GPG_PRIVATE_KEY }} |
| 108 | + run: mvn jreleaser:deploy -Djreleaser.output.directory=out -ntp -N |
| 109 | + - name: Upload JReleaser output |
| 110 | + if: always() |
| 111 | + uses: actions/upload-artifact@v4 |
| 112 | + with: |
| 113 | + name: jreleaser-release-logs |
| 114 | + path: out/ |
0 commit comments