-
-
Notifications
You must be signed in to change notification settings - Fork 8
72 lines (66 loc) · 2.59 KB
/
merge.yaml
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
name: Fast-forward merge
on:
issue_comment:
types: [created, edited]
jobs:
fast_forward:
name: Fast-forward merge
runs-on: ubuntu-latest
if: |
github.event.issue.pull_request &&
github.event.issue.state == 'open' &&
(
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
) &&
github.event.comment.body == '/fast-forward-merge'
permissions:
actions: write
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Minimize calling comment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.graphql(`mutation { minimizeComment(input: { subjectId: "${context.payload.comment.node_id}", classifier: OUTDATED }) { clientMutationId } }`)
const { data: comments } = await github.rest.issues.listComments({
...context.repo,
issue_number: ${{ github.event.issue.number }},
});
for (const comment of comments) {
if (comment.user.login === 'github-actions[bot]' && comment.body.startsWith('Failure merging:')) {
await github.graphql(`mutation { minimizeComment(input: { subjectId: "${comment.node_id}", classifier: OUTDATED }) { clientMutationId } }`)
}
}
- name: Checkout pull request
id: pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr checkout ${{ github.event.issue.number }}
echo "base_ref=$(gh pr view ${{ github.event.issue.number }} --json baseRefName)" >> $GITHUB_OUTPUT
- name: Fast-forward merge
run: |
export PR_COMMIT=$(git rev-parse HEAD)
git checkout ${{ fromJSON(steps.pr.outputs.base_ref).baseRefName }}
git merge --ff-only "$PR_COMMIT" 2>output.log
git push origin ${{ fromJSON(steps.pr.outputs.base_ref).baseRefName }} 2>output.log
- name: Post errors
if: ${{ failure() }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr comment ${{ github.event.issue.number }} -b "Failure merging:
\`\`\`
$(cat output.log)
\`\`\`"
- name: Run CI
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh workflow run "Coverage & Documentation" -r ${{ fromJSON(steps.pr.outputs.base_ref).baseRefName }}