|
| 1 | +name: Publish Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: [Build] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + branches: |
| 9 | + - '**' |
| 10 | + - '!main' |
| 11 | + - '!dependabot/**' |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read # to fetch code (actions/checkout) |
| 15 | + |
| 16 | +env: |
| 17 | + LANG: 'en_US.UTF-8' |
| 18 | + |
| 19 | +jobs: |
| 20 | + check-version: |
| 21 | + # only run in the official pmd/pmd-designer repo, where we have access to the secrets and not on forks |
| 22 | + # and only run for _successful_ push workflow runs on tags. |
| 23 | + if: ${{ github.repository == 'pmd/designer' |
| 24 | + && contains(fromJSON('["push", "workflow_dispatch"]'), github.event.workflow_run.event) |
| 25 | + && github.event.workflow_run.head_branch != 'main' |
| 26 | + && github.event.workflow_run.conclusion == 'success' }} |
| 27 | + runs-on: ubuntu-latest |
| 28 | + timeout-minutes: 10 |
| 29 | + defaults: |
| 30 | + run: |
| 31 | + shell: bash |
| 32 | + outputs: |
| 33 | + VERSION: ${{ steps.version.outputs.VERSION }} |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + ref: ${{ github.event.workflow_run.head_branch }} |
| 38 | + - uses: actions/setup-java@v4 |
| 39 | + with: |
| 40 | + distribution: 'temurin' |
| 41 | + java-version: '11' |
| 42 | + cache: 'maven' |
| 43 | + - name: Determine Version |
| 44 | + id: version |
| 45 | + env: |
| 46 | + REF: ${{ github.event.workflow_run.head_branch }} |
| 47 | + run: | |
| 48 | + if ! git show-ref --exists "refs/tags/$REF"; then |
| 49 | + echo "::error ::Tag $REF does not exist, aborting." |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + |
| 53 | + VERSION=$(./mvnw --batch-mode --no-transfer-progress help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 54 | + echo "Determined VERSION=$VERSION" |
| 55 | + if [[ "$VERSION" = *-SNAPSHOT ]]; then |
| 56 | + echo "::error ::VERSION=$VERSION is a snapshot version, aborting." |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" |
| 60 | + - name: Add Job Summary |
| 61 | + env: |
| 62 | + WORKFLOW_RUN_DISPLAY_TITLE: ${{ github.event.workflow_run.display_title }} |
| 63 | + WORKFLOW_RUN_NAME: ${{ github.event.workflow_run.name }} |
| 64 | + WORKFLOW_RUN_NUMBER: ${{ github.event.workflow_run.run_number }} |
| 65 | + WORKFLOW_RUN_HTML_URL: ${{ github.event.workflow_run.html_url }} |
| 66 | + VERSION: ${{ steps.version.outputs.VERSION }} |
| 67 | + TAG: ${{ github.event.workflow_run.head_branch }} |
| 68 | + run: | |
| 69 | + echo "### Run Info" >> "${GITHUB_STEP_SUMMARY}" |
| 70 | + echo "Building Version: ${VERSION}" >> "${GITHUB_STEP_SUMMARY}" |
| 71 | + echo "" >> "${GITHUB_STEP_SUMMARY}" |
| 72 | + echo "Tag: ${TAG}" >> "${GITHUB_STEP_SUMMARY}" |
| 73 | + echo "" >> "${GITHUB_STEP_SUMMARY}" |
| 74 | + echo "Called by [${WORKFLOW_RUN_DISPLAY_TITLE} (${WORKFLOW_RUN_NAME} #${WORKFLOW_RUN_NUMBER})](${WORKFLOW_RUN_HTML_URL})" >> "${GITHUB_STEP_SUMMARY}" |
| 75 | + echo "" >> "${GITHUB_STEP_SUMMARY}" |
| 76 | +
|
| 77 | + deploy-to-maven-central: |
| 78 | + needs: check-version |
| 79 | + # use environment maven-central, where secrets are configured for OSSRH_* |
| 80 | + environment: |
| 81 | + name: maven-central |
| 82 | + url: https://repo.maven.apache.org/maven2/net/sourceforge/pmd/pmd-designer/ |
| 83 | + runs-on: ubuntu-latest |
| 84 | + timeout-minutes: 20 |
| 85 | + permissions: |
| 86 | + contents: write # to create a new release |
| 87 | + defaults: |
| 88 | + run: |
| 89 | + shell: bash |
| 90 | + steps: |
| 91 | + - uses: actions/checkout@v4 |
| 92 | + with: |
| 93 | + ref: ${{ github.event.workflow_run.head_branch }} |
| 94 | + - uses: actions/setup-java@v4 |
| 95 | + with: |
| 96 | + distribution: 'temurin' |
| 97 | + java-version: '11' |
| 98 | + cache: 'maven' |
| 99 | + server-id: ossrh |
| 100 | + server-username: MAVEN_USERNAME |
| 101 | + server-password: MAVEN_PASSWORD |
| 102 | + gpg-passphrase: MAVEN_GPG_PASSPHRASE |
| 103 | + gpg-private-key: ${{ secrets.PMD_CI_GPG_PRIVATE_KEY }} |
| 104 | + - name: Build and Publish |
| 105 | + env: |
| 106 | + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} |
| 107 | + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} |
| 108 | + MAVEN_GPG_PASSPHRASE: ${{ secrets.PMD_CI_GPG_PASSPHRASE }} |
| 109 | + run: | |
| 110 | + ./mvnw --show-version --errors --batch-mode \ |
| 111 | + -Psign,shading \ |
| 112 | + deploy |
| 113 | + - name: Prepare Release Notes |
| 114 | + run: | |
| 115 | + BEGIN_LINE=$(grep -n "^## " CHANGELOG.md|head -1|cut -d ":" -f 1) |
| 116 | + BEGIN_LINE=$((BEGIN_LINE + 1)) |
| 117 | + END_LINE=$(grep -n "^## " CHANGELOG.md|head -2|tail -1|cut -d ":" -f 1) |
| 118 | + END_LINE=$((END_LINE - 1)) |
| 119 | + RELEASE_BODY="$(head -$END_LINE CHANGELOG.md | tail -$((END_LINE - BEGIN_LINE)))" |
| 120 | + echo "$RELEASE_BODY" > release_notes.md |
| 121 | + - name: Create Release |
| 122 | + env: |
| 123 | + TAG_NAME: ${{ github.event.workflow_run.head_branch }} |
| 124 | + VERSION: ${{ needs.check-version.outputs.VERSION }} |
| 125 | + run: | |
| 126 | + # Note: The release asset is the shaded jar |
| 127 | + gh release create "$TAG_NAME" "target/pmd-designer-${VERSION}.jar" \ |
| 128 | + --verify-tag \ |
| 129 | + --notes-file release_notes.md \ |
| 130 | + --title "$VERSION" |
0 commit comments