Skip to content

Commit

Permalink
Add auto-merge checkers for information to developers
Browse files Browse the repository at this point in the history
what is missing in PR.

Later on in case PR is approved by two reviewers and
PR contains label 'READY-to-MERGE' it will be automatically
merged. Otherwise only manually.

Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
  • Loading branch information
phracek committed Sep 26, 2024
1 parent 72e3aa0 commit 04ec37d
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target-branch: []
71 changes: 71 additions & 0 deletions .github/workflows/auto-merge-on-demand.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Auto Merge Scheduled / On Demand
on:
schedule:
# Workflow runs every 45 minutes
- cron: '*/45 * * * *'
workflow_dispatch:
inputs:
pr-number:
description: 'Pull Request number/s ; when not provided, the workflow will run for all open PRs'
required: true
default: '0'

permissions:
contents: read

jobs:
# Get all open PRs
gather-pull-requests:
if: github.repository_owner == 'sclorg'
runs-on: ubuntu-latest

outputs:
pr-numbers: ${{ steps.get-pr-numbers.outputs.result }}
pr-numbers-manual: ${{ steps.parse-manual-input.outputs.result }}

steps:
- id: get-pr-numbers
if: inputs.pr-number == '0'
name: Get all open PRs
uses: actions/github-script@v7
with:
# !FIXME: this is not working if there is more than 100 PRs opened
script: |
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 100
});
return pullRequests.map(pr => pr.number);
- id: parse-manual-input
if: inputs.pr-number != '0'
name: Parse manual input
run: |
# shellcheck disable=SC2086
echo "result="[ ${{ inputs.pr-number }} ]"" >> $GITHUB_OUTPUT
shell: bash

validate-pr:
name: 'Validation of Pull Request #${{ matrix.pr-number }}'
needs: [ gather-pull-requests ]
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
pr-number: ${{ inputs.pr-number == 0 && fromJSON(needs.gather-pull-requests.outputs.pr-numbers) || fromJSON(needs.gather-pull-requests.outputs.pr-numbers-manual) }}

permissions:
# required for merging PRs
contents: write
# required for PR comments and setting labels
pull-requests: write

steps:
- name: Auto Merge wrapper
uses: sclorg/auto-merge-wrapper@v1
with:
pr-number: ${{ matrix.pr-number }}
token: ${{ secrets.GITHUB_TOKEN }}
43 changes: 43 additions & 0 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Auto Merge
on:
workflow_run:
workflows: [ Gather Pull Request Metadata ]
types:
- completed

permissions:
contents: read

jobs:
download-metadata:
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest

outputs:
pr-metadata: ${{ steps.Artifact.outputs.pr-metadata-json }}

steps:
- id: Artifact
name: Download Artifact
uses: redhat-plumbers-in-action/download-artifact@v1
with:
name: pr-metadata

auto-merge:
needs: [ download-metadata ]
runs-on: ubuntu-latest

permissions:
# required for merging PRs
contents: write
# required for PR comments and setting labels
pull-requests: write

steps:
- name: Auto Merge wrapper
uses: sclorg/auto-merge-wrapper@v1
with:
pr-metadata: ${{ needs.download-metadata.outputs.pr-metadata }}
token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 04ec37d

Please sign in to comment.