Skip to content

Commit

Permalink
ci(automerge): move automerge job into new workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Frazer Smith committed Mar 29, 2021
1 parent 4422367 commit 1f6c64c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Automerge Dependabot PRs

on:
workflow_run:
workflows: ["CI"]
types: [completed]

jobs:
on-success:
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' &&
github.actor == 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: Download Artifact
uses: actions/github-script@v3.1.0
with:
script: |
const fs = require('fs');
const artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == 'pr';
})[0];
const download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
- run: unzip pr.zip
- name: Comment on PR
uses: actions/github-script@v3.1.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const pull_number = Number(fs.readFileSync('./NR'));
await github.pulls.merge({
merge_method: "merge",
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull_number,
});
21 changes: 14 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,20 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true

automerge:
name: Automatically Merge Dependabot Pull Requests
if: github.event.pull_request.draft == false
needs: [commit-lint, lint, unit-tests]
# This job is used to save the PR number in an artifact, for use in the automerge.yml workflow
save-pr-number:
name: Save PR Number
if: >
github.event.pull_request.draft == false &&
github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: fastify/github-action-merge-dependabot@v1.2.1
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }}
- uses: actions/checkout@v2.3.4
- name: Save PR Number
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/NR
- uses: actions/upload-artifact@v2.2.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
name: pr
path: pr/

0 comments on commit 1f6c64c

Please sign in to comment.