|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + GPG_PRIVATE_KEY: |
| 7 | + description: 'The private key to sign the artifacts' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + OSSRH_USERNAME: |
| 11 | + description: 'The username to deploy to Maven Central' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + OSSRH_TOKEN: |
| 15 | + description: 'The token to deploy to Maven Central' |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + |
| 19 | +jobs: |
| 20 | + build_and_deploy: |
| 21 | + name: Build and Deploy to Maven Central |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + - uses: ./.github/actions/setup-jdk |
| 26 | + - uses: ./.github/actions/setup-maven-cache |
| 27 | + - uses: ./.github/actions/run-tests |
| 28 | + |
| 29 | + - name: Prepare for release |
| 30 | + run: ./mvnw versions:set -DremoveSnapshot=true -DgenerateBackupPoms=false |
| 31 | + |
| 32 | + - name: Get the version |
| 33 | + id: get_version |
| 34 | + run: echo ::set-output name=version::$(./mvnw -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec) |
| 35 | + |
| 36 | + - name: Import GPG key |
| 37 | + run: echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --import |
| 38 | + env: |
| 39 | + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} |
| 40 | + |
| 41 | + - name: Deploy |
| 42 | + run: ./mvnw -P release --batch-mode -DskipTests deploy |
| 43 | + env: |
| 44 | + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} |
| 45 | + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} |
| 46 | + |
| 47 | + - name: Upload JARs as artifact |
| 48 | + uses: actions/upload-artifact@v2 |
| 49 | + with: |
| 50 | + name: jars |
| 51 | + path: ./target/*.jar |
| 52 | + |
| 53 | + commit_and_tag: |
| 54 | + name: Commit and Tag |
| 55 | + needs: build_and_sign |
| 56 | + runs-on: ubuntu-latest |
| 57 | + steps: |
| 58 | + - uses: ./.github/actions/setup-jdk |
| 59 | + |
| 60 | + - name: Set version |
| 61 | + run: ./mvnw versions:set -DnewVersion=${{ steps.get_version.outputs.version }} -DgenerateBackupPoms=false |
| 62 | + |
| 63 | + - name: Update README.md |
| 64 | + run: sed -i "s|<version>.*</version>|<version>${{ steps.get_version.outputs.version }}</version>|g" README.md |
| 65 | + |
| 66 | + - name: Commit release POM and Tag |
| 67 | + run: | |
| 68 | + git config --local user.email "[email protected]" |
| 69 | + git config --local user.name "GitHub Action" |
| 70 | + git commit -m "Release ${{ steps.get_version.outputs.version }}" -a |
| 71 | + git tag ${{ steps.get_version.outputs.version }} |
| 72 | +
|
| 73 | + - name: Set next development version |
| 74 | + run: ./mvnw versions:set -DnextSnapshot=true -DgenerateBackupPoms=false |
| 75 | + |
| 76 | + - name: Commit next snapshot |
| 77 | + run: | |
| 78 | + git commit -m "Next development version" -a |
| 79 | +
|
| 80 | + - name: Push |
| 81 | + uses: ad-m/github-push-action@master |
| 82 | + with: |
| 83 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 84 | + branch: ${{ github.ref }} |
| 85 | + |
| 86 | + create_github_release_and_attach_artifacts: |
| 87 | + name: Create GitHub Release and attach artifacts |
| 88 | + needs: commit_and_tag |
| 89 | + runs-on: ubuntu-latest |
| 90 | + steps: |
| 91 | + - name: Download build artifacts |
| 92 | + uses: actions/download-artifact@v2 |
| 93 | + with: |
| 94 | + name: build-artifacts |
| 95 | + path: ./target |
| 96 | + |
| 97 | + - name: Build Changelog |
| 98 | + id: build_changelog |
| 99 | + uses: mikepenz/release-changelog-builder-action@v4 |
| 100 | + with: |
| 101 | + configuration: ".github/workflows/changelog-configuration.json" |
| 102 | + env: |
| 103 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + |
| 105 | + - name: Create GitHub Release |
| 106 | + id: create_release |
| 107 | + uses: actions/create-release@v1 |
| 108 | + env: |
| 109 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 110 | + with: |
| 111 | + tag_name: ${{ steps.get_version.output.version }} |
| 112 | + release_name: Release ${{ steps.get_version.output.version }} |
| 113 | + draft: false |
| 114 | + prerelease: false |
| 115 | + body: ${{steps.build_changelog.outputs.changelog}} |
| 116 | + |
| 117 | + - name: Upload all jars to Release |
| 118 | + run: | |
| 119 | + for file in ./target/*.jar; do |
| 120 | + echo "Uploading $file" |
| 121 | + curl \ |
| 122 | + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 123 | + -H "Content-Type: $(file -b --mime-type $file)" \ |
| 124 | + --data-binary @"$file" \ |
| 125 | + "${{ steps.create_release.outputs.upload_url }}?name=$(basename $file)" |
| 126 | + done |
| 127 | + shell: bash |
0 commit comments