Skip to content

chore: Enable auto-merge for dependabot PRs #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 13, 2021
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 }}