|
| 1 | +name: Auto-merge Bot PRs |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["OpenSSL testing"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + |
| 9 | +permissions: |
| 10 | + pull-requests: write |
| 11 | + contents: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + enable-auto-merge: |
| 15 | + if: | |
| 16 | + github.repository == 'envoyproxy/envoy-openssl' |
| 17 | + && github.event.workflow_run.conclusion == 'success' |
| 18 | + && github.event.workflow_run.repository.full_name == github.repository |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Get PR info |
| 23 | + id: pr |
| 24 | + uses: actions/github-script@v7 |
| 25 | + with: |
| 26 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + script: | |
| 28 | + const prs = context.payload.workflow_run.pull_requests; |
| 29 | + if (prs.length === 0) { |
| 30 | + core.notice("No pull request associated with this workflow_run (likely from a fork). Skipping workflow."); |
| 31 | + // Explicitly set a flag so next steps can check |
| 32 | + core.setOutput("skip", "true"); |
| 33 | + return; |
| 34 | + } |
| 35 | + const prNumber = prs[0].number; |
| 36 | + const { data: pr } = await github.rest.pulls.get({ |
| 37 | + owner: context.repo.owner, |
| 38 | + repo: context.repo.repo, |
| 39 | + pull_number: prNumber |
| 40 | + }); |
| 41 | + core.setOutput("pr_number", pr.number); |
| 42 | + core.setOutput("pr_author", pr.user.login); |
| 43 | + core.setOutput("labels", pr.labels.map(l => l.name).join(",")); |
| 44 | +
|
| 45 | + - name: Print info |
| 46 | + if: ${{ steps.pr.outputs.skip != 'true' }} |
| 47 | + run: | |
| 48 | + echo "PR author: ${{ steps.pr.outputs.pr_author }}" |
| 49 | + echo "Labels: ${{ steps.pr.outputs.labels }}" |
| 50 | + if [[ "${{ steps.pr.outputs.pr_author }}" != "update-openssl-envoy[bot]" ]]; then |
| 51 | + echo "::notice title=Skip reason::PR author is not update-openssl-envoy[bot]" |
| 52 | + fi |
| 53 | + if [[ "${{ steps.pr.outputs.labels }}" != *"auto-merge"* ]]; then |
| 54 | + echo "::notice title=Skip reason::Label 'auto-merge' not found" |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Merge PR |
| 58 | + if: ${{ steps.pr.outputs.skip != 'true' && contains(steps.pr.outputs.labels, 'auto-merge') && steps.pr.outputs.pr_author == 'update-openssl-envoy[bot]' }} |
| 59 | + uses: actions/github-script@v7 |
| 60 | + with: |
| 61 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + script: | |
| 63 | + const prNumber = parseInt('${{ steps.pr.outputs.pr_number }}'); |
| 64 | + await github.rest.pulls.merge({ |
| 65 | + owner: context.repo.owner, |
| 66 | + repo: context.repo.repo, |
| 67 | + pull_number: prNumber, |
| 68 | + merge_method: 'merge' |
| 69 | + }); |
| 70 | + core.notice(`✅ PR #${prNumber} merged automatically.`); |
0 commit comments