-
Notifications
You must be signed in to change notification settings - Fork 111
386 lines (325 loc) · 14.1 KB
/
build-plugins.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
name: Build Plugins
on:
push:
branches:
- main
- backend-builder
- use-cli
paths:
- "plugins/**"
- ".github/workflows/build-plugins.yml"
pull_request_target:
branches: ['*']
workflow_dispatch:
inputs:
plugin_override:
description: Whitespace-separated list of plugin names to be built and uploaded. Enter "#all" to build and upload all plugins. Leave blank to use the default behavior.
type: string
required: false
force_revision:
type: boolean
description: Force a revision for for a plugin upload (used to fix issues caused by CI.)
force_pnpm:
type: choice
description: Forces an update to pnpm lockfile version and or Decky Frontend Library. This is only to be used in "oh shit" situations. Otherwise defer to the plugin developer so that they can submit a fix/update.
default: 'none'
options:
- none
- pnpm
- dfl
- pnpm-dfl
test_build:
type: boolean
description: Build pre-selected list of plugins for testing. They will not be uploaded.
env:
revision_force: ${{ inputs.force_revision }}
pnpm_force: ${{ inputs.force_pnpm }}
testing: ${{ inputs.test_build }}
testing_plugins: "Bluetooth ControllerTools SDH-AudioLoader SDH-CssLoader moondeck memory-deck Fantastic"
jobs:
find:
name: Find plugins to be built
runs-on: ubuntu-latest
outputs:
plugins: ${{ steps.generate-matrix.outputs.plugins }}
steps:
- name: Checkout
if: ${{ !env.ACT }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0
submodules: "recursive"
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get changed files
id: changed-files
env:
isPr: ${{ github.event_name == 'pull_request_target' }}
pluginOverride: ${{ inputs.plugin_override }}
run: |
# Returns a list of paths relative to the git repository of the files that changed
# In pull requests, it diffs files between the last commit in the pull request and main
# In push events, it diffs between the current commit and the previous
# Paths to be included in the diff
PATHS=(plugins)
# Find refs to be diffed
if [[ $isPr == "true" ]]; then
# Fetch all remotes so we can properly diff
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
# Diff with the ref of the target branch
REF=${{ github.event.pull_request.base.sha }}
else
# Diff with previous commit
REF=HEAD^
fi
ALL_PLUGINS=$(find ${PATHS[@]} -mindepth 1 -maxdepth 1 | xargs -r -L1 basename)
CHANGED_PLUGINS=$(git diff ${REF[@]} --name-only --submodule=diff -- ${PATHS[@]} | xargs -r -L1 basename)
PLUGINS_PENDING_BUILD=$CHANGED_PLUGINS
PLUGINS_PENDING_UPLOAD=$CHANGED_PLUGINS
WORKFLOW_CHANGED=$(git diff ${REF[@]} --name-only -- .github/workflows/build-plugins.yml)
if [[ $WORKFLOW_CHANGED ]]; then
echo "::notice::Workflow was changed. Setting all plugins as pending build."
PLUGINS_PENDING_BUILD=$ALL_PLUGINS
fi
if [[ "${{ env.testing }}" == "true" ]]; then
echo "::notice::Testing is enabled, using limited plugin set for build testing."
PLUGINS_PENDING_BUILD=(${{ env.testing_plugins }})
PLUGINS_PENDING_BUILD=$(IFS=$'\n'; echo "${PLUGINS_PENDING_BUILD[*]}")
PLUGINS_PENDING_UPLOAD=""
fi
if [[ $pluginOverride ]]; then
echo "::notice::Plugin override is set. Disregard previous notices. Building $pluginOverride"
plugins=$(tr " " "\n" <<< "$pluginOverride")
PLUGINS_PENDING_BUILD=$plugins
PLUGINS_PENDING_UPLOAD=$plugins
fi
if [[ $pluginOverride == "#all" ]]; then
echo "::notice::Workflow run set to upload all. Setting all plugins as pending build and upload."
PLUGINS_PENDING_BUILD=$ALL_PLUGINS
PLUGINS_PENDING_UPLOAD=$ALL_PLUGINS
fi
echo "all_changed_plugins<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGED_PLUGINS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "plugins_pending_build<<EOF" >> $GITHUB_OUTPUT
echo "$PLUGINS_PENDING_BUILD" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "plugins_pending_upload<<EOF" >> $GITHUB_OUTPUT
echo "$PLUGINS_PENDING_UPLOAD" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Generate plugin matrix
id: generate-matrix
run: |
PLUGINS_PENDING_BUILD=(${{ steps.changed-files.outputs.plugins_pending_build }})
PLUGINS_PENDING_UPLOAD=(${{ steps.changed-files.outputs.plugins_pending_upload }})
# Outputs an array of plugins to be built, specifying if they should be uploaded or not
# [{ "name": "Bluetooth", "upload": false }, { "name": "PowerTools", "upload": "true" }]
PLUGINS=$(
jq --null-input \
--join-output \
--compact-output \
--arg build "${PLUGINS_PENDING_BUILD[*]}" \
--arg upload "${PLUGINS_PENDING_UPLOAD[*]}" \
'($upload | split(" ")) as $upload | $build | split(" ") | map(. as $plugin | { name: $plugin, upload: ($upload | any(contains($plugin))) })'
)
echo "plugins=$PLUGINS" >> $GITHUB_OUTPUT
- name: Generate job summary
id: generate-summary
run: |
PLUGINS_PENDING_BUILD=(${{ steps.changed-files.outputs.plugins_pending_build }})
PLUGINS_PENDING_UPLOAD=(${{ steps.changed-files.outputs.plugins_pending_upload }})
echo "| Plugin | Build | Upload |" >> "$GITHUB_STEP_SUMMARY"
echo "| ------ | ----- | ------ |" >> "$GITHUB_STEP_SUMMARY"
yes="✔️"
no="🚫"
for plugin in "${PLUGINS_PENDING_BUILD[@]}"; do
# Find whether plugin needs to be uploaded
upload="$no"
for uploadPlugin in "${PLUGINS_PENDING_UPLOAD[@]}"; do
if [[ "$uploadPlugin" == "$plugin" ]]; then
upload=1
break
fi
done
if [[ "$upload" == 1 ]]; then
upload="$yes"
fi
echo "| $plugin | $yes | $upload |" >> "$GITHUB_STEP_SUMMARY"
done
# ------------------------------------------------------------------
build:
name: Build plugin
runs-on: ubuntu-latest
environment:
name: ${{ (github.ref == 'refs/heads/main' && (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.plugin_override))) && 'env' || 'testing_env' }}
needs:
- find
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.find.outputs.plugins) }}
env:
plugin: ${{ matrix.name }}
steps:
- name: Checkout
if: ${{ !env.ACT }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout relevant plugin submodule
run: |
# Default to HTTPS always
git config --global url."https://github.com/".insteadOf [email protected]:
git config --global url."https://".insteadOf git://
git submodule update --recursive --init -- plugins/$plugin
- name: Append hash to plugin version
if: ${{ github.event_name == 'pull_request_target' }}
run: |
echo "::notice::This run was triggered by a pull request. Appending the commit hash to the plugin version."
echo "::group::Appending hash to plugin $plugin"
PACKAGE_FILE="plugins/$plugin/package.json"
SHA=$(cut -c1-7 <<< "${{ github.event.pull_request.head.sha || github.sha }}")
VERSION=$(jq -r '.version' $PACKAGE_FILE)
NEW_VERSION="$VERSION-$SHA"
echo "::notice::Going from $VERSION to $NEW_VERSION"
tmp=$(mktemp)
jq --arg newversion "$NEW_VERSION" '.version = $newversion' $PACKAGE_FILE > $tmp
mv $tmp $PACKAGE_FILE
echo "::endgroup::"
- name: Append revision to force update
if: ${{ env.revision_force == 'true' }}
run: |
echo "::notice::This run was manually to force an appended revision. Appending a revision to the plugin version."
echo "::group::Appending revision to plugin $plugin"
PACKAGE_FILE="plugins/$plugin/package.json"
VERSION=$(jq -r '.version' $PACKAGE_FILE)
echo "Version: $VERSION"
VERSION_WO_REVISION=$(echo $VERSION | sed -e 's|-[^-]*$||')
echo "Version without revisions: $VERSION"
PREV_REVISION=$(echo $VERSION | sed -e 's|[0-9][0-9.]*[0-9]-||')
echo "Current revision: $PREV_REVISION"
if [[ "$PREV_REVISION" =~ "-" ]]; then
IS_REVISED=true
echo "Is revised"
else
IS_REVISED=false
echo "Is not revised"
fi
if [[ "$IS_REVISED" == "false" ]]; then
echo "Plugin is not revised, setting to revision 1."
REVISION="1"
echo "Revision: $REVISION"
NEW_VERSION="$VERSION-$REVISION"
else
REVISION=$(($PREV_REVISION + 1))
echo "Revision: $REVISION"
NEW_VERSION="$VERSION_WO_REVISION-$REVISION"
fi
echo "New version: $NEW_VERISION"
echo "::notice::Going from $VERSION to $NEW_VERSION"
tmp=$(mktemp)
jq --arg newversion "$NEW_VERSION" '.version = $newversion' $PACKAGE_FILE > $tmp
mv $tmp $PACKAGE_FILE
echo "::endgroup::"
- uses: pnpm/action-setup@v3
with:
version: 9.4.0
- name: Force update pnpm lockfile and/or DFL
if: ${{ inputs.force_pnpm != 'none' }}
run: |
if [[ "${{ env.pnpm_force }}" == "pnpm" ]]; then
$(which pnpm) -C plugins/$plugin install --lockfile-only
elif [[ "${{ env.pnpm_force }}" == "dfl" ]]; then
$(which pnpm) -C plugins/$plugin update --latest decky-frontend-lib
elif [[ "${{ env.pnpm_force }}" == "pnpm-dfl" ]]; then
$(which pnpm) -C plugins/$plugin install --lockfile-only
$(which pnpm) -C plugins/$plugin update --latest decky-frontend-lib
fi
- name: Download Decky CLI
run: |
mkdir /tmp/decky-cli
curl -L -o /tmp/decky-cli/decky "https://github.com/SteamDeckHomebrew/cli/releases/download/0.0.2/decky-linux-x86_64"
chmod +x /tmp/decky-cli/decky
echo "/tmp/decky-cli" >> $GITHUB_PATH
- name: Build plugins
run: |
echo "::group::Building plugin $plugin"
# Run the CLI as root to get around Docker's weird permissions
sudo $(which decky) plugin build -b -o /tmp/output -s directory plugins/$plugin
sudo chown -R $(whoami) plugins/$plugin
echo "::endgroup::"
- name: Upload Artifacts to Github
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: /tmp/output/*.zip
- name: Upload plugins to store
id: upload-plugins
env:
SUBMIT_AUTH_KEY: ${{ secrets.SUBMIT_AUTH_KEY }}
STORE_URL: ${{ secrets.STORE_URL }}
upload: ${{ matrix.upload }}
if: ${{ matrix.upload == true && inputs.test_build != true && env.SUBMIT_AUTH_KEY != '' }}
run: |
shopt -s dotglob
echo "::group::Processing plugin $plugin"
artifact=/tmp/output/$plugin.zip
if [[ -z $artifact ]]; then
echo "::error::Could not find artifact for $plugin in $artifact"
continue
fi
query_package_json () {
local result=$(unzip -p $artifact $plugin/package.json | jq -r "$1")
echo $result
}
query_plugin_json () {
local result=$(unzip -p $artifact $plugin/plugin.json | jq -r "$1")
echo $result
}
PLUGIN_NAME=$(query_plugin_json '.name')
PLUGIN_AUTHOR=$(query_plugin_json '.author')
PLUGIN_DESCRIPTION=$(query_plugin_json '.publish.description')
PLUGIN_VERSION=$(query_package_json '.version')
PLUGIN_IMAGE=$(query_plugin_json '.publish.image')
PLUGIN_TAGS=$(query_plugin_json '.publish.tags|join(",")')
echo "::notice::Processing plugin $PLUGIN_NAME v$PLUGIN_VERSION (by $PLUGIN_AUTHOR)"
upload_plugin () {
curl -X POST \
-H "Authorization: ${SUBMIT_AUTH_KEY}" \
-F "name=$PLUGIN_NAME" \
-F "author=$PLUGIN_AUTHOR" \
-F "description=$PLUGIN_DESCRIPTION" \
-F "tags=$PLUGIN_TAGS" \
-F "version_name=$PLUGIN_VERSION" \
-F "image=$PLUGIN_IMAGE" \
-F "file=@$artifact" ${STORE_URL}/__submit
}
shouldUpload=$(query_plugin_json '.publish | any(.tags[] == "dnu"; .) | not')
if [[ "$shouldUpload" == "true" ]]; then
echo "::notice::Uploading"
upload_response=$(upload_plugin)
if [[ "$upload_response" =~ "Version already exists" ]]; then
echo "::warning title=Could not upload $plugin::Version of plugin being pushed already exists, moving to next plugin."
elif [[ "$upload_response" =~ "INVALID AUTH KEY" ]]; then
echo "::error::Authentication Key used is invalid, exiting."
exit 1
elif [[ "$upload_response" =~ "invalid or missing URL scheme" ]]; then
echo "::error::url format in plugin.json is broken, please investigate."
if [[ "$upload_response" =~ "image" ]]; then
echo "::error::Submitted screenshot URL does not exist or is broken."
exit 1
else
echo "::error::Unknown URL is broken, please see output below"
echo "::error::$upload_response"
exit 1
fi
exit 1
else
echo "::notice::$upload_response"
fi
else
echo "::warning::Plugin $PLUGIN_NAME is marked as 'do not upload'. Consider removing the 'dnu' tag if this is an accident."
fi
echo "::endgroup::"