automerge #48007
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@11bd71901bbe5b1630ceea73d27597364c9af683 # 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@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # 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@e2e5e9a103e331dad343f381a29e654aea3cf8fc | |
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 |