1
+ name : Auto Merge On Demand
2
+ on :
3
+ schedule :
4
+ # Workflow runs every 45 minutes
5
+ - cron : ' */45 * * * *'
6
+ workflow_dispatch :
7
+ inputs :
8
+ pr-number :
9
+ description : ' Pull Request number/s ; when not provided, the workflow will run for all open PRs'
10
+ required : true
11
+ default : ' 0'
12
+
13
+ permissions :
14
+ contents : read
15
+
16
+ jobs :
17
+ # Get all open PRs
18
+ gather-pull-requests :
19
+ if : github.repository_owner == 'sclorg'
20
+ runs-on : ubuntu-latest
21
+
22
+ outputs :
23
+ pr-numbers : ${{ steps.get-pr-numbers.outputs.result }}
24
+ pr-numbers-manual : ${{ steps.parse-manual-input.outputs.result }}
25
+
26
+ steps :
27
+ - id : get-pr-numbers
28
+ if : inputs.pr-number == '0'
29
+ name : Get all open PRs
30
+ uses : actions/github-script@v6
31
+ with :
32
+ # !FIXME: this is not working if there is more than 100 PRs opened
33
+ script : |
34
+ const { data: pullRequests } = await github.rest.pulls.list({
35
+ owner: context.repo.owner,
36
+ repo: context.repo.repo,
37
+ state: 'open',
38
+ per_page: 100
39
+ });
40
+ return pullRequests.map(pr => pr.number);
41
+
42
+ - id : parse-manual-input
43
+ if : inputs.pr-number != '0'
44
+ name : Parse manual input
45
+ run : |
46
+ # shellcheck disable=SC2086
47
+ echo "result="[ ${{ inputs.pr-number }} ]"" >> $GITHUB_OUTPUT
48
+ shell : bash
49
+
50
+ validate-pr :
51
+ name : ' Validation of Pull Request #${{ matrix.pr-number }}'
52
+ needs : [ gather-pull-requests ]
53
+ runs-on : ubuntu-latest
54
+
55
+ strategy :
56
+ fail-fast : false
57
+ matrix :
58
+ pr-number : ${{ inputs.pr-number == 0 && fromJSON(needs.gather-pull-requests.outputs.pr-numbers) || fromJSON(needs.gather-pull-requests.outputs.pr-numbers-manual) }}
59
+
60
+ permissions :
61
+ # required for merging PRs
62
+ contents : write
63
+ # required for PR comments and setting labels
64
+ pull-requests : write
65
+
66
+ steps :
67
+ - id : metadata
68
+ name : Gather Pull Request Metadata
69
+ uses : redhat-plumbers-in-action/gather-pull-request-metadata@v1
70
+ with :
71
+ pr-number : ${{ matrix.pr-number }}
72
+
73
+ - id : pull-request-validator
74
+ name : Pull Request Validator
75
+ uses : redhat-plumbers-in-action/pull-request-validator@v2
76
+ with :
77
+ pr-metadata : ${{ steps.metadata.outputs.metadata }}
78
+ token : ${{ secrets.GITHUB_TOKEN }}
79
+
80
+ - id : auto-merge
81
+ name : Auto Merge
82
+ uses : redhat-plumbers-in-action/auto-merge@v2
83
+ with :
84
+ pr-metadata : ${{ steps.metadata.outputs.metadata }}
85
+ token : ${{ secrets.GITHUB_TOKEN }}
86
+
87
+ - if : ${{ !cancelled() }}
88
+ name : Show results in PR comment
89
+ uses : redhat-plumbers-in-action/issue-commentator@v1
90
+ with :
91
+ issue : ${{ fromJSON(steps.metadata.outputs.metadata).number }}
92
+ message : |
93
+ ${{ steps.pull-request-validator.outputs.status && steps.pull-request-validator.outputs.status || '' }}
94
+ ${{ steps.auto-merge.outputs.status && steps.auto-merge.outputs.status || '' }}
95
+ token : ${{ secrets.GITHUB_TOKEN }}
0 commit comments