Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 }}