-
Notifications
You must be signed in to change notification settings - Fork 329
123 lines (105 loc) · 4.33 KB
/
comment-commands.yaml
File metadata and controls
123 lines (105 loc) · 4.33 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Issue and PR comment commands
permissions: {}
on:
issue_comment:
types:
- created
- edited
jobs:
execute:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: jpmcb/prow-github-actions@c44ac3a57d67639e39e4a4988b52049ef45b80dd # v2.0.0
with:
prow-commands: '/assign
/unassign
/lgtm
/milestone'
github-token: "${{ secrets.GITHUB_TOKEN }}"
# /cherry-pick command, only send a message if PR is unmerged, cherry-pick if PR was already merged
cherry-pick:
runs-on: ubuntu-latest
if: |
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/cherry-pick')
permissions:
issues: write
pull-requests: write
contents: write
steps:
# NOTE: can be removed if slash-command-action is uncommented
- name: React to comment
uses: dkershner6/reaction-action@97ede302a1b145b3739dec3ca84a489a34ef48b5 # v2.2.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
reaction: "+1"
- name: Check if PR is merged
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
id: check-merged
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
return {
merged: pr.data.merged,
state: pr.data.state,
mergeCommit: pr.data.merge_commit_sha
};
- name: Extract target branch
if: fromJSON(steps.check-merged.outputs.result).merged == true
id: extract-branch
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
set -euo pipefail
# Keep only the first line
first_line="$(printf '%s' "$COMMENT_BODY" | tr -d '\r' | head -n1)"
candidate="$(printf '%s' "$first_line" | awk '{print $2}')"
if [ -z "${candidate:-}" ]; then
echo "No branch in comment (expected: /cherry-pick <branch>)" >&2
exit 1
fi
# Validate branch format using git
if ! git check-ref-format --branch "$candidate"; then
echo "Invalid branch name: $candidate" >&2
exit 1
fi
echo "branch=$candidate" >> "$GITHUB_OUTPUT"
- name: Comment PR Unmerged
if: ${{ fromJSON(steps.check-merged.outputs.result).merged == false && fromJSON(steps.check-merged.outputs.result).state != 'closed' }}
uses: ben-z/actions-comment-on-issue@402eb412a8f396be0d4ac52a823ec7121206cc26 # v1.0.3
with:
GITHUB_TOKEN: ${{ secrets.PR_UPDATE_TOKEN }}
message: |
Commits from this PR will automatically be cherry-picked once this PR gets merged.
- name: Checkout repository
if: fromJSON(steps.check-merged.outputs.result).merged == true
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Cherry Pick
if: fromJSON(steps.check-merged.outputs.result).merged == true
uses: ./.github/actions/cherry-pick
continue-on-error: true # Send failure comment to PR
id: cherry-pick
with:
github-token: ${{ secrets.PR_UPDATE_TOKEN }}
source-pr: ${{ github.event.issue.number }}
source-pr-title: ${{ github.event.issue.title }}
target-branches: ${{ steps.extract-branch.outputs.branch }}
merge-commit: ${{ fromJson(steps.check-merged.outputs.result).mergeCommit }}
- name: Comment Cherry-pick Fail
if: ${{ steps.cherry-pick.outputs.success == false && fromJSON(steps.check-merged.outputs.result).merged == true }}
uses: ben-z/actions-comment-on-issue@402eb412a8f396be0d4ac52a823ec7121206cc26 # v1.0.3
with:
GITHUB_TOKEN: ${{ secrets.PR_UPDATE_TOKEN }}
message: |
:no_entry_sign: Cherry picking merge commit `${{ fromJSON(steps.check-merged.outputs.result).mergeCommit}}` failed.
Please check workflow logs.