-
Notifications
You must be signed in to change notification settings - Fork 108
76 lines (72 loc) · 2.72 KB
/
merge_on_comment.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
name: 'Merge a PR on a comment'
on:
issue_comment:
types: [created]
jobs:
is_merge_command:
if: ${{ github.event.issue.pull_request }}
runs-on: 'ubuntu-latest'
outputs:
is_merge_command: ${{ steps.set_is_merge_command.outputs.is_merge_command }}
steps:
- name: Set is_merge_command
id: set_is_merge_command
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
ruby -e '
is_merge_command = ENV["COMMENT_BODY"].match?(%r!\A/merge\s*\z!)
puts "is_merge_command=#{is_merge_command}"
' >> $GITHUB_OUTPUT
merge:
needs: is_merge_command
if: ${{ needs.is_merge_command.outputs.is_merge_command == 'true' }}
runs-on: 'ubuntu-latest'
permissions:
pull-requests: write
contents: write
steps:
- uses: actions/checkout@v4
with:
filter: 'blob:none'
fetch-depth: 0
ref: main
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: false
- name: Fetch PR information
id: pr_info
env:
PR_NUMBER: ${{ github.event.issue.number }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
pr="$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${GH_REPO}/pulls/${PR_NUMBER})"
author="$(echo "$pr" | jq -r .user.login)"
head_sha="$(echo "$pr" | jq -r .head.sha)"
base_sha="$(echo "$pr" | jq -r .base.sha)"
echo "author=$author" >> $GITHUB_OUTPUT
echo "head_sha=$head_sha" >> $GITHUB_OUTPUT
echo "base_sha=$base_sha" >> $GITHUB_OUTPUT
- name: Changed gems and non gem files
env:
BASE_SHA: ${{ steps.pr_info.outputs.base_sha }}
HEAD_SHA: ${{ steps.pr_info.outputs.head_sha }}
id: changes
run: |
ruby .github/workflows/pr_bot/changed_files.rb
- name: Merge the PR
env:
BASE_SHA: ${{ steps.pr_info.outputs.base_sha }}
HEAD_SHA: ${{ steps.pr_info.outputs.head_sha }}
PR_AUTHOR: ${{ steps.pr_info.outputs.author }}
CHANGED_GEMS: ${{ steps.changes.outputs.gems }}
CHANGED_NON_GEMS: ${{ steps.changes.outputs.non_gems }}
COMMENTED_BY: ${{ github.event.comment.user.login }}
PR_NUMBER: ${{ github.event.issue.number }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
ruby .github/workflows/pr_bot/check_merge_ability.rb "$CHANGED_GEMS" "$CHANGED_NON_GEMS" "$PR_NUMBER"
gh pr merge "$PR_NUMBER" --repo "$GH_REPO" --squash --match-head-commit $HEAD_SHA