-
-
Notifications
You must be signed in to change notification settings - Fork 1
96 lines (86 loc) · 3.2 KB
/
fast-forward.yml
File metadata and controls
96 lines (86 loc) · 3.2 KB
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
name: fast-forward
on:
issue_comment:
types: [created, edited]
jobs:
fast-forward:
# Only run if the comment contains the /fast-forward command.
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/fast-forward') }}
runs-on: ubuntu-latest
concurrency:
group: fast-forward-${{ github.event.issue.number }}
cancel-in-progress: true
# https://docs.github.com/ko/actions/writing-workflows/workflow-syntax-for-github-actions#permissions
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: Check comment
id: check_comment
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
if [[ "$COMMENT_BODY" =~ (^|[[:space:]])/fast-forward($|[[:space:]]) ]]; then
echo "MATCH=true" >> $GITHUB_OUTPUT
else
echo "MATCH=false" >> $GITHUB_OUTPUT
fi
- name: Fast forwarding
if: ${{ steps.check_comment.outputs.MATCH == 'true' }}
uses: sequoia-pgp/fast-forward@v1
with:
merge: true
# To reduce the workflow's verbosity, use 'on-error'
# to only post a comment when an error occurs, or 'never' to
# never post a comment. (In all cases the information is
# still available in the step's summary.)
comment: always
- name: Check target branch
if: ${{ steps.check_comment.outputs.MATCH == 'true' }}
id: check_branch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# From https://github.com/sequoia-pgp/fast-forward/blob/main/src/fast-forward.sh
PR_URL="${{ github.event.issue.pull_request.url }}"
if test "x$PR_URL" = x
then
echo "Unable to find pull request's context."
exit 1
fi
GITHUB_PR=$(mktemp)
function get_pr_info {
# https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request
curl --silent --show-error --location \
-X GET \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"$PR_URL" >$GITHUB_PR
}
function check_pr_merged {
local merged_status="false"
local attempt=1
local max_attempts=30
local sleep_duration=1
while [ "$merged_status" != "true" ] && [ $attempt -le $max_attempts ]; do
get_pr_info
merged_status=$(jq -r ".merged" <$GITHUB_PR)
if [ "$merged_status" = "true" ]; then
break
else
sleep $sleep_duration
((attempt++))
fi
done
if [ $attempt -gt $max_attempts ]; then
echo "The maximum number of attempts has been reached. The pull request was not merged."
exit 1
fi
}
get_pr_info
BASE_REF=$(jq -r ".base.ref" <$GITHUB_PR)
if [ "$BASE_REF" = "main" ]; then
check_pr_merged
fi