forked from manna-harbour/miryoku_zmk
-
Notifications
You must be signed in to change notification settings - Fork 0
375 lines (349 loc) · 13.2 KB
/
main.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
# Copyright 2021 Manna Harbour
# https://github.com/manna-harbour/miryoku
name: 'Main'
on:
workflow_call:
inputs:
board:
type: string
default: '["default"]'
shield:
type: string
default: '["default"]'
alphas:
type: string
default: '["default"]'
extra:
type: string
default: '["default"]'
tap:
type: string
default: '["default"]'
nav:
type: string
default: '["default"]'
clipboard:
type: string
default: '["default"]'
layers:
type: string
default: '["default"]'
mapping:
type: string
default: '["default"]'
custom_config:
type: string
default: '["default"]'
kconfig:
type: string
default: '["default"]'
branches:
type: string
default: '["default"]'
modules:
type: string
default: '["default"]'
jobs:
main:
runs-on: ubuntu-latest
container:
image: zmkfirmware/zmk-build-arm:stable
strategy:
fail-fast: false
matrix:
board: ${{ fromJSON(inputs.board) }}
shield: ${{ fromJSON(inputs.shield) }}
alphas: ${{ fromJSON(inputs.alphas) }}
extra: ${{ fromJSON(inputs.extra) }}
tap: ${{ fromJSON(inputs.tap) }}
nav: ${{ fromJSON(inputs.nav) }}
clipboard: ${{ fromJSON(inputs.clipboard) }}
layers: ${{ fromJSON(inputs.layers) }}
mapping: ${{ fromJSON(inputs.mapping) }}
custom_config: ${{ fromJSON(inputs.custom_config) }}
kconfig: ${{ fromJSON(inputs.kconfig) }}
branches: ${{ fromJSON(inputs.branches) }}
modules: ${{ fromJSON(inputs.modules) }}
env:
MIRYOKU_DEBUG: ${{ secrets.MIRYOKU_DEBUG }}
steps:
- name: checkout
uses: actions/checkout@v4
with:
path: 'miryoku_zmk'
- name: main
id: main
run: |
test "$MIRYOKU_DEBUG" = 'MIRYOKU_DEBUG_TRUE' && set -x
echo "::group::variables"
if [ -n "${{ matrix.shield }}" -a "${{ matrix.shield }}" != "default" ]
then
SHIELD_ARG="-DSHIELD=\"${{ matrix.shield }}\""
shield=`echo ${{ matrix.shield }} | cut -d ' ' -f 1`
keyboard="$shield"
else
keyboard=${{ matrix.board }}
shield=""
fi
echo "shield_arg=$SHIELD_ARG" >> $GITHUB_OUTPUT
keyboard_split="$keyboard"
keyboard_base=`echo "$keyboard" | sed -e 's/_\(left\|right\)//' -e 's/@.*//'`
configfile="${GITHUB_WORKSPACE}/miryoku_zmk/miryoku/custom_config.h"
tmpfile="$configfile.tmp"
echo -n '#define ' > "$tmpfile"
echo -n "MIRYOKU_KEYBOARD_$keyboard_base" | tr -c '[:alnum:]' '_' | tr '[:lower:]' '[:upper:]' >> "$tmpfile"
echo >> "$tmpfile"
cat "$configfile" >> "$tmpfile"
mv "$tmpfile" "$configfile"
run_name="miryoku_zmk"
if [ -n "${{ matrix.shield }}" -a "${{ matrix.shield }}" != 'default' ]
then
run_name="$run_name ${{ matrix.shield }}"
fi
run_name="$run_name ${{ matrix.board }}"
hash_length=8
if [ -n "${{ matrix.custom_config }}" -a "${{ matrix.custom_config }}" != 'default' ]
then
echo "${{ matrix.custom_config }}" >> "$configfile"
run_name="$run_name config_"`echo "${{ matrix.custom_config }}" | md5sum | head -c "$hash_length"`
fi
for option in "alphas_${{ matrix.alphas }}" "extra_${{ matrix.extra }}" "tap_${{ matrix.tap }}" "nav_${{ matrix.nav }}" "clipboard_${{ matrix.clipboard }}" "layers_${{ matrix.layers }}" "mapping_${{ matrix.mapping }}"
do
case "$option" in
*_ ) ;;
*_default ) ;;
* )
run_name="$run_name $option"
echo "#define MIRYOKU_"`echo "$option" | tr 'a-z' 'A-Z'` >> "$configfile"
;;
esac
done
artifact_dir="${GITHUB_WORKSPACE}/artifacts"
echo "artifact_dir=$artifact_dir" >> $GITHUB_OUTPUT
mkdir "$artifact_dir"
test "$MIRYOKU_DEBUG" = 'MIRYOKU_DEBUG_TRUE' && cp "$configfile" "$artifact_dir"
if [ -n "${{ matrix.kconfig }}" -a "${{ matrix.kconfig }}" != 'default' ]
then
kconfig_file="${GITHUB_WORKSPACE}/miryoku_zmk/config/$keyboard_split.conf"
echo "${{ matrix.kconfig }}" >> "$kconfig_file"
test "$MIRYOKU_DEBUG" = 'MIRYOKU_DEBUG_TRUE' && cp "$kconfig_file" "$artifact_dir"
run_name="$run_name kconfig_"`echo "${{ matrix.kconfig }}" | md5sum | head -c "$hash_length"`
fi
if [ -n "${{ matrix.branches }}" -a "${{ matrix.branches }}" != 'default' ]
then
run_name="$run_name branches_"`echo "${{ matrix.branches }}" | md5sum | head -c "$hash_length"`
branches="${{ matrix.branches }}"
fi
if [ -n "${{ matrix.modules }}" -a "${{ matrix.modules }}" != 'default' ]
then
run_name="$run_name modules_"`echo "${{ matrix.modules }}" | md5sum | head -c "$hash_length"`
modules="${{ matrix.modules }}"
fi
run_name=`echo $run_name | tr ' ' '-'`
echo "run_name=$run_name" >> $GITHUB_OUTPUT
echo "::endgroup::"
echo "::group::matrix"
matrix_file="$artifact_dir/matrix.txt"
echo "
board: '${{ matrix.board }}'
shield: '${{ matrix.shield }}'
alphas: '${{ matrix.alphas }}'
extra: '${{ matrix.extra }}'
tap: '${{ matrix.tap }}'
nav: '${{ matrix.nav }}'
clipboard: '${{ matrix.clipboard }}'
layers: '${{ matrix.layers }}'
mapping: '${{ matrix.mapping }}'
custom_config: '${{ matrix.custom_config }}'
kconfig: '${{ matrix.kconfig }}'
branches: '${{ matrix.branches }}'
modules: '${{ matrix.modules }}'
" > "$matrix_file"
cat "$matrix_file"
echo "::endgroup::"
echo "::group::outboards"
if [ -n "$shield" ]
then
outboards="shields/$keyboard_base boards/${{ matrix.board }}"
else
outboards="boards/$keyboard_base"
fi
for outboard in $outboards
do
outboard_repository=''
outboard_ref=''
outboard_from=''
outboard_to=''
outboard_branches=''
outboard_modules=''
outboard_file="${GITHUB_WORKSPACE}/miryoku_zmk/.github/workflows/outboards/$outboard"
if [ -f "$outboard_file" ]
then
test "$MIRYOKU_DEBUG" = 'MIRYOKU_DEBUG_TRUE' && cp "$outboard_file" "$artifact_dir"
. "$outboard_file"
outboard_dir="${GITHUB_WORKSPACE}/$outboard"
if [ -n "$outboard_repository" -a -n "$outboard_ref" -a -n "$outboard_from" -a -n "$outboard_to" ]
then
if ! echo "$outboard_repository" | grep -q 'https:\/\/'
then
outboard_repository="https://github.com/$outboard_repository.git"
fi
git clone -b "$outboard_ref" --depth 1 "$outboard_repository" "$outboard_dir"
to="${GITHUB_WORKSPACE}/miryoku_zmk/config/$outboard_to"
mkdir -p `dirname "$to"`
ln -sr "$outboard_dir/$outboard_from" "$to"
fi
if [ -n "$outboard_branches" ]
then
if [ -n "$branches" ]
then
branches="$braches $outboard_branches"
else
branches="$outboard_branches"
fi
fi
if [ -n "$outboard_modules" ]
then
if [ -n "$modules" ]
then
modules="$modules $outboard_modules"
else
modules="$outboard_modules"
fi
fi
fi
done
echo "::endgroup::"
echo "::group::zmk"
zmk=`echo "$branches" | cut -d ' ' -f 1`
if [ -z "$zmk" ]
then
zmk='zmkfirmware/zmk/main'
fi
user=`echo "$zmk" | cut -f 1 -d '/'`
repo=`echo "$zmk" | cut -f 2 -d '/'`
branch=`echo "$zmk" | cut -f 3- -d '/'`
git clone -b "$branch" --depth 1 "https://github.com/$user/$repo.git" 'zmk'
echo "::endgroup::"
echo "::group::merge"
merges=`echo "$branches" | cut -d ' ' -f 2- -s`
if [ -n "$merges" ]
then
cd "${GITHUB_WORKSPACE}/zmk"
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git fetch --unshallow
for merge in $merges
do
user=`echo "$merge" | cut -f 1 -d '/'`
repo=`echo "$merge" | cut -f 2 -d '/'`
branch=`echo "$merge" | cut -f 3- -d '/'`
remote="$user-$repo"
git remote add "$remote" "https://github.com/$user/$repo.git"
git fetch "$remote" "$branch"
git merge "$remote/$branch"
git remote remove "$remote"
git status
done
fi
echo "::endgroup::"
echo "::group::modules"
for module in $modules
do
user=`echo "$module" | cut -f 1 -d '/'`
repo=`echo "$module" | cut -f 2 -d '/'`
branch=`echo "$module" | cut -f 3- -d '/'`
module_dir="${GITHUB_WORKSPACE}/modules/$user-$repo-"`echo "$branch" | tr '/' '_'`
if [ ! -d "$module_dir" ]
then
git clone -b "$branch" --depth 1 "https://github.com/$user/$repo.git" "$module_dir"
if [ -z "$module_dirs" ]
then
module_dirs="$module_dir;"
else
module_dirs="$module_dirs;$module_dir;"
fi
fi
done
if [ -n "$module_dirs" ]
then
modules_arg="-DZMK_EXTRA_MODULES=\"$module_dirs\""
echo "modules_arg=$modules_arg" >> $GITHUB_OUTPUT
fi
echo "::endgroup::"
- name: cache
if: true
uses: actions/cache@v4
with:
path: |
zmk/modules/
zmk/zephyr/
key: zephyr ${{ runner.os }} ${{ hashFiles('zmk/app/west.yml') }}
timeout-minutes: 2
continue-on-error: true
- name: build
run: |
if [ "$MIRYOKU_DEBUG" = 'MIRYOKU_DEBUG_TRUE' ]
then
set -x
#west_debug='-v'
#west_build_debug='-t rom_report -t ram_report'
fi
echo "::group::setup"
cd "${GITHUB_WORKSPACE}/zmk"
west $west_debug init -l app
west $west_debug update
west $west_debug zephyr-export
echo "::endgroup::"
echo "::group::build"
log='build.log'
build_failed_message='::error::Build failed with exit code'
EX_UNAVAILABLE='69'
EX_DATAERR='65'
cd "${GITHUB_WORKSPACE}/zmk/app"
{
west $west_debug build -b ${{ matrix.board }} $west_build_debug -- ${{ steps.main.outputs.shield_arg }} ${{ steps.main.outputs.modules_arg }} -DZMK_CONFIG="${GITHUB_WORKSPACE}/miryoku_zmk/config" ||
echo "$build_failed_message $?." ;
} 2>&1 | tee "$log"
if grep -q 'Invalid BOARD; see above.' "$log"
then
echo '::error::Board not found. Unsupported or incorrect board.'
(exit "$EX_UNAVAILABLE")
fi
if grep -q 'Failed to locate keymap file!' "$log"
then
echo '::error::Keymap not found. Unsupported or incorrect keyboard.'
(exit "$EX_UNAVAILABLE")
fi
if grep -q 'Invalid SHIELD' "$log"
then
echo '::error::Keymap found but shield not found. Board used for shield.'
(exit "$EX_DATAERR")
fi
if grep -q 'Using keymap file: .*/boards/' "$log" && ! grep -q 'Using keymap file: .*/settings_reset.keymap' "$log"
then
echo '::error::Miryoku keyboard keymap not found. Unsupported or incorrect keyboard.'
(exit "$EX_UNAVAILABLE")
fi
if grep -q "$build_failed_message" "$log"
then
false
fi
echo "::endgroup::"
echo "::group::copy"
for extension in 'uf2' 'bin' 'hex' 'elf'
do
file="${GITHUB_WORKSPACE}/zmk/app/build/zephyr/zmk.$extension"
if [ -f "$file" ]
then
cp "$file" "${{ steps.main.outputs.artifact_dir }}"
test "$MIRYOKU_DEBUG" = 'MIRYOKU_DEBUG_TRUE' || break
fi
done
test "$MIRYOKU_DEBUG" = 'MIRYOKU_DEBUG_TRUE' && cp "${GITHUB_WORKSPACE}/zmk/app/build/zephyr/.config" "${{ steps.main.outputs.artifact_dir }}"
echo "::endgroup::"
- name: upload
uses: actions/upload-artifact@v4
with:
name: ${{ steps.main.outputs.run_name }}
path: ${{ steps.main.outputs.artifact_dir }}