Skip to content

Commit 0a17d46

Browse files
committed
Enable auto-merge in s2i-nodejs-container
Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent 7ed8c57 commit 0a17d46

File tree

4 files changed

+142
-0
lines changed

4 files changed

+142
-0
lines changed

.github/auto-merge.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target-branch: []
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Auto Merge Scheduled / 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@v7
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+
- name: Auto Merge wrapper
68+
uses: sclorg/auto-merge-wrapper@v1
69+
with:
70+
pr-number: ${{ matrix.pr-number }}
71+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/auto-merge.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Auto Merge
2+
on:
3+
workflow_run:
4+
workflows: [ Gather Pull Request Metadata ]
5+
types:
6+
- completed
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
download-metadata:
13+
if: >
14+
github.event.workflow_run.event == 'pull_request' &&
15+
github.event.workflow_run.conclusion == 'success'
16+
runs-on: ubuntu-latest
17+
18+
outputs:
19+
pr-metadata: ${{ steps.Artifact.outputs.pr-metadata-json }}
20+
21+
steps:
22+
- id: Artifact
23+
name: Download Artifact
24+
uses: redhat-plumbers-in-action/download-artifact@v1
25+
with:
26+
name: pr-metadata
27+
28+
auto-merge:
29+
needs: [ download-metadata ]
30+
runs-on: ubuntu-latest
31+
32+
permissions:
33+
# required for merging PRs
34+
contents: write
35+
# required for PR comments and setting labels
36+
pull-requests: write
37+
38+
steps:
39+
- name: Auto Merge wrapper
40+
uses: sclorg/auto-merge-wrapper@v1
41+
with:
42+
pr-metadata: ${{ needs.download-metadata.outputs.pr-metadata }}
43+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/pr-metadata.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Gather Pull Request Metadata
2+
on:
3+
pull_request:
4+
types: [ opened, reopened, synchronize ]
5+
branches: [ master ]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
gather-metadata:
12+
if: github.repository_owner == 'sclorg'
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Repository checkout
17+
uses: actions/checkout@v4
18+
19+
- id: Metadata
20+
name: Gather Pull Request Metadata
21+
uses: redhat-plumbers-in-action/gather-pull-request-metadata@v1
22+
23+
- name: Upload artifact with gathered metadata
24+
uses: actions/upload-artifact@v4
25+
with:
26+
name: pr-metadata
27+
path: ${{ steps.Metadata.outputs.metadata-file }}

0 commit comments

Comments
 (0)