Skip to content

Commit

Permalink
Merge pull request #28 from Fdawgs/ci/automerge
Browse files Browse the repository at this point in the history
ci: automerge
  • Loading branch information
Fdawgs committed Mar 29, 2021
2 parents 5bf2463 + c5d7ab5 commit 45f7942
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 9 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/automerge.yml
@@ -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,
});
25 changes: 17 additions & 8 deletions .github/workflows/ci.yml
Expand Up @@ -31,7 +31,9 @@ jobs:

commit-lint:
name: Lint Commit Messages
if: github.event.pull_request.draft == false
if: >
github.event.pull_request.draft == false &&
github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
Expand Down Expand Up @@ -78,13 +80,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.1.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/
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
@@ -1,4 +1,4 @@
name: Mark Stale Issues and Pull Requests
name: Mark Stale Issues and PRs

on:
schedule:
Expand Down

0 comments on commit 45f7942

Please sign in to comment.