|
| 1 | +name: Maven Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + dry_run: |
| 7 | + description: 'Perform a dry run of the Maven release' |
| 8 | + required: true |
| 9 | + default: false |
| 10 | + type: boolean |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + permissions: |
| 17 | + contents: write |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up JDK 8 |
| 24 | + uses: actions/setup-java@v4 |
| 25 | + with: |
| 26 | + java-version: '8' |
| 27 | + distribution: 'temurin' |
| 28 | + server-id: ossrh |
| 29 | + server-username: MAVEN_USERNAME |
| 30 | + server-password: MAVEN_PASSWORD |
| 31 | + # Export the gpg private key using the following command and add the contents of that file to the GitHub secret |
| 32 | + # gpg --armor --export-secret-keys <key_id> > gpg_key.asc |
| 33 | + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} |
| 34 | + gpg-passphrase: MAVEN_GPG_PASSPHRASE |
| 35 | + |
| 36 | + - name: Set up git |
| 37 | + run: | |
| 38 | + git config --global user.email "info@cyclonedx.org" |
| 39 | + git config --global user.name "CycloneDX Automation" |
| 40 | + git config --global credential.helper 'store --file ~/.git-credentials' |
| 41 | + echo "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com" > ~/.git-credentials |
| 42 | +
|
| 43 | + - name: Set Maven options |
| 44 | + id: maven_options |
| 45 | + run: | |
| 46 | + # Set the Maven options based on the 'dry_run' input |
| 47 | + if ${{ github.event.inputs.dry_run }}; then |
| 48 | + echo "options=release:prepare -DdryRun=true -Prelease" >> $GITHUB_ENV |
| 49 | + else |
| 50 | + echo "options=release:clean release:prepare release:perform -Prelease" >> $GITHUB_ENV |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Run Maven command |
| 54 | + # This requires the connection and developerConnection elements in the scm section of the pom |
| 55 | + # to be set to "scm:git:https:...." thus preventing the release plugin from using SSH. |
| 56 | + run: | |
| 57 | + mvn -B ${{ env.options }} |
| 58 | + env: |
| 59 | + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} |
| 60 | + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} |
| 61 | + MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
| 62 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + continue-on-error: ${{ github.event.inputs.dry_run == false }} |
| 64 | + |
| 65 | + - name: Rollback if release fails |
| 66 | + if: failure() && github.event.inputs.dry_run == false |
| 67 | + run: | |
| 68 | + echo "Release failed. Rolling back..." |
| 69 | + mvn -B release:rollback -Prelease |
| 70 | + env: |
| 71 | + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} |
| 72 | + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} |
| 73 | + MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments