|
| 1 | +name: Publish Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: [Build] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + branches: |
| 9 | + - 'releases/**' |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read # to fetch code (actions/checkout) |
| 13 | + |
| 14 | +env: |
| 15 | + LANG: 'en_US.UTF-8' |
| 16 | + |
| 17 | +jobs: |
| 18 | + check-version: |
| 19 | + # only run in the official pmd/build-tools repo, where we have access to the secrets and not on forks |
| 20 | + # and only run for _successful_ push workflow runs on tags "releases/**". |
| 21 | + if: ${{ github.repository == 'pmd/build-tools' |
| 22 | + && github.event.workflow_run.event == 'push' |
| 23 | + && startsWith('releases/', github.event.workflow_run.head_branch) |
| 24 | + && github.event.workflow_run.conclusion == 'success' }} |
| 25 | + runs-on: ubuntu-latest |
| 26 | + timeout-minutes: 10 |
| 27 | + defaults: |
| 28 | + run: |
| 29 | + shell: bash |
| 30 | + outputs: |
| 31 | + VERSION: ${{ steps.version.outputs.VERSION }} |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + ref: ${{ github.event.workflow_run.head_branch }} |
| 36 | + - uses: actions/setup-java@v4 |
| 37 | + with: |
| 38 | + distribution: 'temurin' |
| 39 | + java-version: '11' |
| 40 | + cache: 'maven' |
| 41 | + - name: Determine Version |
| 42 | + id: version |
| 43 | + env: |
| 44 | + REF: ${{ github.event.workflow_run.head_branch }} |
| 45 | + run: | |
| 46 | + if ! git show-ref --exists "refs/tags/$REF"; then |
| 47 | + echo "::error ::Tag $REF does not exist, aborting." |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | + |
| 51 | + VERSION=$(./mvnw --batch-mode --no-transfer-progress help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 52 | + echo "Determined VERSION=$VERSION" |
| 53 | + if [[ "$VERSION" = *-SNAPSHOT ]]; then |
| 54 | + echo "::error ::VERSION=$VERSION is a snapshot version, aborting." |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" |
| 58 | +
|
| 59 | + deploy-to-maven-central: |
| 60 | + needs: check-version |
| 61 | + # use environment maven-central, where secrets are configured for OSSRH_* |
| 62 | + environment: |
| 63 | + name: maven-central |
| 64 | + url: https://repo.maven.apache.org/maven2/net/sourceforge/pmd/pmd-build-tools-config/ |
| 65 | + runs-on: ubuntu-latest |
| 66 | + timeout-minutes: 20 |
| 67 | + defaults: |
| 68 | + run: |
| 69 | + shell: bash |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + with: |
| 73 | + ref: ${{ github.event.workflow_run.head_branch }} |
| 74 | + - uses: actions/setup-java@v4 |
| 75 | + with: |
| 76 | + distribution: 'temurin' |
| 77 | + java-version: '11' |
| 78 | + cache: 'maven' |
| 79 | + server-id: ossrh |
| 80 | + server-username: MAVEN_USERNAME |
| 81 | + server-password: MAVEN_PASSWORD |
| 82 | + gpg-passphrase: MAVEN_GPG_PASSPHRASE |
| 83 | + gpg-private-key: ${{ secrets.PMD_CI_GPG_PRIVATE_KEY }} |
| 84 | + - name: Build and Publish |
| 85 | + env: |
| 86 | + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} |
| 87 | + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} |
| 88 | + MAVEN_GPG_PASSPHRASE: ${{ secrets.PMD_CI_GPG_PASSPHRASE }} |
| 89 | + run: | |
| 90 | + ./mvnw --show-version --errors --batch-mode \ |
| 91 | + -Psign \ |
| 92 | + deploy |
0 commit comments