From 5300e23002aa04fff0d2f1f506b3c22019874a4e Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Fri, 20 Jun 2025 15:47:14 -0400 Subject: [PATCH 01/19] add auto merge --- .github/workflows/auto_merge.yaml | 28 ++++++++++++++++++++++++++++ .github/workflows/token_test.yaml | 19 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 .github/workflows/auto_merge.yaml create mode 100644 .github/workflows/token_test.yaml diff --git a/.github/workflows/auto_merge.yaml b/.github/workflows/auto_merge.yaml new file mode 100644 index 00000000..64cac1a0 --- /dev/null +++ b/.github/workflows/auto_merge.yaml @@ -0,0 +1,28 @@ +name: Auto Approve and Merge + +on: + pull_request: + types: [opened, synchronize] + +jobs: + auto-approve-merge: + runs-on: ubuntu-latest + # Only run for PRs created by github-actions bot + # Intended to auto-approve and merge PRs created by speakeasy sdk generation + if: github.actor == 'github-actions[bot]' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Auto Approve PR + uses: hmarr/auto-approve-action@v3 + with: + github-token: ${{ secrets.AUTO_MERGE_TOKEN }} + + - name: Enable Auto-merge + run: | + gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{ github.event.pull_request.html_url }} + GITHUB_TOKEN: ${{ secrets.AUTO_MERGE_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/token_test.yaml b/.github/workflows/token_test.yaml new file mode 100644 index 00000000..df7dc7a8 --- /dev/null +++ b/.github/workflows/token_test.yaml @@ -0,0 +1,19 @@ +name: Test Secret Access +on: + workflow_dispatch: + +jobs: + test-secret: + runs-on: ubuntu-latest + steps: + - name: Check if secret exists + run: | + if [ -z "${{ secrets.AUTO_MERGE_TOKEN }}" ]; then + echo "❌ AUTO_MERGE_TOKEN is not accessible" + exit 1 + else + echo "✅ AUTO_MERGE_TOKEN is accessible" + # Test basic API access + curl -s -H "Authorization: token ${{ secrets.AUTO_MERGE_TOKEN }}" \ + https://api.github.com/user | jq -r .login || echo "Token validation failed" + fi \ No newline at end of file From e88d911eb37ead0203f29c75c050d85f529630b6 Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Fri, 20 Jun 2025 16:00:02 -0400 Subject: [PATCH 02/19] update token test --- .github/workflows/token_test.yaml | 39 +++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/.github/workflows/token_test.yaml b/.github/workflows/token_test.yaml index df7dc7a8..3a3e4a21 100644 --- a/.github/workflows/token_test.yaml +++ b/.github/workflows/token_test.yaml @@ -13,7 +13,38 @@ jobs: exit 1 else echo "✅ AUTO_MERGE_TOKEN is accessible" - # Test basic API access - curl -s -H "Authorization: token ${{ secrets.AUTO_MERGE_TOKEN }}" \ - https://api.github.com/user | jq -r .login || echo "Token validation failed" - fi \ No newline at end of file + fi + + - name: Test with GitHub CLI + env: + GITHUB_TOKEN: ${{ secrets.AUTO_MERGE_TOKEN }} + run: | + echo "🔐 Testing authentication..." + + # Get authenticated user + if USER=$(gh api user --jq .login 2>&1); then + echo "✅ Authenticated as: $USER" + else + echo "❌ Authentication failed: $USER" + exit 1 + fi + + # Test repository access + echo "📋 Testing repository access..." + if REPO=$(gh api repos/${{ github.repository }} --jq .full_name 2>&1); then + echo "✅ Can access repository: $REPO" + else + echo "❌ Cannot access repository: $REPO" + exit 1 + fi + + # Test PR operations + echo "🔍 Testing PR access..." + if PRS=$(gh pr list --repo ${{ github.repository }} --limit 1 2>&1); then + echo "✅ Can access pull requests" + else + echo "❌ Cannot access PRs: $PRS" + exit 1 + fi + + echo "🎉 All tests passed!" \ No newline at end of file From d9fe2a895d3e8458fc778ba2f27ea6509e683ead Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Fri, 20 Jun 2025 16:09:52 -0400 Subject: [PATCH 03/19] run on branch push --- .github/workflows/token_test.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/token_test.yaml b/.github/workflows/token_test.yaml index 3a3e4a21..1742918c 100644 --- a/.github/workflows/token_test.yaml +++ b/.github/workflows/token_test.yaml @@ -1,4 +1,7 @@ name: Test Secret Access +on: + push: + branches: [auto-approve-merge] on: workflow_dispatch: From 86ade3f423532ab93f8aa80732b4e2e95f3dc46b Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Fri, 20 Jun 2025 16:14:08 -0400 Subject: [PATCH 04/19] fix syntax, add input --- .github/workflows/token_test.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/token_test.yaml b/.github/workflows/token_test.yaml index 1742918c..cab2698c 100644 --- a/.github/workflows/token_test.yaml +++ b/.github/workflows/token_test.yaml @@ -2,8 +2,12 @@ name: Test Secret Access on: push: branches: [auto-approve-merge] -on: workflow_dispatch: + inputs: + environment: + description: Environment to test secret access + required: false + default: staging jobs: test-secret: From deb51510fe2f1437dcbbdc7e53c2c4e8cf025b2e Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Fri, 20 Jun 2025 16:23:55 -0400 Subject: [PATCH 05/19] test --- .github/workflows/token_test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/token_test.yaml b/.github/workflows/token_test.yaml index cab2698c..7e177401 100644 --- a/.github/workflows/token_test.yaml +++ b/.github/workflows/token_test.yaml @@ -4,10 +4,10 @@ on: branches: [auto-approve-merge] workflow_dispatch: inputs: - environment: - description: Environment to test secret access - required: false - default: staging + force: + description: Force test of secret access + type: boolean + default: false jobs: test-secret: From cfe65d32c54163cd5f6bec55091229729f41174e Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 23 Jun 2025 09:42:44 -0400 Subject: [PATCH 06/19] remove token test --- .github/workflows/token_test.yaml | 57 ------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 .github/workflows/token_test.yaml diff --git a/.github/workflows/token_test.yaml b/.github/workflows/token_test.yaml deleted file mode 100644 index 7e177401..00000000 --- a/.github/workflows/token_test.yaml +++ /dev/null @@ -1,57 +0,0 @@ -name: Test Secret Access -on: - push: - branches: [auto-approve-merge] - workflow_dispatch: - inputs: - force: - description: Force test of secret access - type: boolean - default: false - -jobs: - test-secret: - runs-on: ubuntu-latest - steps: - - name: Check if secret exists - run: | - if [ -z "${{ secrets.AUTO_MERGE_TOKEN }}" ]; then - echo "❌ AUTO_MERGE_TOKEN is not accessible" - exit 1 - else - echo "✅ AUTO_MERGE_TOKEN is accessible" - fi - - - name: Test with GitHub CLI - env: - GITHUB_TOKEN: ${{ secrets.AUTO_MERGE_TOKEN }} - run: | - echo "🔐 Testing authentication..." - - # Get authenticated user - if USER=$(gh api user --jq .login 2>&1); then - echo "✅ Authenticated as: $USER" - else - echo "❌ Authentication failed: $USER" - exit 1 - fi - - # Test repository access - echo "📋 Testing repository access..." - if REPO=$(gh api repos/${{ github.repository }} --jq .full_name 2>&1); then - echo "✅ Can access repository: $REPO" - else - echo "❌ Cannot access repository: $REPO" - exit 1 - fi - - # Test PR operations - echo "🔍 Testing PR access..." - if PRS=$(gh pr list --repo ${{ github.repository }} --limit 1 2>&1); then - echo "✅ Can access pull requests" - else - echo "❌ Cannot access PRs: $PRS" - exit 1 - fi - - echo "🎉 All tests passed!" \ No newline at end of file From a02405213cd7290b77c230423fb2e08a19a2e828 Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 23 Jun 2025 09:53:51 -0400 Subject: [PATCH 07/19] add auto merge test --- .github/workflows/test_auto_merge.yaml | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/test_auto_merge.yaml diff --git a/.github/workflows/test_auto_merge.yaml b/.github/workflows/test_auto_merge.yaml new file mode 100644 index 00000000..2a41ea8b --- /dev/null +++ b/.github/workflows/test_auto_merge.yaml @@ -0,0 +1,33 @@ +name: Create Test PR for Auto-Merge +on: + workflow_dispatch: + inputs: + branch_name: + description: 'Branch name for test PR' + default: 'test-auto-merge' + required: false + +jobs: + create-test-pr: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Create test file + run: | + echo "Test auto-merge at $(date)" > test-auto-merge.txt + echo "This file can be deleted after testing" >> test-auto-merge.txt + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "test: auto-merge functionality" + title: "Test: Auto-merge workflow" + body: | + This is a test PR to verify auto-merge functionality. + - Created by: github-actions[bot] + - Should trigger: auto-approve and merge workflow + - Can be closed if auto-merge fails + branch: ${{ inputs.branch_name }}-${{ github.run_number }} + delete-branch: true \ No newline at end of file From 5ddba49f056d764e24bc80fc7e58d426ff4ae3e9 Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 23 Jun 2025 10:00:38 -0400 Subject: [PATCH 08/19] run on push --- .github/workflows/test_auto_merge.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test_auto_merge.yaml b/.github/workflows/test_auto_merge.yaml index 2a41ea8b..516f3d10 100644 --- a/.github/workflows/test_auto_merge.yaml +++ b/.github/workflows/test_auto_merge.yaml @@ -6,6 +6,8 @@ on: description: 'Branch name for test PR' default: 'test-auto-merge' required: false + push: + branches: [auto-approve-merge] jobs: create-test-pr: From ccd6020637ba00e5a1da94f80c614645f76999d9 Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 23 Jun 2025 10:06:33 -0400 Subject: [PATCH 09/19] fix branch naming --- .github/workflows/test_auto_merge.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_auto_merge.yaml b/.github/workflows/test_auto_merge.yaml index 516f3d10..cfb52d34 100644 --- a/.github/workflows/test_auto_merge.yaml +++ b/.github/workflows/test_auto_merge.yaml @@ -31,5 +31,5 @@ jobs: - Created by: github-actions[bot] - Should trigger: auto-approve and merge workflow - Can be closed if auto-merge fails - branch: ${{ inputs.branch_name }}-${{ github.run_number }} + branch: automerge-test-${{ github.run_number }} delete-branch: true \ No newline at end of file From 9e964552cf1a6076fbba32a8a4e3906ca78bc75f Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 23 Jun 2025 10:25:44 -0400 Subject: [PATCH 10/19] update merge test --- .github/workflows/test_auto_merge.yaml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_auto_merge.yaml b/.github/workflows/test_auto_merge.yaml index cfb52d34..8d2ae392 100644 --- a/.github/workflows/test_auto_merge.yaml +++ b/.github/workflows/test_auto_merge.yaml @@ -6,14 +6,15 @@ on: description: 'Branch name for test PR' default: 'test-auto-merge' required: false - push: - branches: [auto-approve-merge] + type: string jobs: create-test-pr: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + ref: auto-approve-merge - name: Create test file run: | @@ -31,5 +32,7 @@ jobs: - Created by: github-actions[bot] - Should trigger: auto-approve and merge workflow - Can be closed if auto-merge fails - branch: automerge-test-${{ github.run_number }} - delete-branch: true \ No newline at end of file + branch: ${{ inputs.branch_name || 'test-auto-merge' }}-${{ github.run_number }} + base: auto-approve-merge + delete-branch: true + draft: false \ No newline at end of file From c0c9fb55501e4376994b37382dd27f790d88b122 Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 23 Jun 2025 10:26:58 -0400 Subject: [PATCH 11/19] run on push --- .github/workflows/test_auto_merge.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test_auto_merge.yaml b/.github/workflows/test_auto_merge.yaml index 8d2ae392..3dca8d4c 100644 --- a/.github/workflows/test_auto_merge.yaml +++ b/.github/workflows/test_auto_merge.yaml @@ -7,6 +7,8 @@ on: default: 'test-auto-merge' required: false type: string + push: + branches: [auto-approve-merge] jobs: create-test-pr: From da33226569a48c380630dcaf78ca4a569909072f Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 23 Jun 2025 10:55:45 -0400 Subject: [PATCH 12/19] debug actor, update condition --- .github/workflows/auto_merge.yaml | 5 ++++- .github/workflows/debug_actor.yaml | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/debug_actor.yaml diff --git a/.github/workflows/auto_merge.yaml b/.github/workflows/auto_merge.yaml index 64cac1a0..1f072d8a 100644 --- a/.github/workflows/auto_merge.yaml +++ b/.github/workflows/auto_merge.yaml @@ -9,7 +9,10 @@ jobs: runs-on: ubuntu-latest # Only run for PRs created by github-actions bot # Intended to auto-approve and merge PRs created by speakeasy sdk generation - if: github.actor == 'github-actions[bot]' + if: | + github.actor == 'github-actions[bot]' || + github.event.pull_request.user.login == 'github-actions[bot]' || + github.event.pull_request.user.type == 'Bot' steps: - name: Checkout diff --git a/.github/workflows/debug_actor.yaml b/.github/workflows/debug_actor.yaml new file mode 100644 index 00000000..ec17c8b7 --- /dev/null +++ b/.github/workflows/debug_actor.yaml @@ -0,0 +1,17 @@ +name: Debug PR Actor +on: + pull_request: + types: [opened, synchronize] + +jobs: + debug: + runs-on: ubuntu-latest + steps: + - name: Show Actor Info + run: | + echo "github.actor: ${{ github.actor }}" + echo "github.triggering_actor: ${{ github.triggering_actor }}" + echo "PR author: ${{ github.event.pull_request.user.login }}" + echo "PR author type: ${{ github.event.pull_request.user.type }}" + echo "Sender: ${{ github.event.sender.login }}" + echo "Sender type: ${{ github.event.sender.type }}" \ No newline at end of file From b4b6307926b41e2e55e620f3c7ad14761b45260f Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 14 Jul 2025 17:14:16 -0400 Subject: [PATCH 13/19] remove third party dependencies --- .github/workflows/auto_merge.yaml | 59 +++++++++++++++++++------ .github/workflows/test_auto_merge.yaml | 61 +++++++++++++++----------- 2 files changed, 81 insertions(+), 39 deletions(-) diff --git a/.github/workflows/auto_merge.yaml b/.github/workflows/auto_merge.yaml index 1f072d8a..478e4ffa 100644 --- a/.github/workflows/auto_merge.yaml +++ b/.github/workflows/auto_merge.yaml @@ -7,25 +7,56 @@ on: jobs: auto-approve-merge: runs-on: ubuntu-latest - # Only run for PRs created by github-actions bot - # Intended to auto-approve and merge PRs created by speakeasy sdk generation + # Check commit author or PR title since actor will be the person who triggered if: | - github.actor == 'github-actions[bot]' || - github.event.pull_request.user.login == 'github-actions[bot]' || - github.event.pull_request.user.type == 'Bot' + contains(github.event.pull_request.title, 'Test: Auto-merge workflow') || + github.event.pull_request.head.repo.full_name == github.repository steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Auto Approve PR - uses: hmarr/auto-approve-action@v3 - with: - github-token: ${{ secrets.AUTO_MERGE_TOKEN }} + - name: Check PR Details + id: check-pr + run: | + echo "Checking if this PR should be auto-merged..." + + # Get the commit author of the head commit + COMMIT_AUTHOR=$(gh api \ + repos/${{ github.repository }}/commits/${{ github.event.pull_request.head.sha }} \ + --jq '.commit.author.name') + + echo "Commit author: $COMMIT_AUTHOR" + echo "PR title: ${{ github.event.pull_request.title }}" + + # Check if this is a bot commit + if [[ "$COMMIT_AUTHOR" == "github-actions[bot]" ]] || \ + [[ "${{ github.event.pull_request.title }}" == "Test: Auto-merge workflow" ]]; then + echo "should_proceed=true" >> $GITHUB_OUTPUT + else + echo "should_proceed=false" >> $GITHUB_OUTPUT + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Approve PR + if: steps.check-pr.outputs.should_proceed == 'true' + run: | + # Create approval review + gh pr review ${{ github.event.pull_request.number }} \ + --approve \ + --body "Auto-approved by workflow" + env: + GITHUB_TOKEN: ${{ secrets.AUTO_MERGE_TOKEN }} - name: Enable Auto-merge + if: steps.check-pr.outputs.should_proceed == 'true' run: | - gh pr merge --auto --merge "$PR_URL" + # Enable auto-merge + gh pr merge ${{ github.event.pull_request.number }} \ + --auto \ + --merge \ + --delete-branch + + # Check status + echo "Auto-merge status:" + gh pr view ${{ github.event.pull_request.number }} --json autoMergeRequest env: - PR_URL: ${{ github.event.pull_request.html_url }} GITHUB_TOKEN: ${{ secrets.AUTO_MERGE_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test_auto_merge.yaml b/.github/workflows/test_auto_merge.yaml index 3dca8d4c..9694fc4c 100644 --- a/.github/workflows/test_auto_merge.yaml +++ b/.github/workflows/test_auto_merge.yaml @@ -1,40 +1,51 @@ name: Create Test PR for Auto-Merge on: workflow_dispatch: - inputs: - branch_name: - description: 'Branch name for test PR' - default: 'test-auto-merge' - required: false - type: string - push: - branches: [auto-approve-merge] jobs: create-test-pr: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 with: + token: ${{ secrets.GITHUB_TOKEN }} ref: auto-approve-merge - - name: Create test file + - name: Create test branch and file run: | + # Create a unique branch name + BRANCH_NAME="test-auto-merge-${{ github.run_number }}" + echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV + + # Create and switch to new branch + git checkout -b $BRANCH_NAME + + # Create test file echo "Test auto-merge at $(date)" > test-auto-merge.txt echo "This file can be deleted after testing" >> test-auto-merge.txt - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 - with: - token: ${{ secrets.GITHUB_TOKEN }} - commit-message: "test: auto-merge functionality" - title: "Test: Auto-merge workflow" - body: | - This is a test PR to verify auto-merge functionality. - - Created by: github-actions[bot] - - Should trigger: auto-approve and merge workflow - - Can be closed if auto-merge fails - branch: ${{ inputs.branch_name || 'test-auto-merge' }}-${{ github.run_number }} - base: auto-approve-merge - delete-branch: true - draft: false \ No newline at end of file + # Configure git (as github-actions bot) + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + # Commit and push + git add test-auto-merge.txt + git commit -m "test: auto-merge functionality" + git push origin $BRANCH_NAME + + - name: Create PR using GitHub API + run: | + # Create PR using gh CLI + PR_URL=$(gh pr create \ + --base auto-approve-merge \ + --head $BRANCH_NAME \ + --title "Test: Auto-merge workflow" \ + --body "This is a test PR to verify auto-merge functionality. + - Created by: github-actions[bot] + - Should trigger: auto-approve and merge workflow + - Can be closed if auto-merge fails") + + echo "Created PR: $PR_URL" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 594fde2d698a2d02051a35c6c4a5a8652ddbed4c Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 14 Jul 2025 17:17:21 -0400 Subject: [PATCH 14/19] run test on push --- .github/workflows/test_auto_merge.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test_auto_merge.yaml b/.github/workflows/test_auto_merge.yaml index 9694fc4c..8fed9ef8 100644 --- a/.github/workflows/test_auto_merge.yaml +++ b/.github/workflows/test_auto_merge.yaml @@ -1,6 +1,8 @@ name: Create Test PR for Auto-Merge on: workflow_dispatch: + push: + branches: [auto-approve-merge] jobs: create-test-pr: From affea291f24dc36fc4e2a57c361cceabd19de06a Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 14 Jul 2025 17:29:46 -0400 Subject: [PATCH 15/19] update test action --- .github/workflows/test_auto_merge.yaml | 37 +++++++++++++++++++++----- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test_auto_merge.yaml b/.github/workflows/test_auto_merge.yaml index 8fed9ef8..af9fd24a 100644 --- a/.github/workflows/test_auto_merge.yaml +++ b/.github/workflows/test_auto_merge.yaml @@ -8,10 +8,19 @@ jobs: create-test-pr: runs-on: ubuntu-latest steps: + - name: Generate GitHub App Token + id: generate_token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ vars.APP_ID }} + private-key: ${{ secrets.APP_PRIVATE_KEY }} + continue-on-error: true + - name: Checkout uses: actions/checkout@v4 with: - token: ${{ secrets.GITHUB_TOKEN }} + # Use app token if available, otherwise fallback to GITHUB_TOKEN + token: ${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }} ref: auto-approve-merge - name: Create test branch and file @@ -27,18 +36,21 @@ jobs: echo "Test auto-merge at $(date)" > test-auto-merge.txt echo "This file can be deleted after testing" >> test-auto-merge.txt - # Configure git (as github-actions bot) + # Configure git explicitly as github-actions bot git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - # Commit and push + # Commit with explicit author git add test-auto-merge.txt - git commit -m "test: auto-merge functionality" + git commit -m "test: auto-merge functionality" \ + --author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" + + # Push with the token that creates the PR git push origin $BRANCH_NAME - name: Create PR using GitHub API run: | - # Create PR using gh CLI + # The PR will be created by whatever token is used here PR_URL=$(gh pr create \ --base auto-approve-merge \ --head $BRANCH_NAME \ @@ -49,5 +61,16 @@ jobs: - Can be closed if auto-merge fails") echo "Created PR: $PR_URL" + echo "PR_URL=$PR_URL" >> $GITHUB_ENV + + - name: Verify PR details + run: | + # Extract PR number from URL + PR_NUMBER=$(echo $PR_URL | grep -oE '[0-9]+$') + + # Check the actual commit author + echo "Checking commit author on the PR..." + gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/commits \ + --jq '.[0].commit.author' env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }} \ No newline at end of file From 2e30c9755aa30e4edd418336ae34dd7f1b5adba6 Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 14 Jul 2025 17:43:54 -0400 Subject: [PATCH 16/19] use GH token for cli action --- .github/workflows/test_auto_merge.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_auto_merge.yaml b/.github/workflows/test_auto_merge.yaml index af9fd24a..000985f3 100644 --- a/.github/workflows/test_auto_merge.yaml +++ b/.github/workflows/test_auto_merge.yaml @@ -62,7 +62,9 @@ jobs: echo "Created PR: $PR_URL" echo "PR_URL=$PR_URL" >> $GITHUB_ENV - + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Verify PR details run: | # Extract PR number from URL @@ -73,4 +75,4 @@ jobs: gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/commits \ --jq '.[0].commit.author' env: - GITHUB_TOKEN: ${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }} \ No newline at end of file + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 73d8e40a6f5010b1268fe87dcd2ed3288fd8d9b6 Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 14 Jul 2025 18:15:45 -0400 Subject: [PATCH 17/19] simplify actions, remove actor debug --- .github/workflows/auto_merge.yaml | 53 +++----------------- .github/workflows/debug_actor.yaml | 17 ------- .github/workflows/test_auto_merge.yaml | 69 ++++---------------------- 3 files changed, 17 insertions(+), 122 deletions(-) delete mode 100644 .github/workflows/debug_actor.yaml diff --git a/.github/workflows/auto_merge.yaml b/.github/workflows/auto_merge.yaml index 478e4ffa..c4456625 100644 --- a/.github/workflows/auto_merge.yaml +++ b/.github/workflows/auto_merge.yaml @@ -7,56 +7,17 @@ on: jobs: auto-approve-merge: runs-on: ubuntu-latest - # Check commit author or PR title since actor will be the person who triggered - if: | - contains(github.event.pull_request.title, 'Test: Auto-merge workflow') || - github.event.pull_request.head.repo.full_name == github.repository + if: contains(github.event.pull_request.title, 'Auto-merge workflow') steps: - - name: Check PR Details - id: check-pr + - name: Auto approve and merge run: | - echo "Checking if this PR should be auto-merged..." + echo "Auto-merging PR #${{ github.event.pull_request.number }}" - # Get the commit author of the head commit - COMMIT_AUTHOR=$(gh api \ - repos/${{ github.repository }}/commits/${{ github.event.pull_request.head.sha }} \ - --jq '.commit.author.name') + # Approve + gh pr review ${{ github.event.pull_request.number }} --approve - echo "Commit author: $COMMIT_AUTHOR" - echo "PR title: ${{ github.event.pull_request.title }}" - - # Check if this is a bot commit - if [[ "$COMMIT_AUTHOR" == "github-actions[bot]" ]] || \ - [[ "${{ github.event.pull_request.title }}" == "Test: Auto-merge workflow" ]]; then - echo "should_proceed=true" >> $GITHUB_OUTPUT - else - echo "should_proceed=false" >> $GITHUB_OUTPUT - fi - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Approve PR - if: steps.check-pr.outputs.should_proceed == 'true' - run: | - # Create approval review - gh pr review ${{ github.event.pull_request.number }} \ - --approve \ - --body "Auto-approved by workflow" - env: - GITHUB_TOKEN: ${{ secrets.AUTO_MERGE_TOKEN }} - - - name: Enable Auto-merge - if: steps.check-pr.outputs.should_proceed == 'true' - run: | # Enable auto-merge - gh pr merge ${{ github.event.pull_request.number }} \ - --auto \ - --merge \ - --delete-branch - - # Check status - echo "Auto-merge status:" - gh pr view ${{ github.event.pull_request.number }} --json autoMergeRequest + gh pr merge ${{ github.event.pull_request.number }} --auto --merge --delete-branch env: - GITHUB_TOKEN: ${{ secrets.AUTO_MERGE_TOKEN }} \ No newline at end of file + GH_TOKEN: ${{ secrets.AUTO_MERGE_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/debug_actor.yaml b/.github/workflows/debug_actor.yaml deleted file mode 100644 index ec17c8b7..00000000 --- a/.github/workflows/debug_actor.yaml +++ /dev/null @@ -1,17 +0,0 @@ -name: Debug PR Actor -on: - pull_request: - types: [opened, synchronize] - -jobs: - debug: - runs-on: ubuntu-latest - steps: - - name: Show Actor Info - run: | - echo "github.actor: ${{ github.actor }}" - echo "github.triggering_actor: ${{ github.triggering_actor }}" - echo "PR author: ${{ github.event.pull_request.user.login }}" - echo "PR author type: ${{ github.event.pull_request.user.type }}" - echo "Sender: ${{ github.event.sender.login }}" - echo "Sender type: ${{ github.event.sender.type }}" \ No newline at end of file diff --git a/.github/workflows/test_auto_merge.yaml b/.github/workflows/test_auto_merge.yaml index 000985f3..1133be53 100644 --- a/.github/workflows/test_auto_merge.yaml +++ b/.github/workflows/test_auto_merge.yaml @@ -1,4 +1,4 @@ -name: Create Test PR for Auto-Merge +name: Create Test PR on: workflow_dispatch: push: @@ -8,71 +8,22 @@ jobs: create-test-pr: runs-on: ubuntu-latest steps: - - name: Generate GitHub App Token - id: generate_token - uses: actions/create-github-app-token@v1 - with: - app-id: ${{ vars.APP_ID }} - private-key: ${{ secrets.APP_PRIVATE_KEY }} - continue-on-error: true - - - name: Checkout - uses: actions/checkout@v4 - with: - # Use app token if available, otherwise fallback to GITHUB_TOKEN - token: ${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }} - ref: auto-approve-merge + - uses: actions/checkout@v4 - - name: Create test branch and file + - name: Create test PR run: | - # Create a unique branch name + # Create branch with test file BRANCH_NAME="test-auto-merge-${{ github.run_number }}" - echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV - - # Create and switch to new branch git checkout -b $BRANCH_NAME - - # Create test file - echo "Test auto-merge at $(date)" > test-auto-merge.txt - echo "This file can be deleted after testing" >> test-auto-merge.txt - - # Configure git explicitly as github-actions bot - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - - # Commit with explicit author - git add test-auto-merge.txt - git commit -m "test: auto-merge functionality" \ - --author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" - - # Push with the token that creates the PR + echo "Test $(date)" > test.txt + git add test.txt + git commit -m "test: auto-merge" git push origin $BRANCH_NAME - - name: Create PR using GitHub API - run: | - # The PR will be created by whatever token is used here - PR_URL=$(gh pr create \ + # Create PR + gh pr create \ --base auto-approve-merge \ - --head $BRANCH_NAME \ --title "Test: Auto-merge workflow" \ - --body "This is a test PR to verify auto-merge functionality. - - Created by: github-actions[bot] - - Should trigger: auto-approve and merge workflow - - Can be closed if auto-merge fails") - - echo "Created PR: $PR_URL" - echo "PR_URL=$PR_URL" >> $GITHUB_ENV - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Verify PR details - run: | - # Extract PR number from URL - PR_NUMBER=$(echo $PR_URL | grep -oE '[0-9]+$') - - # Check the actual commit author - echo "Checking commit author on the PR..." - gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/commits \ - --jq '.[0].commit.author' + --body "Testing auto-merge functionality" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 91ec32b2016fa9916667d6e1eb01184dabdffb4b Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 14 Jul 2025 18:17:25 -0400 Subject: [PATCH 18/19] add git config for test --- .github/workflows/test_auto_merge.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test_auto_merge.yaml b/.github/workflows/test_auto_merge.yaml index 1133be53..a45f703c 100644 --- a/.github/workflows/test_auto_merge.yaml +++ b/.github/workflows/test_auto_merge.yaml @@ -12,6 +12,10 @@ jobs: - name: Create test PR run: | + # Configure git identity + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + # Create branch with test file BRANCH_NAME="test-auto-merge-${{ github.run_number }}" git checkout -b $BRANCH_NAME From 8cc3436d67e51f6460a690d5bb988675832e8ce8 Mon Sep 17 00:00:00 2001 From: Jonah Stewart Date: Mon, 14 Jul 2025 18:29:29 -0400 Subject: [PATCH 19/19] debug --- .github/workflows/auto_merge.yaml | 34 +++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto_merge.yaml b/.github/workflows/auto_merge.yaml index c4456625..d4a9bb56 100644 --- a/.github/workflows/auto_merge.yaml +++ b/.github/workflows/auto_merge.yaml @@ -2,15 +2,45 @@ name: Auto Approve and Merge on: pull_request: - types: [opened, synchronize] + types: [opened, synchronize, reopened, ready_for_review] + workflow_dispatch: # Add manual trigger for testing jobs: + debug-context: + runs-on: ubuntu-latest + # Always run this job to see what's happening + steps: + - name: Debug PR Context + run: | + echo "Event Name: ${{ github.event_name }}" + echo "PR Title: ${{ github.event.pull_request.title }}" + echo "PR Number: ${{ github.event.pull_request.number }}" + echo "PR State: ${{ github.event.pull_request.state }}" + echo "Is Draft: ${{ github.event.pull_request.draft }}" + echo "Base Branch: ${{ github.event.pull_request.base.ref }}" + echo "Head Branch: ${{ github.event.pull_request.head.ref }}" + echo "Contains check: ${{ contains(github.event.pull_request.title, 'Auto-merge workflow') }}" + auto-approve-merge: runs-on: ubuntu-latest + # TODO: restore condition if: contains(github.event.pull_request.title, 'Auto-merge workflow') - + steps: + - name: Check conditions + run: | + echo "🔍 Checking if should auto-merge..." + echo "PR Title: '${{ github.event.pull_request.title }}'" + + if [[ "${{ github.event.pull_request.title }}" == *"Auto-merge workflow"* ]]; then + echo "✅ Title contains 'Auto-merge workflow' - proceeding" + else + echo "❌ Title does not contain 'Auto-merge workflow' - would skip" + exit 0 # Don't fail, just skip + fi + - name: Auto approve and merge + if: contains(github.event.pull_request.title, 'Auto-merge workflow') run: | echo "Auto-merging PR #${{ github.event.pull_request.number }}"