-
-
Notifications
You must be signed in to change notification settings - Fork 9
261 lines (232 loc) · 9.35 KB
/
Copy pathauto-update-db.yml
File metadata and controls
261 lines (232 loc) · 9.35 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
---
name: Auto Update DB
run-name: ${{ github.event.label.name }} ${{ github.event.issue.title }}
permissions: {}
env:
PYTHON_VERSION: '3.14'
on:
issues:
types:
- labeled
# GitHub concurrency still cancels pending runs in the same group, so approved
# database writes use explicit wait steps instead.
jobs:
auto_update_db:
if: (github.event.label.name == 'request-theme' || github.event.label.name == 'approve-theme')
runs-on: ubuntu-latest
env:
EVENT_ISSUE_NUMBER: ${{ github.event.issue.number }}
GH_TOKEN: ${{ github.token }}
permissions:
actions: read
contents: read
steps:
- name: Check if member
if: (github.event.label.name == 'approve-theme')
# if someone, somehow, adds the approval label but isn't a member, then exit
run: |
gh api \
-H "Accept: application/vnd.github+json" \
"/orgs/${GITHUB_REPOSITORY_OWNER}/members/${GITHUB_ACTOR}" || exit 1
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Wait for approved database updates
if: (github.event.label.name == 'approve-theme')
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const {waitForWorkflowJobs} = require('./src/github-scripts/workflow-run-queue.js')
await waitForWorkflowJobs({
github,
context,
workflowId: 'auto-update-db.yml',
runTitlePrefix: 'approve-theme ',
markerStepName: 'Wait for approved database updates'
})
await waitForWorkflowJobs({
github,
context,
workflowId: 'update-pages.yml',
ignoredEvents: ['pull_request'],
jobName: 'update'
})
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: database
path: database
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, will fail to push refs to dest repo
filter: blob:none # full history for rebase, but skip historical file blobs
- name: Setup Python
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
with:
enable-cache: true
- name: Setup Python Dependencies
run: uv sync --locked --python "${PYTHON_VERSION}" --no-python-downloads
- name: Parse Issue
uses: stefanbuck/github-issue-parser@cb6e97157cbf851e3a393ff8d57c93a484cc323f # v3.2.5
id: issue-parser
with:
template-path: .github/ISSUE_TEMPLATE/theme.yml
- name: Crease JSON
env:
JSON_STRING: ${{ steps.issue-parser.outputs.jsonString }}
run: echo "${JSON_STRING}" > submission.json
- name: Check Queue Eligibility
id: queue
if: github.event.label.name == 'request-theme'
env:
ISSUE_AUTHOR_USER_ID: ${{ github.event.issue.user.id }}
run: uv run --no-sync python -m src.queue_eligibility
- name: Update
id: update
env:
ISSUE_AUTHOR_LOGIN: ${{ github.event.issue.user.login }}
ISSUE_AUTHOR_USER_ID: ${{ github.event.issue.user.id }}
TMDB_API_KEY_V3: ${{ secrets.TMDB_API_KEY_V3 }}
TWITCH_CLIENT_ID: ${{ secrets.TWITCH_CLIENT_ID }}
TWITCH_CLIENT_SECRET: ${{ secrets.TWITCH_CLIENT_SECRET }}
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
run: uv run --no-sync python -u ./src/updater.py --issue_update
- name: Set Outputs
id: outputs
if: always()
run: |
# if exceptions.md file exists, then set output to true
exception=false
if [ -f exceptions.md ]; then
exception=true
fi
echo "exception=${exception}" >> "${GITHUB_OUTPUT}"
# if duplicate.md file exists, then set output to true
duplicate=false
if [ -f duplicate.md ]; then
duplicate=true
fi
echo "duplicate=${duplicate}" >> "${GITHUB_OUTPUT}"
# if auto_close.md file exists, then set output to true
auto_close=false
if [ -f auto_close.md ]; then
auto_close=true
fi
echo "auto_close=${auto_close}" >> "${GITHUB_OUTPUT}"
- name: Git Diff
id: diff
if: always()
working-directory: database
run: |
echo "::group::issue_comment"
git add .
{
echo ""
echo "\`\`\`diff"
git diff --cached
echo "\`\`\`"
echo ""
echo ""
cat ../docs/botCommands.md
} >> ../comment.md
cat ../comment.md
echo "::endgroup::"
echo "::group::issue_title"
cat ../title.md
echo "issue_title=$(cat ../title.md)" >> "${GITHUB_OUTPUT}"
echo "::endgroup::"
- name: Update Issue Title
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
ISSUE_TITLE: ${{ steps.diff.outputs.issue_title }}
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
const {run} = require('./src/github-scripts/update-issue-title.js')
await run({github, context})
- name: Update Labels
id: labels
if: always()
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
AUTO_CLOSE: ${{ steps.outputs.outputs.auto_close }}
DUPLICATE: ${{ steps.outputs.outputs.duplicate }}
EXCEPTION: ${{ steps.outputs.outputs.exception }}
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
result-encoding: string
script: |
const {run} = require('./src/github-scripts/update-labels.js')
return await run({github, context})
- name: Issue comment
if: always()
uses: mshick/add-pr-comment@ec328af66588ab8f77cdeb2c264f14aba45bbf59 # v3.12
with:
repo-token: ${{ secrets.GH_BOT_TOKEN }}
message-path: comment.md
- name: Queue Eligible Submission
if:
(github.event.label.name == 'request-theme') &&
steps.outputs.outputs.exception == 'false' &&
steps.outputs.outputs.duplicate == 'false' &&
steps.outputs.outputs.auto_close == 'false' &&
steps.queue.outputs.queue_eligible == 'true'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
const {run} = require('./src/github-scripts/queue-eligible-submission.js')
await run({github, context})
- name: Auto Close
if:
(github.event.label.name == 'request-theme' || github.event.label.name == 'approve-theme') &&
steps.outputs.outputs.auto_close == 'true'
env:
GH_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
run: |
comment=$(cat auto_close.md)
close_reason="not planned"
lock_reason="resolved"
gh issue close "${EVENT_ISSUE_NUMBER}" --comment "${comment}" --reason "${close_reason}"
gh issue lock "${EVENT_ISSUE_NUMBER}" --reason "${lock_reason}"
- name: GitHub Commit & Push
if:
(github.event.label.name == 'approve-theme') &&
steps.outputs.outputs.exception == 'false' &&
steps.outputs.outputs.auto_close == 'false' &&
steps.labels.outputs.result == 'true'
uses: actions-js/push@5a7cbd780d82c0c937b5977586e641b2fd94acc5 # v1.5
with:
author_email: ${{ secrets.GH_BOT_EMAIL }}
author_name: ${{ vars.GH_BOT_NAME }}
branch: database
directory: database
github_token: ${{ secrets.GH_BOT_TOKEN }}
message: 'chore: resolves #${{ github.event.issue.number }}'
rebase: true
- name: Close Issue
if:
(github.event.label.name == 'approve-theme') &&
steps.outputs.outputs.exception == 'false' &&
steps.outputs.outputs.auto_close == 'false' &&
steps.labels.outputs.result == 'true'
env:
GH_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
run: |
comment="This theme has been added/updated and will be available on the next daily scheduled update."
close_reason="completed"
lock_reason="resolved"
gh issue close "${EVENT_ISSUE_NUMBER}" --comment "${comment}" --reason "${close_reason}"
gh issue lock "${EVENT_ISSUE_NUMBER}" --reason "${lock_reason}"
- name: Label next issue
if:
(github.event.label.name == 'approve-theme') &&
steps.outputs.outputs.exception == 'false'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
const {run} = require('./src/github-scripts/label-next-issue.js')
await run({github, context})