From d703a8abb280b629388b5f551c54a5f9142d7dea Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner <73236783+michelroegl-brunner@users.noreply.github.com> Date: Wed, 14 May 2025 11:02:41 +0200 Subject: [PATCH] Add App to do the merging (#4461) --- .github/workflows/auto-update-app-headers.yml | 21 ++++++++++----- .github/workflows/changelog-pr.yml | 25 +++++++++--------- .github/workflows/update-json-date.yml | 26 +++++++++++++------ 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/.github/workflows/auto-update-app-headers.yml b/.github/workflows/auto-update-app-headers.yml index 61b583c68..649a36ff0 100644 --- a/.github/workflows/auto-update-app-headers.yml +++ b/.github/workflows/auto-update-app-headers.yml @@ -5,8 +5,8 @@ on: branches: - main paths: - - 'ct/**.sh' - workflow_dispatch: + - "ct/**.sh" + workflow_dispatch: jobs: update-app-files: @@ -25,6 +25,13 @@ jobs: app-id: ${{ vars.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Generate a token for PR approval and merge + id: generate-token-merge + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ secrets.APP_ID_APPROVE_AND_MERGE }} + private-key: ${{ secrets.APP_KEY_APPROVE_AND_MERGE }} + # Step 1: Checkout repository - name: Checkout repository uses: actions/checkout@v2 @@ -80,7 +87,7 @@ jobs: --label "automated pr" env: GH_TOKEN: ${{ steps.generate-token.outputs.token }} - + - name: Approve pull request if: env.changed == 'true' env: @@ -90,13 +97,15 @@ jobs: if [ -n "$PR_NUMBER" ]; then gh pr review $PR_NUMBER --approve fi - + - name: Approve pull request and merge if: env.changed == 'true' env: - GH_TOKEN: ${{ secrets.PAT_AUTOMERGE }} + GH_TOKEN: ${{ steps.generate-token-merge.outputs.token }} run: | - PR_NUMBER=$(gh pr list --head "pr-update-app-files" --json number --jq '.[].number') + git config --global user.name "github-actions-automege[bot]" + git config --global user.email "github-actions-automege[bot]@users.noreply.github.com" + PR_NUMBER=$(gh pr list --head "${BRANCH_NAME}" --json number --jq '.[].number') if [ -n "$PR_NUMBER" ]; then gh pr review $PR_NUMBER --approve gh pr merge $PR_NUMBER --squash --admin diff --git a/.github/workflows/changelog-pr.yml b/.github/workflows/changelog-pr.yml index f441bce63..dd23df0ea 100644 --- a/.github/workflows/changelog-pr.yml +++ b/.github/workflows/changelog-pr.yml @@ -24,6 +24,13 @@ jobs: app-id: ${{ vars.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Generate a token for PR approval and merge + id: generate-token-merge + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ secrets.APP_ID_APPROVE_AND_MERGE }} + private-key: ${{ secrets.APP_KEY_APPROVE_AND_MERGE }} + - name: Checkout code uses: actions/checkout@v4 with: @@ -177,7 +184,7 @@ jobs: } return await main(); - + - name: Update CHANGELOG.md uses: actions/github-script@v7 with: @@ -202,7 +209,7 @@ jobs: if (hasMainNotes || hasSubNotes) { newReleaseNotes += `### ${title}\n\n`; } - + if (hasMainNotes) { newReleaseNotes += ` ${notes.join("\n")}\n\n`; } @@ -267,20 +274,12 @@ jobs: - name: Approve pull request and merge if: env.changed == 'true' env: - GH_TOKEN: ${{ secrets.PAT_AUTOMERGE }} + GH_TOKEN: ${{ steps.generate-token-merge.outputs.token }} run: | + git config --global user.name "github-actions-automege[bot]" + git config --global user.email "github-actions-automege[bot]@users.noreply.github.com" PR_NUMBER=$(gh pr list --head "${BRANCH_NAME}" --json number --jq '.[].number') if [ -n "$PR_NUMBER" ]; then gh pr review $PR_NUMBER --approve gh pr merge $PR_NUMBER --squash --admin fi - - - name: Re-approve pull request after update - if: env.changed == 'true' - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - PR_NUMBER=$(gh pr list --head "${BRANCH_NAME}" --json number --jq '.[].number') - if [ -n "$PR_NUMBER" ]; then - gh pr review $PR_NUMBER --approve - fi diff --git a/.github/workflows/update-json-date.yml b/.github/workflows/update-json-date.yml index 2004f1522..ba73b3ace 100644 --- a/.github/workflows/update-json-date.yml +++ b/.github/workflows/update-json-date.yml @@ -5,8 +5,8 @@ on: branches: - main paths: - - 'frontend/public/json/**.json' - workflow_dispatch: + - "frontend/public/json/**.json" + workflow_dispatch: jobs: update-app-files: @@ -25,10 +25,17 @@ jobs: app-id: ${{ vars.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Generate a token for PR approval and merge + id: generate-token-merge + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ secrets.APP_ID_APPROVE_AND_MERGE }} + private-key: ${{ secrets.APP_KEY_APPROVE_AND_MERGE }} + - name: Generate dynamic branch name id: timestamp run: echo "BRANCH_NAME=pr-update-json-$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV - + - name: Set up GH_TOKEN env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -38,7 +45,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 with: - fetch-depth: 2 # Ensure we have the last two commits + fetch-depth: 2 # Ensure we have the last two commits - name: Get Previous Commit id: prev_commit @@ -103,8 +110,8 @@ jobs: - name: Commit and create PR if changes exist if: env.changed == 'true' run: | - - + + git commit -m "Update date in json" git checkout -b ${{ env.BRANCH_NAME }} git push origin ${{ env.BRANCH_NAME }} @@ -126,12 +133,15 @@ jobs: if [ -n "$PR_NUMBER" ]; then gh pr review $PR_NUMBER --approve fi + - name: Approve pull request and merge if: env.changed == 'true' env: - GH_TOKEN: ${{ secrets.PAT_AUTOMERGE }} + GH_TOKEN: ${{ steps.generate-token-merge.outputs.token }} run: | - PR_NUMBER=$(gh pr list --head "${{ env.BRANCH_NAME }}" --json number --jq '.[].number') + git config --global user.name "github-actions-automege[bot]" + git config --global user.email "github-actions-automege[bot]@users.noreply.github.com" + PR_NUMBER=$(gh pr list --head "${BRANCH_NAME}" --json number --jq '.[].number') if [ -n "$PR_NUMBER" ]; then gh pr review $PR_NUMBER --approve gh pr merge $PR_NUMBER --squash --admin