|
| 1 | +name: Merge release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [released] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + branch: |
| 9 | + description: Branch to merge into |
| 10 | + required: false |
| 11 | + type: string |
| 12 | + default: main |
| 13 | + tag: |
| 14 | + description: Tag to merge |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + |
| 18 | +jobs: |
| 19 | + merge-release: |
| 20 | + timeout-minutes: 5 |
| 21 | + permissions: |
| 22 | + contents: write |
| 23 | + strategy: |
| 24 | + fail-fast: true |
| 25 | + matrix: |
| 26 | + os: [ubuntu-latest] |
| 27 | + runs-on: ${{ matrix.os }} |
| 28 | + |
| 29 | + name: Merge tag |
| 30 | + |
| 31 | + steps: |
| 32 | + - uses: actions/create-github-app-token@v1 |
| 33 | + id: app-token |
| 34 | + with: |
| 35 | + app-id: ${{ vars.GHA_APP_ID }} |
| 36 | + private-key: ${{ secrets.GHA_PRIVATE_KEY }} |
| 37 | + |
| 38 | + - name: Determine branch |
| 39 | + run: | |
| 40 | + echo 'BRANCH='${{ inputs.branch || 'main' }} >> $GITHUB_ENV |
| 41 | +
|
| 42 | + - name: Checkout "${{ env.BRANCH }}" branch locally |
| 43 | + uses: actions/checkout@v4 |
| 44 | + with: |
| 45 | + ref: ${{ env.BRANCH }} |
| 46 | + fetch-tags: true |
| 47 | + fetch-depth: 0 |
| 48 | + token: ${{ steps.app-token.outputs.token }} |
| 49 | + |
| 50 | + - name: Get GitHub App User ID |
| 51 | + if: ${{ github.event_name == 'release' }} |
| 52 | + id: get-user-id |
| 53 | + run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" |
| 54 | + env: |
| 55 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 56 | + |
| 57 | + - name: Update values for git user config (release) |
| 58 | + if: ${{ github.event_name == 'release' }} |
| 59 | + run: | |
| 60 | + echo "GIT_USER_NAME=${{ steps.app-token.outputs.app-slug }}[bot]" >> $GITHUB_ENV |
| 61 | + echo "GIT_USER_EMAIL=${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com" >> $GITHUB_ENV |
| 62 | +
|
| 63 | + - name: Update values for git user config (workflow_dispatch) |
| 64 | + if: ${{ github.event_name == 'workflow_dispatch' }} |
| 65 | + run: | |
| 66 | + # fetch user info |
| 67 | + user=$(gh api \ |
| 68 | + -H "Accept: application/vnd.github+json" \ |
| 69 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 70 | + /user/$ACCOUNT_ID ) |
| 71 | +
|
| 72 | + # get user's name and email |
| 73 | + # email will be set to null if it is private |
| 74 | + name=$(echo $user | jq '.name') |
| 75 | + email=$(echo $user | jq '.email') |
| 76 | +
|
| 77 | + # store in environment variables to use for setting up git user |
| 78 | + echo "GIT_USER_NAME=$name" >> $GITHUB_ENV |
| 79 | + echo "GIT_USER_EMAIL=$email" >> $GITHUB_ENV |
| 80 | + env: |
| 81 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + ACCOUNT_ID: ${{ github.actor_id }} |
| 83 | + |
| 84 | + - name: Merge tag to "${{ env.BRANCH }}" branch |
| 85 | + run: | |
| 86 | + git config --local user.email "$GIT_USER_EMAIL" |
| 87 | + git config --local user.name "$GIT_USER_NAME" |
| 88 | + git merge ${{ inputs.tag || github.event.release.tag_name }} |
| 89 | + git push |
0 commit comments