|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - release |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + # Do not run workflow if the triggering commit created the 'release' branch |
| 12 | + if: ${{github.event.created}} == false |
| 13 | + permissions: |
| 14 | + contents: write |
| 15 | + id-token: write |
| 16 | + packages: write |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Create DaplaBot app token |
| 20 | + uses: actions/create-github-app-token@v1 |
| 21 | + id: app-token |
| 22 | + with: |
| 23 | + app-id: ${{ secrets.DAPLA_BOT_APP_ID }} |
| 24 | + private-key: ${{ secrets.DAPLA_BOT_PRIVATE_KEY }} |
| 25 | + |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + token: ${{ steps.app-token.outputs.token }} |
| 29 | + ref: refs/heads/master |
| 30 | + |
| 31 | + - name: Set up JDK |
| 32 | + uses: actions/setup-java@v4 |
| 33 | + with: |
| 34 | + java-version: 17 |
| 35 | + distribution: temurin |
| 36 | + cache: maven |
| 37 | + overwrite-settings: false |
| 38 | + |
| 39 | + - name: Get bot variables |
| 40 | + id: get-bot-vars |
| 41 | + run: | |
| 42 | + bot_name="dapla-bot" |
| 43 | + bot_id=$(curl -s https://api.github.com/users/${bot_name}%5Bbot%5D | jq '.id') |
| 44 | + bot_email="${dapla_bot_id}+${bot_name}[bot]@users.noreply.github.com" |
| 45 | +
|
| 46 | + echo "bot_name=${bot_name}[bot]" >> $GITHUB_OUTPUT |
| 47 | + echo "bot_email=${bot_email}" >> $GITHUB_OUTPUT |
| 48 | +
|
| 49 | + - name: Configure Git user |
| 50 | + run: | |
| 51 | + git config user.email ${{steps.get-bot-vars.outputs.bot_email}} |
| 52 | + git config user.name ${{steps.get-bot-vars.outputs.bot_name}} |
| 53 | +
|
| 54 | + - name: Setup Maven authentication to GitHub packages |
| 55 | + uses: s4u/maven-settings-action@v3.0.0 |
| 56 | + with: |
| 57 | + override: true |
| 58 | + githubServer: false |
| 59 | + servers: >- |
| 60 | + [{"id": "github","username": "${{steps.get-bot-vars.outputs.bot_email}}","password": "${{steps.app-token.outputs.token}}", |
| 61 | + "configuration": {"httpHeaders": {"property": {"name": "Authorization","value": "Bearer ${{ secrets.GITHUB_TOKEN }}"}}}}] |
| 62 | +
|
| 63 | + - name: Maven release and deploy to GitHub packages |
| 64 | + id: release-artifact |
| 65 | + run: | |
| 66 | + # Get the release version from the pom.xml before the next snapshot increment |
| 67 | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed "s/-SNAPSHOT//") |
| 68 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 69 | + # Perform the release/deploy and increment the version to the next snapshot |
| 70 | + mvn --batch-mode release:prepare -P github -Darguments="-Dmaven.test.skip=true -Dmaven.deploy.skip=true" |
| 71 | + mvn --batch-mode release:perform |
| 72 | + TAG=$(git describe --abbrev=0 --tags) |
| 73 | + echo "tag=${TAG}" >> $GITHUB_OUTPUT |
| 74 | +
|
| 75 | + - name: Create GitHub release draft |
| 76 | + uses: release-drafter/release-drafter@v6 |
| 77 | + id: create-github-release |
| 78 | + env: |
| 79 | + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} |
| 80 | + with: |
| 81 | + tag: ${{ steps.release-artifact.outputs.tag }} |
| 82 | + |
| 83 | + - name: Upload assets to GitHub release draft |
| 84 | + env: |
| 85 | + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} |
| 86 | + run: | |
| 87 | + ARTIFACT_ID=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout) |
| 88 | + # Get all files matching the artifact id and version (source, javadoc, etc.) |
| 89 | + ARTIFACT_GLOB=(./target/$ARTIFACT_ID-${{ steps.release-artifact.outputs.version }}*.jar) |
| 90 | + for file in "${ARTIFACT_GLOB[@]}"; do |
| 91 | + echo "Uploading $file" |
| 92 | + gh release upload ${{ steps.create-github-release.outputs.tag_name }} $file |
| 93 | + done |
| 94 | +
|
| 95 | + - name: Publish GitHub release |
| 96 | + uses: eregon/publish-release@v1 |
| 97 | + env: |
| 98 | + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} |
| 99 | + with: |
| 100 | + release_id: ${{ steps.create-github-release.outputs.id }} |
0 commit comments