-
-
Notifications
You must be signed in to change notification settings - Fork 442
70 lines (63 loc) · 2.12 KB
/
Copy pathlabelize.yml
File metadata and controls
70 lines (63 loc) · 2.12 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
on:
issue_comment:
types: created
name: Labelize
jobs:
#----------------------------------------------------------------------------
# Labelize
#----------------------------------------------------------------------------
labelize:
name: Labelize
runs-on: ubuntu-latest
if: |
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '\ci')
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.F3D_CI_LABEL }}
steps:
- name: Injection check
if: ${{contains(github.event.comment.body, '$')}}
shell: bash
run: exit 1
# Remove the first word
# Extract the second word
# Sanitize it
# Using an env var is a way to ensure user input is not an injection
# https://securitylab.github.com/resources/github-actions-untrusted-input/
- name: Analyze comment
env:
COMMENT: ${{github.event.comment.body}}
shell: bash
run: |
label="$COMMENT"
label=${label#* }
label=${label%% *}
label=${label//[^a-z-_]/}
echo "F3D_LABEL_COMMENT=$label" >> $GITHUB_ENV
# Stop the job if cache is being added
- name: cache stop
if: env.F3D_LABEL_COMMENT == 'cache'
shell: bash
run: exit 0
- name: Add ack reaction
uses: GrantBirki/comment@v3.0.3
with:
comment-id: ${{ github.event.comment.id }}
reactions: eyes
- name: Add label on PR
if: ${{!contains(env.F3D_LABEL_COMMENT, '-')}}
shell: bash
run: gh issue edit ${{ github.event.issue.number }} --add-label "ci:${{env.F3D_LABEL_COMMENT}}"
- name: Remove label on PR
if: contains(env.F3D_LABEL_COMMENT, '-')
shell: bash
run: |
label="${{env.F3D_LABEL_COMMENT}}"
label=${label#*-}
gh issue edit ${{ github.event.issue.number }} --remove-label "ci:$label"
- name: Create comment for invalid command
if: failure()
uses: GrantBirki/comment@v3.0.3
with:
body: ❌ Invalid CI command "${{env.F3D_LABEL_COMMENT}}"