Skip to content

automerge

automerge #41312

Workflow file for this run

name: automerge
on:
schedule:
- cron: 0 * * * *
pull_request_review:
types:
- submitted
pull_request_target:
types:
- opened
- synchronize
- reopened
- edited
- labeled
- unlabeled
- ready_for_review
workflow_dispatch:
inputs:
pull-request:
description: Pull Request Number
required: false
review:
description: Review ID
required: false
jobs:
automerge:
if: >
github.event_name != 'workflow_run' || (
github.event.workflow_run.event == 'pull_request_review' &&
github.event.workflow_run.conclusion == 'success'
)
runs-on: ubuntu-latest
steps:
- name: Event
run: |
echo "${EVENT_NAME}"
echo "${EVENT_JSON}"
env:
EVENT_NAME: ${{ github.event_name }}
EVENT_JSON: ${{ toJSON(github.event) }}
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
with:
ref: main
- uses: ./
with:
token: ${{ secrets.GH_TOKEN }}
squash-commit-title: ${pull_request.title} (#${pull_request.number})
squash-commit-message: '\n'
do-not-merge-labels: never-merge
required-labels: automerge
pull-request: ${{ github.event.inputs.pull-request }}
review: ${{ github.event.inputs.review }}
if: github.event_name != 'pull_request_review'
- name: Upload `event.json`
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
if: github.event_name == 'pull_request_review'
with:
name: event.json
path: ${{ github.event_path }}
if-no-files-found: error
- name: Download `event.json`
id: download_event_json
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
...context.repo,
run_id: ${{ github.event.workflow_run.id }},
})
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "event.json"
})[0]
const download = await github.rest.actions.downloadArtifact({
...context.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs')
fs.writeFileSync('${{ github.workspace }}/artifact.zip', Buffer.from(download.data))
if: >
github.event.workflow_run.event == 'pull_request_review' &&
github.event.workflow_run.conclusion == 'success'
- name: Extract `event.json`
id: review_info
run: |
unzip artifact.zip
echo "pull_request=$(jq -r .pull_request.number event.json)" >> "${GITHUB_OUTPUT}"
echo "review=$(jq -r .review.id event.json)" >> "${GITHUB_OUTPUT}"
if: steps.download_event_json.outcome == 'success'
- name: Trigger workflow for review ${{ steps.review_info.outputs.review }} on pull request \#${{ steps.review_info.outputs.pull_request }}
uses: benc-uk/workflow-dispatch@25b02cc069be46d637e8fe2f1e8484008e9e9609
with:
workflow: automerge.yml
inputs: >
{
"pull-request": "${{ steps.review_info.outputs.pull_request }}",
"review": "${{ steps.review_info.outputs.review }}"
}
if: >
steps.review_info.outputs.pull_request &&
steps.review_info.outputs.review