generated from actions/typescript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 14
104 lines (101 loc) · 3.58 KB
/
automerge.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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