|
| 1 | +name: 'Workflow: Maven Release: Prepare and Perform' |
| 2 | +run-name: 'Workflow Run: Maven Release: Prepare and Perform' |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + dryRun: |
| 7 | + default: true |
| 8 | + description: 'Dry run?' |
| 9 | + type: 'boolean' |
| 10 | + mvnDebug: |
| 11 | + default: false |
| 12 | + description: 'Debug?' |
| 13 | + type: 'boolean' |
| 14 | + mvnTransferLogging: |
| 15 | + default: false |
| 16 | + description: 'Log Maven artifact transfers?' |
| 17 | + type: 'boolean' |
| 18 | +jobs: |
| 19 | + job-mvn-release-prepare-perform: |
| 20 | + name: 'Job: Maven Release: Prepare and Perform' |
| 21 | + permissions: |
| 22 | + contents: 'read' |
| 23 | + runs-on: 'ubuntu-latest' |
| 24 | + steps: |
| 25 | + - id: 'checkout' |
| 26 | + name: 'Step: Check Out Project' |
| 27 | + uses: 'actions/checkout@v4' |
| 28 | + with: |
| 29 | + fetch-depth: 1 |
| 30 | + persist-credentials: false |
| 31 | + - id: 'setup-java' |
| 32 | + name: 'Step: Set Up Java and Maven' |
| 33 | + uses: 'actions/setup-java@v4' |
| 34 | + with: |
| 35 | + cache: 'maven' |
| 36 | + distribution: 'temurin' |
| 37 | + gpg-passphrase: 'GPG_PASSPHRASE' |
| 38 | + gpg-private-key: '${{ secrets.GPG_PRIVATE_KEY }}' |
| 39 | + java-version: '23' |
| 40 | + mvn-toolchain-id: 'Temurin 23' |
| 41 | + mvn-toolchain-vendor: 'openjdk' # see ../../pom.xml |
| 42 | + server-id: 'sonatype-oss-repository-hosting' # see https://github.com/microbean/microbean-parent/blob/master/pom.xml#L38 |
| 43 | + server-password: 'SONATYPE_OSSRH_PASSWORD' |
| 44 | + server-username: 'SONATYPE_OSSRH_USERNAME' |
| 45 | + - id: 'setup-askpass' |
| 46 | + name: 'Step: Set Up GIT_ASKPASS' |
| 47 | + run: | |
| 48 | + install -m 700 /dev/null "${RUNNER_TEMP}/.askpass" # atomically create empty file with appropriate permissions |
| 49 | + cat >> "${RUNNER_TEMP}/.askpass" <<<'#!/bin/bash |
| 50 | + case "${1}" in |
| 51 | + Username*) exec echo x-access-token ;; |
| 52 | + Password*) exec echo "${PUSH_TOKEN}" ;; |
| 53 | + esac' |
| 54 | + - id: 'setup-gpg' |
| 55 | + name: 'Step: Set Up GPG' |
| 56 | + run: | |
| 57 | + echo 'pinentry-mode loopback' >> ~/.gnupg/gpg.conf |
| 58 | + - id: 'mvn-release-prepare' |
| 59 | + name: 'Step: Maven Release: Prepare, Perform and Publish Site' |
| 60 | + env: |
| 61 | + DRY_RUN: '${{ inputs.dryRun }}' |
| 62 | + GIT_ASKPASS: '${{ runner.temp }}/.askpass' |
| 63 | + GPG_PASSPHRASE: '${{ secrets.GPG_PASSPHRASE }}' |
| 64 | + MVN_DEBUG: ${{ inputs.mvnDebug && '--debug' || '' }} |
| 65 | + MVN_TRANSFER_LOGGING: ${{ inputs.mvnTransferLogging && '' || '--no-transfer-progress' }} |
| 66 | + PUSH_TOKEN : '${{ secrets.PUSH_TOKEN }}' # critical; see ${GIT_ASKPASS} file |
| 67 | + SCM_GIT_HTTPS_URL: 'scm:git:${{ github.server_url }}/${{ github.repository }}.git' |
| 68 | + SONATYPE_OSSRH_PASSWORD: '${{ secrets.SONATYPE_OSSRH_PASSWORD }}' |
| 69 | + SONATYPE_OSSRH_STAGING_PROFILE_ID: '${{ vars.SONATYPE_OSSRH_STAGING_PROFILE_ID }}' |
| 70 | + SONATYPE_OSSRH_USERNAME: '${{ secrets.SONATYPE_OSSRH_USERNAME }}' |
| 71 | + shell: 'bash -e {0}' |
| 72 | + run: > |
| 73 | + git config --global user.email '[email protected]' |
| 74 | +
|
| 75 | + git config --global user.name 'microbean' |
| 76 | +
|
| 77 | + echo "::group::Running mvn prepare" |
| 78 | + |
| 79 | + ./mvnw --batch-mode ${MVN_DEBUG} --errors ${MVN_TRANSFER_LOGGING} release:prepare |
| 80 | + -DdryRun="${DRY_RUN}" |
| 81 | + -Darguments="${MVN_TRANSFER_LOGGING}" |
| 82 | + -Dscm.url="${SCM_GIT_HTTPS_URL}" |
| 83 | + |
| 84 | + scm_tag="$(grep '^scm.tag=' release.properties | cut -f 2 -d =)" |
| 85 | +
|
| 86 | + echo "Prepared ${scm_tag}" >> "${GITHUB_STEP_SUMMARY}" |
| 87 | +
|
| 88 | + echo "scm_tag=${scm_tag}" >> "${GITHUB_OUTPUT}" |
| 89 | +
|
| 90 | + echo "::endgroup::" |
| 91 | +
|
| 92 | + echo "::group::Running mvn perform" |
| 93 | + |
| 94 | + set +e |
| 95 | +
|
| 96 | + { |
| 97 | + ./mvnw --batch-mode ${MVN_DEBUG} --errors ${MVN_TRANSFER_LOGGING} release:perform |
| 98 | + -Darguments="${MVN_TRANSFER_LOGGING} -Dscmpublish.dryRun=${DRY_RUN} -Dscmpublish.pubScmUrl=${SCM_GIT_HTTPS_URL} -DskipTests -DstagingProfileId=${SONATYPE_OSSRH_STAGING_PROFILE_ID}" |
| 99 | + -DdryRun="${DRY_RUN}" |
| 100 | + -Dgoals="process-classes,post-site,scm-publish:publish-scm,deploy" |
| 101 | + -Dscm.url="${SCM_GIT_HTTPS_URL}" |
| 102 | + | |
| 103 | + tee /dev/fd/3 |
| 104 | + | |
| 105 | + grep --invert-match --silent 'Java class com.sonatype.nexus.staging.api.dto.StagingProfileRepositoryDTO' || cat > /dev/null |
| 106 | + ; |
| 107 | + } |
| 108 | + 3>&1 |
| 109 | +
|
| 110 | + exit_codes=(${PIPESTATUS[@]}) |
| 111 | +
|
| 112 | + echo "::endgroup::" |
| 113 | + |
| 114 | + set -e |
| 115 | +
|
| 116 | + if [ "${exit_codes[2]}" -ne 0 ] ; then |
| 117 | + # grep "failed" (found com.sonatype.nexus.staging.api.dto.StagingProfileRepositoryDTO) and mvn failed |
| 118 | + echo "Released ${scm_tag} successfully, but verify that the staging repository was successfully released" >> "${GITHUB_STEP_SUMMARY}"; |
| 119 | + # Treat this as a successful run |
| 120 | + exit 0; |
| 121 | + elif [ "${exit_codes[0]}" -eq 0 ] ; then |
| 122 | + # mvn succeeded and grep "succeeded" (did not find com.sonatype.nexus.staging.api.dto.StagingProfileRepositoryDTO) |
| 123 | + echo "Released ${scm_tag} successfully" >> "${GITHUB_STEP_SUMMARY}"; |
| 124 | + fi |
| 125 | +
|
| 126 | + exit "${exit_codes[0]}" |
0 commit comments