2022-05-13 17:42:42 +00:00
name : Dependabot auto-merge
on :
workflow_run :
workflows : [ "Tests" ]
2022-06-10 21:42:19 +00:00
# completed does not mean success of Tests workflow. see below checking github.event.workflow_run.conclusion
2022-05-13 17:42:42 +00:00
types :
- completed
2022-06-10 21:42:19 +00:00
# workflow_call is used to indicate that a workflow can be called by another workflow. When a workflow is triggered with the workflow_call event, the event payload in the called workflow is the same event payload from the calling workflow. For more information see, "Reusing workflows."
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
# maybe hook into this instead of workflow_run:
# on:
# pull_request:
# pull_request_target:
# types: [labeled]
2022-05-13 17:42:42 +00:00
permissions :
contents : write
jobs :
2022-06-10 21:42:19 +00:00
# print the context for debugging in case a job gets skipped
printJob :
name : Print event
runs-on : ubuntu-latest
steps :
2022-06-10 21:48:36 +00:00
- name : Dump GitHub context
env :
GITHUB_CONTEXT : ${{ toJson(github) }}
run : |
echo "$GITHUB_CONTEXT"
2022-06-10 21:42:19 +00:00
2022-05-13 17:42:42 +00:00
dependabot :
runs-on : ubuntu-latest
2022-06-10 21:42:19 +00:00
if : ${{ github.actor == 'dependabot[bot]' && github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
2022-05-13 17:42:42 +00:00
steps :
2022-06-10 21:42:19 +00:00
- name : Development Code
uses : actions/checkout@v3
###### GET PR NUMBER
# we saved the pr_number in tests.yml. fetch it so we can merge the correct PR.
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
2022-06-10 21:48:36 +00:00
- name : "Download artifact"
2022-06-10 21:42:19 +00:00
uses : actions/github-script@v6
2022-05-13 17:42:42 +00:00
with :
2022-06-10 21:42:19 +00:00
script : |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner : context.repo.owner,
repo : context.repo.repo,
run_id : context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr_number"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner : context.repo.owner,
repo : context.repo.repo,
artifact_id : matchArtifact.id,
archive_format : 'zip' ,
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
2022-06-10 21:48:36 +00:00
- name : "Unzip artifact"
2022-06-10 21:42:19 +00:00
run : unzip pr_number.zip
###########
- name : print pr number
run : cat pr_number
- name : actually merge it
run : gh pr merge --auto --merge "$(cat pr_number)"
2022-05-13 17:42:42 +00:00
env :
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}