-
Notifications
You must be signed in to change notification settings - Fork 3
152 lines (148 loc) · 5.9 KB
/
commands.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: PR Commands
on:
issue_comment:
types: [created, edited]
jobs:
report:
if: ${{ github.event.issue.pull_request && contains(github.event.issue.labels.*.name, 'new theme') }}
runs-on: ubuntu-latest
steps:
- run: |
echo "On PR #$NUM @$ACTOR commented:"
echo "$BODY"
echo "=============================="
echo "PR original body:"
echo "$PRBODY"
echo "=============================="
echo "PR JSON:"
echo "$PR_JSON"
env:
PR_JSON: ${{ toJSON(github.event.issue.pull_request) }}
ACTOR: ${{ github.actor }}
NUM: ${{ github.event.issue.number }}
BODY: ${{ github.event.comment.body }}
PRBODY: ${{ github.event.issue.body }}
update-theme:
if: ${{ github.event.issue.pull_request && contains(github.event.issue.labels.*.name, 'new theme') && contains(github.event.comment.body, '!update') }}
runs-on: ubuntu-latest
steps:
- name: Get head branch
uses: eficode/resolve-pr-refs@v0.0.4
id: branch
with:
token: ${{ github.token }}
- name: Checkout
uses: actions/checkout@v2.7.0
with:
ref: ${{ steps.branch.outputs.head_ref }}
- name: Read body
id: parse
uses: edumserrano/github-issue-forms-parser@v1
with:
template-filepath: .github/ISSUE_TEMPLATE/new-theme.yml
issue-form-body: ${{ github.event.issue.body }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Extract command parameters
id: extractcmd
run: |
ONELINE_MATCH="$(grep -m1 -P '^!update [A-Za-z0-9]([A-Za-z_.-]*[A-Za-z0-9])? [A-Za-z"\[]([A-Za-z_#\[\],"-]*[A-Za-z0-9"\]])?$' <<< "$BODY")" && echo "err=false" >> "$GITHUB_OUTPUT" || echo "err=true" >> "$GITHUB_OUTPUT"
MATCH="$(tr ' ' '\n' <<< "$ONELINE_MATCH")"
echo "prop=$(head -n2 <<< "$MATCH" | tail -n1)" >> "$GITHUB_OUTPUT"
echo "good=$(tail -n1 <<< "$MATCH")" >> "$GITHUB_OUTPUT"
set
env:
BODY: ${{ github.event.comment.body }}
- name: Report error
if: ${{ steps.extractcmd.outputs.err == 'true' }}
run: |
gh pr comment ${{ github.event.issue.number }} --body '❌ Could not find the update data. Type `!help update-theme` to get help.'
exit 1
env:
GH_TOKEN: ${{ github.token }}
- name: Make the change
id: change
run: |
node scripts/add-new-theme.cjs "$(jq <<< "$THEMEINFO" ".$PROP=$GOOD")"
echo '=============================='
cat themes.new.json | jq --tab . | tee src/themes.json
env:
THEMEINFO: ${{ steps.parse.outputs.parsed-issue }}
PROP: ${{ steps.extractcmd.outputs.prop }}
GOOD: ${{ steps.extractcmd.outputs.good }}
- name: Configure Git
id: gitconfig
run: |
git config --global user.name "$GNAME"
git config --global user.email "$GEMAIL"
env:
GNAME: ${{ github.actor }}
GEMAIL: ${{ github.actor }}@users.noreply.github.com
- name: Commit and push
id: commit
run: |
git add src/themes.json
git commit -m"Update $PROP to $GOOD"
git push
env:
PROP: ${{ steps.extractcmd.outputs.prop }}
GOOD: ${{ steps.extractcmd.outputs.good }}
- name: Report error
if: ${{ failure() }}
run: |
if [ "$CHANGE" = failure ]; then
gh issue comment ${{ github.event.issue.number }} --body '❌ An error occured while doing the change.'
elif [ "$GITCONFIG" = failure ]; then
gh issue comment ${{ github.event.issue.number }} --body '❌ An internal error occured while configuring Git.'
elif [ "$COMMIT" = failure ]; then
gh issue comment ${{ github.event.issue.number }} --body '❌ An internal error occured while commiting the changes.'
else
gh issue comment ${{ github.event.issue.number }} --body '❌ An internal error occured.'
fi
env:
CHANGE: ${{ steps.change.conclusion }}
CHLOGS: ${{ steps.change.logs }}
GITCONFIG: ${{ steps.gitconfig.conclusion }}
GCLOGS: ${{ steps.gitconfig.logs }}
COMMIT: ${{ steps.commit.conclusion }}
COMMIT_LOGS: ${{ steps.commit.logs }}
PROP: ${{ steps.extractcmd.outputs.prop }}
GH_TOKEN: ${{ github.token }}
- name: Comment on PR
run: |
gh pr comment ${{ github.event.issue.number }} --body "🎉 Updated \`$PROP\` successfully 👏"
env:
PROP: ${{ steps.extractcmd.outputs.prop }}
GH_TOKEN: ${{ github.token }}
update-theme-help:
if: ${{ github.event.issue.pull_request && contains(github.event.issue.labels.*.name, 'new theme') && contains(github.event.comment.body, '!help update-theme') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.7.0
- name: Comment on PR
run: |
gh pr comment ${{ github.event.issue.number }} --body "$BODY"
env:
BODY: |
Welcome, @${{ github.actor }}.
The `!update` command can be used as following:
```
!update <PROPERTY NAME> <NEW VALUE>
```
Here are the property names:
Field | Property name
---------------------------------- | ------------------
Internal name | `name`
Full name | `fullName`
Background color | `bgcolor`
Color | `color`
Light square color - NORMAL | `lscolor`
Light square color - SELECTED | `lscolor-selected`
Light square color - POSSIBLE MOVE | `lscolor-canmove`
Dark square color - NORMAL | `dscolor`
Dark square color - SELECTED | `dscolor-selected`
Dark square color - POSSIBLE MOVE | `dscolor-canmove`
GH_TOKEN: ${{ github.token }}