-
-
Notifications
You must be signed in to change notification settings - Fork 73
314 lines (298 loc) · 11.7 KB
/
plugin-repo-gen.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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
name: Unmanic Plugin Test and Generate Repo
on:
push:
branches:
- '**'
- 'pr-**'
- '!template'
pull_request:
branches:
- 'official'
- 'master'
jobs:
# Ensure that all plugins contain the required files and that
# certain files or directories are not present.
plugins-contain-required-files:
runs-on: ubuntu-latest
name: Plugins contain all required files
steps:
# Checkout
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# _____ ____ _
# | ____|_ __ ___ _ _ _ __ ___ | _ \ _ __ ___ ___ ___ _ __ | |_
# | _| | '_ \/ __| | | | '__/ _ \ | |_) | '__/ _ \/ __|/ _ \ '_ \| __|
# | |___| | | \__ \ |_| | | | __/ | __/| | | __/\__ \ __/ | | | |_
# |_____|_| |_|___/\__,_|_| \___| |_| |_| \___||___/\___|_| |_|\__|
#
- name: Check all plugins exist in source directory
if: success() || failure()
run: |
success=0
for root_dir in ./*; do
if [ -d "${root_dir:?}" ]; then
# Ignore docs directory
[ "$(basename ${root_dir:?})" == "docs" ] && continue
# The only other directory should be "source"
if [ "$(basename ${root_dir:?})" != "source" ]; then
echo "FAIL - Found an unexpected directory in '${root_dir:?}'. All plugins should be added to './source/'."
success=1
fi
fi
done
if [ ${success} -gt 0 ]; then
exit 1
else
echo "PASS - Found a correct directory structure in the project root."
fi
- name: Check .gitignore in all plugin folders
if: success() || failure()
run: |
success=0
for plugin_dir in source/*; do
if [ -d "${plugin_dir}" ]; then
# Ensure this directory contains a .gitignore file
if [ -e "${plugin_dir}/.gitignore" ]; then
echo "PASS - Found .gitignore in plugin '${plugin_dir}'"
else
echo "FAIL - Missing .gitignore in plugin '${plugin_dir}'"
success=1
fi
fi
done
if [ ${success} -gt 0 ]; then
exit 1
fi
- name: Check info.json in all plugin folders
if: success() || failure()
run: |
success=0
for plugin_dir in source/*; do
if [ -d "${plugin_dir}" ]; then
# Ensure this directory contains a info.json file
if [ -e "${plugin_dir}/info.json" ]; then
echo "PASS - Found info.json in plugin '${plugin_dir}'"
else
echo "FAIL - Missing info.json in plugin '${plugin_dir}'"
success=1
fi
fi
done
if [ ${success} -gt 0 ]; then
exit 1
fi
- name: Check LICENSE file in all plugin folders
if: success() || failure()
run: |
success=0
for plugin_dir in source/*; do
if [ -d "${plugin_dir}" ]; then
# Ensure this directory contains a LICENSE file
if [ -e "${plugin_dir}/LICENSE" ]; then
echo "PASS - Found LICENSE in plugin '${plugin_dir}'"
else
echo "FAIL - Missing LICENSE in plugin '${plugin_dir}'"
success=1
fi
fi
done
if [ ${success} -gt 0 ]; then
exit 1
fi
- name: Check plugin.py in all plugin folders
if: success() || failure()
run: |
success=0
for plugin_dir in source/*; do
if [ -d "${plugin_dir}" ]; then
# Ensure this directory contains a plugin.py file
if [ -e "${plugin_dir}/plugin.py" ]; then
echo "PASS - Found plugin.py in plugin '${plugin_dir}'"
else
echo "FAIL - Missing plugin.py in plugin '${plugin_dir}'"
success=1
fi
fi
done
if [ ${success} -gt 0 ]; then
exit 1
fi
- name: Check python source files contain the required SPDX identifier in header
if: success() || failure()
run: |
success=0
for plugin_dir in source/*; do
if [ -d "${plugin_dir}" ]; then
correct_header=0
# Ensure this directory contains a settings.json file
for python_file in $(find ${plugin_dir} -name '*.py' -not -path "${plugin_dir}/site-packages/*" -not -path "${plugin_dir}/dep/*"); do
if ! grep -q "Copyright:" "${python_file}"; then
echo "FAIL - Python file '${python_file}' Missing required SPDX identifier in header"
echo " See 'Standard License Header' here: https://spdx.org/licenses/GPL-3.0-only.html#licenseHeader"
correct_header=1
success=1
continue
fi
if ! grep -q "Copyright (C)" "${python_file}"; then
echo "FAIL - Python file '${python_file}' Missing required SPDX identifier in header"
echo " See 'Standard License Header' here: https://spdx.org/licenses/GPL-3.0-only.html#licenseHeader"
correct_header=1
success=1
continue
fi
if ! grep -q "This program is free software" "${python_file}"; then
echo "FAIL - Python file '${python_file}' Missing required SPDX identifier in header"
echo " See 'Standard License Header' here: https://spdx.org/licenses/GPL-3.0-only.html#licenseHeader"
correct_header=1
success=1
continue
fi
if ! grep -q "This program is distributed in the hop" "${python_file}"; then
echo "FAIL - Python file '${python_file}' Missing required SPDX identifier in header"
echo " See 'Standard License Header' here: https://spdx.org/licenses/GPL-3.0-only.html#licenseHeader"
correct_header=1
success=1
continue
fi
if ! grep -q "You should have received a copy of the GNU General Public License along with this program" "${python_file}"; then
echo "FAIL - Python file '${python_file}' Missing required SPDX identifier in header"
echo " See 'Standard License Header' here: https://spdx.org/licenses/GPL-3.0-only.html#licenseHeader"
correct_header=1
success=1
continue
fi
done
if [ ${correct_header} == 0 ]; then
echo "PASS - All python files in plugin '${plugin_dir}' contain the correct SPDX identifier in header"
fi
fi
done
if [ ${success} -gt 0 ]; then
exit 1
fi
# _____ __ __ _ _
# | ____|_ __ ___ _ _ _ __ ___ | \/ (_)___ ___(_)_ __ __ _
# | _| | '_ \/ __| | | | '__/ _ \ | |\/| | / __/ __| | '_ \ / _` |
# | |___| | | \__ \ |_| | | | __/ | | | | \__ \__ \ | | | | (_| |
# |_____|_| |_|___/\__,_|_| \___| |_| |_|_|___/___/_|_| |_|\__, |
# |___/
- name: Check site-packages in all plugin folders
if: success() || failure()
run: |
success=0
for plugin_dir in source/*; do
if [ -d "${plugin_dir}" ]; then
# Ensure this directory contains a site-packages file
if [ -e "${plugin_dir}/site-packages" ]; then
echo "FAIL - Directory 'site-packages' found in plugin '${plugin_dir}'"
success=1
else
echo "PASS - No 'site-packages' directory found in plugin '${plugin_dir}'"
fi
fi
done
if [ ${success} -gt 0 ]; then
exit 1
fi
- name: Check settings.json in all plugin folders
if: success() || failure()
run: |
success=0
for plugin_dir in source/*; do
if [ -d "${plugin_dir}" ]; then
# Ensure this directory contains a settings.json file
if [ -e "${plugin_dir}/settings.json" ]; then
echo "FAIL - Directory 'settings.json' found in plugin '${plugin_dir}'"
success=1
else
echo "PASS - No 'settings.json' directory found in plugin '${plugin_dir}'"
fi
fi
done
if [ ${success} -gt 0 ]; then
exit 1
fi
# Store success message in success file artifact
- name: Set success file on completion of tests
if: success()
run: echo 'true' > success_file.txt
- name: Upload success file
if: success()
uses: actions/upload-artifact@v3
with:
name: success_file
path: success_file.txt
# Build the plugin repository
deploy-plugin-repo:
needs: [plugins-contain-required-files]
runs-on: ubuntu-latest
name: Build the plugin repository
steps:
# Fetch and read sucess file
- name: Download success file from previous job
uses: actions/download-artifact@v3
with:
path: ./artifacts/
- name: Read success file
id: previous_jobs_success
run: |
IS_SUCCESS=$(cat ./artifacts/success_file/success_file.txt)
echo ::set-output name=IS_SUCCESS::${IS_SUCCESS}
rm -rfv ./artifacts
# Checkout
- name: Checkout
if: steps.previous_jobs_success.outputs.IS_SUCCESS == 'true'
uses: actions/checkout@v3
with:
submodules: recursive
# Ensure repo is checked out
- name: Check repo for config file
if: success()
id: ensure_repo
run: |
if [ ! -e ./config.json ]; then
echo "Unable to build repo. Was not checked out."
exit 1
fi
# Import scripts from template branch
- name: Pull in scripts from template branch
if: success()
id: read_template_tree
run: |
git fetch origin template
git read-tree --prefix=template -u origin/template
cp -rf ./template/scripts ./
git rm -r --cached template
if [ ! -e ./scripts/generate_repository.py ]; then
echo "Unable to build repo. Could not find generator script."
exit 1
fi
# Setup python environment
- name: Set up Python 3.8
if: success()
uses: actions/setup-python@v4
with:
python-version: 3.8
# Setup node environment
- name: Set up node 16
uses: actions/setup-node@v3
with:
node-version: '16'
# Generate repo
- name: Generate repository from source
if: success()
id: generate_repo
run: |
python ./scripts/generate_repository.py
# Deploy to repo branch
- name: Deploy repository
if: success() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/official')
uses: s0/git-publish-subdir-action@develop
env:
REPO: self
BRANCH: repo
FOLDER: repo
SQUASH_HISTORY: true
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}