This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
203 lines (176 loc) · 6.96 KB
/
auto-update-db.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
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
---
name: Auto Update DB
on:
issues:
types: [labeled]
# no point in concurrency since it still cancels pending jobs
# concurrency:
# # only if label starts with "request" then add issue number to end of group
# group: >-
# ${{ github.workflow }}-${{ github.event.label.name }}
# ${{ startsWith(github.event.label.name, 'request-') | github.event.issue.number }}
# cancel-in-progress: false # false to act as queue
jobs:
auto_update_db:
if: >-
(github.event.label.name == 'add-plugin' || github.event.label.name == 'request-plugin')
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Check if member
if: startsWith(github.event.label.name, 'add-')
# if someone, somehow, adds a label that starts with "add-" 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: Queue
# we only want to run one add job at a time, so queue them
if: startsWith(github.event.label.name, 'add-')
uses: ahmadnassri/action-workflow-queue@v1
- name: Checkout
uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4
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
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Setup Python Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
- name: Parse Issue
uses: stefanbuck/github-issue-parser@v3
id: issue-parser
with:
issue-body: ${{ github.event.issue.body }}
template-path: .github/ISSUE_TEMPLATE/plugin.yml
- name: Crease JSON
run: |
echo '${{ steps.issue-parser.outputs.jsonString }}' > submission.json
- name: Get Issue Author ID
id: author
run: |
echo "issue_author_id=$(echo "${{ github.event.issue.user.id }}")" >> $GITHUB_OUTPUT
- name: Update
id: update
env:
PAT_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
ISSUE_AUTHOR_USER_ID: ${{ steps.author.outputs.issue_author_id }}
run: |
python -u ./updater.py --issue_update
# if exceptions.md file exists, then set output to true
if [ -f exceptions.md ]; then
echo "exception=true" >> $GITHUB_OUTPUT
else
echo "exception=false" >> $GITHUB_OUTPUT
fi
- name: Git Diff
id: diff
working-directory: database
run: |
echo "::group::issue_comment"
git add .
echo "" >> ../comment.md
echo "\`\`\`diff" >> ../comment.md
echo "$(git diff --cached)" >> ../comment.md
echo "\`\`\`" >> ../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@v7
env:
ISSUE_TITLE: ${{ steps.diff.outputs.issue_title }}
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
github.rest.issues.update({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
title: process.env.ISSUE_TITLE
})
- name: Update Labels for Exceptions
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
// get labels
const labels = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
})
// get exception output
const exception = "${{ steps.update.outputs.exception }}"
// check if labels list contains "exception"
const label_exception = labels.data.some(label => label.name === 'exception')
// add exception label if there was an exception and not already labeled
if (!label_exception && exception === 'true') {
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['exception']
})
}
// remove exception label if there is no longer an exception
if (label_exception && exception === 'false') {
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ['exception']
})
}
// check if labels list contains "add-plugin"
const label_add_plugin = labels.data.some(label => label.name === 'add-plugin')
// remove add-plugin label if there was an exception
if (label_add_plugin && exception === 'true') {
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ['add-plugin']
})
}
- name: Issue comment
uses: mshick/add-pr-comment@v2
with:
repo-token: ${{ secrets.GH_BOT_TOKEN }}
message-path: comment.md
- name: GitHub Commit & Push
if: >-
startsWith(github.event.label.name, 'add-') &&
steps.update.outputs.exception == 'false'
uses: actions-js/[email protected]
with:
author_email: ${{ secrets.GH_BOT_EMAIL }}
author_name: ${{ secrets.GH_BOT_NAME }}
branch: database # commit to database
directory: database # use the database directory
github_token: ${{ secrets.GH_BOT_TOKEN }}
message: 'resolves #${{ github.event.issue.number }}'
- name: Close Issue
if: >-
startsWith(github.event.label.name, 'add-') &&
steps.update.outputs.exception == 'false'
env:
GH_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
run: |
comment="This plugin has been added/updated and will be available on the next daily scheduled update."
close_reason="completed"
lock_reason="resolved"
gh issue close ${{ github.event.issue.number }} --comment "${comment}" --reason "${close_reason}"
gh issue lock ${{ github.event.issue.number }} --reason "${lock_reason}"