2022-06-09 15:44:58 -04:00
name : Dependabot auto-merge
on :
workflow_run :
workflows : [ "Tests" ]
2022-06-09 19:21:33 -04:00
# completed does not mean success of Tests workflow. see below checking github.event.workflow_run.conclusion
2022-06-09 15:44:58 -04:00
types :
- completed
2022-06-09 18:57:25 -04: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-06-09 15:44:58 -04:00
permissions :
contents : write
jobs :
2022-06-10 09:20:03 -04:00
printJob :
name : Print event
runs-on : ubuntu-latest
steps :
- name : Dump GitHub context
env :
GITHUB_CONTEXT : ${{ toJson(github) }}
run : |
echo "$GITHUB_CONTEXT"
2022-06-09 15:44:58 -04:00
dependabot :
runs-on : ubuntu-latest
2022-06-09 19:21:33 -04:00
# FIXME: uncomment after logging confirms actor is dependabot
2022-06-10 09:40:05 -04:00
# if: ${{ github.actor == 'dependabot[bot]' && github.event.workflow_run.conclusion == 'success' }}
2022-06-09 15:44:58 -04:00
steps :
2022-06-09 19:21:33 -04:00
- name : Log github metadata for debugging
2022-06-09 17:50:50 -04:00
# if: ${{contains(steps.metadata.outputs.dependency-names, 'pytest') && steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
# if: ${{contains(steps.metadata.outputs.dependency-names, 'pytest')}}
# ideally we auto-merge if all checks pass
run : |
2022-06-09 18:57:25 -04:00
echo about to log stuff from webhook
2022-06-09 17:50:50 -04:00
echo actor : ${{ github.actor }}
echo conclusion : ${{ github.event.workflow_run.conclusion }}
echo event_name : ${{ github.event_name }}
echo pr_url : ${{ github.event.pull_request.html_url }}
2022-06-09 18:57:25 -04:00
echo workflow : ${{ github.workflow }}
2022-06-09 17:50:50 -04:00
echo and going to next step where it should auto merge
env :
PR_URL : ${{github.event.pull_request.html_url}}
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
2022-06-09 19:21:33 -04:00
# 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
- name : 'Download artifact'
uses : actions/github-script@v6
with :
script : |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner : context.repo.owner,
repo : context.repo.repo,
run_id : context.payload.workflow_run.id,
2022-06-10 08:58:51 -04:00
});
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-09 19:21:33 -04:00
- name : 'Unzip artifact'
run : unzip pr_number.zip
2022-06-10 09:40:05 -04:00
#
# - name: Dependabot metadata
# id: metadata
# uses: dependabot/fetch-metadata@v1.3.1
# with:
# github-token: "${{ secrets.GITHUB_TOKEN }}"
2022-06-09 19:21:33 -04:00
- name : actually merge it
2022-06-09 15:44:58 -04:00
# if: ${{contains(steps.metadata.outputs.dependency-names, 'pytest') && steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
# if: ${{contains(steps.metadata.outputs.dependency-names, 'pytest')}}
# ideally we auto-merge if all checks pass
2022-06-09 19:21:33 -04:00
# run: gh pr merge --auto --merge "$PR_URL"
run : gh pr merge --auto --merge "$(cat pr_number)"
2022-06-09 15:44:58 -04:00
env :
PR_URL : ${{github.event.pull_request.html_url}}
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}