diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml new file mode 100644 index 0000000000..5da98c171a --- /dev/null +++ b/.github/workflows/auto-merge.yml @@ -0,0 +1,68 @@ +name: Dependabot PR auto-merge + +on: + workflow_run: + workflows: [on-pull-request] + types: ["completed"] + +jobs: + auto-merge: + name: Auto-merge + runs-on: ubuntu-latest + # Run this only when the previous workflow was successfull & the initial actor was dependabot + if: ${{ github.event.workflow_run.conclusion == 'success' && github.actor == 'dependabot[bot]' }} + steps: + - uses: actions/checkout@v2 + - name: Download PR artifact + uses: actions/github-script@v3.1.0 + with: + script: | + const fs = require('fs'); + + // Get all artifacts + const artifacts = await github.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{github.event.workflow_run.id }}, + }); + + // Identify the artifact of the PR + const matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "pr" + })[0]; + + // Download the actual artifact + const download = await github.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + + // Write it to disk + fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); + - name: Unzip artifact + run: unzip pr.zip + - name: Merge PR + uses: actions/github-script@v3 + with: + script: | + const fs = require('fs'); + const pullNumber = Number(fs.readFileSync('./NR')); + + // Create a review + github.pulls.createReview({ + owner: context.payload.repository.owner.login, + repo: context.payload.repository.name, + pull_number: pullNumber, + event: 'APPROVE' + }) + + // Merge PR + github.pulls.merge({ + owner: context.payload.repository.owner.login, + repo: context.payload.repository.name, + pull_number: pullNumber, + merge_method: 'squash' + }) + github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file