-
Notifications
You must be signed in to change notification settings - Fork 36
287 lines (253 loc) · 10.1 KB
/
user_config_build.yaml
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
name: Reusable user config build
on:
workflow_call:
inputs:
build_matrix_path:
description: "Path to the build matrix file"
default: "build.yaml"
required: false
type: string
config_path:
description: "Path to the config directory"
default: "config"
required: false
type: string
shield_path:
description: "Path to the shields directory"
default: "boards/shields/charybdis"
required: false
type: string
keymap_path:
description: "Path to the keymap directory"
default: "boards/shields/charybdis/keymaps"
required: false
type: string
fallback_binary:
description: "Fallback binary format, if no *.uf2 file was built"
default: "bin"
required: false
type: string
jobs:
matrix:
runs-on: ubuntu-latest
name: Fetch Build Keyboards
outputs:
build_matrix: ${{ env.build_matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install yaml2json
run: python3 -m pip install remarshal
- name: Fetch Build Matrix
run: |
echo "build_matrix=$(yaml2json '${{ inputs.build_matrix_path }}' | jq -c .)" >> $GITHUB_ENV
yaml2json "${{ inputs.build_matrix_path }}" | jq
build:
runs-on: ubuntu-latest
container:
image: zmkfirmware/zmk-build-arm:stable
needs: matrix
name: Build
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.matrix.outputs.build_matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create build directory
run: |
echo "build_dir=$(mktemp -d)" >> $GITHUB_ENV
- name: Prepare variables
shell: sh -x {0}
env:
board: ${{ matrix.board }}
shield: ${{ matrix.shield }}
keymap: ${{ matrix.keymap }}
format: ${{ matrix.format }}
artifact_name: ${{ matrix.artifact-name }}
snippet: ${{ matrix.snippet }}
run: |
if [ -e zephyr/module.yml ]; then
export zmk_load_arg=" -DZMK_EXTRA_MODULES='${GITHUB_WORKSPACE}'"
new_tmp_dir="${TMPDIR:-/tmp}/zmk-config"
mkdir -p "${new_tmp_dir}"
echo "base_dir=${new_tmp_dir}" >> $GITHUB_ENV
else
echo "base_dir=${GITHUB_WORKSPACE}" >> $GITHUB_ENV
fi
if [ -n "${snippet}" ]; then
extra_west_args="-S \"${snippet}\""
fi
echo "zephyr_version=${ZEPHYR_VERSION}" >> $GITHUB_ENV
echo "extra_west_args=${extra_west_args}" >> $GITHUB_ENV
echo "extra_cmake_args=${shield:+-DSHIELD=\"$shield\"}${zmk_load_arg}" >> $GITHUB_ENV
echo "display_name=${shield:+$shield - }${board}" >> $GITHUB_ENV
echo "format=${format}" >> $GITHUB_ENV
echo "keymap=${keymap}" >> $GITHUB_ENV
echo "shield=${shield}" >> $GITHUB_ENV
echo "artifact_name=${artifact_name:-${shield:+$shield-}${board}-zmk}" >> $GITHUB_ENV
- name: Download keymaps
uses: actions/download-artifact@v4
with:
name: keymap_files
path: "${{ github.workspace }}/"
- name: Copy keymaps to keymap directory
run: |
rm -f $GITHUB_WORKSPACE/config/*.keymap
mkdir -p "$GITHUB_WORKSPACE/${{ inputs.keymap_path }}/"
cd "$GITHUB_WORKSPACE"
mv charybdis.keymap qwerty.keymap
mv *.keymap "$GITHUB_WORKSPACE/${{ inputs.keymap_path }}/"
ls -lR "$GITHUB_WORKSPACE/${{ inputs.keymap_path }}/"
- name: Copy config files to isolated temporary directory
run: |
if [ "${{ env.base_dir }}" != "${GITHUB_WORKSPACE}" ]; then
apt-get -qq update && apt-get -q install -o Dpkg::Progress-Fancy="0" -o APT::Color="0" -o Dpkg::Use-Pty="0" tree
# Define base directory for config
base_config_path="${{ env.base_dir }}/${{ inputs.config_path }}"
# Create config directory
mkdir -p "$base_config_path"
# Copy config files
cp -R "${{ inputs.config_path }}"/* "$base_config_path/"
echo "config files ready"
# Copy keymap & physical layouts
if [ "${{ env.shield }}" != "settings_reset" ]; then
# Copy physical layout file to shield directory
mv -v "$base_config_path/charybdis-layouts.dtsi" \
"${GITHUB_WORKSPACE}/boards/shields/charybdis-${{ env.format }}/"
# Copy active keymap to the board directory & adjust for bt/dongle format
cp -Rv "$GITHUB_WORKSPACE/${{ inputs.keymap_path }}/${{ env.keymap }}.keymap" \
"$base_config_path/charybdis.keymap"
echo "format: ${{ env.format }}"
case "${{ env.format }}" in
*bt*)
echo "converting trackball device to bt/usb format"
sed -i 's/device = <&vtrackball>;/device = <\&trackball>;/g' "$base_config_path/charybdis.keymap"
grep "device = <" "$base_config_path/charybdis.keymap"
;;
esac
fi
fi
# Remove untargeted shields so they don't get auto picked up by the west build command
find "${GITHUB_WORKSPACE}/boards/shields" \
-mindepth 1 \
-maxdepth 1 \
! -name "charybdis-${{ env.format }}" \
-exec rm -rf {} +
echo "Removed extra shields"
echo "Build files list:"
tree "${{ env.base_dir }}"
tree "${GITHUB_WORKSPACE}/boards/shields"
- name: Cache west modules
uses: actions/cache@v4
continue-on-error: true
env:
cache_name: cache-zephyr-${{ env.zephyr_version }}-modules
with:
path: |
${{ env.base_dir }}/modules/
${{ env.base_dir }}/tools/
${{ env.base_dir }}/zephyr/
${{ env.base_dir }}/bootloader/
${{ env.base_dir }}/zmk/
key: ${{ runner.os }}-build-${{ env.cache_name }}-${{ hashFiles('**/west.yml', '**/build.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache_name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: West Init
working-directory: ${{ env.base_dir }}
run: west init -l "${{ env.base_dir }}/${{ inputs.config_path }}"
- name: West Update
working-directory: ${{ env.base_dir }}
run: west update
- name: West Zephyr export
working-directory: ${{ env.base_dir }}
run: west zephyr-export
- name: West Build (${{ env.display_name }})
working-directory: ${{ env.base_dir }}
shell: sh -x {0}
run: west build --pristine -s zmk/app -d "${{ env.build_dir }}" -b "${{ matrix.board }}" ${{ env.extra_west_args }} -- -DZMK_CONFIG=${{ env.base_dir }}/${{ inputs.config_path }} ${{ env.extra_cmake_args }} ${{ matrix.cmake-args }}
- name: ${{ env.display_name }} Kconfig file
run: |
if [ -f "${{ env.build_dir }}/zephyr/.config" ]
then
grep -v -e "^#" -e "^$" "${{ env.build_dir }}/zephyr/.config" | sort
else
echo "No Kconfig output"
fi
if: ${{ !cancelled() }}
- name: ${{ env.display_name }} Devicetree file
run: |
if [ -f "${{ env.build_dir }}/zephyr/zephyr.dts" ]
then
cat "${{ env.build_dir }}/zephyr/zephyr.dts"
elif [ -f "${{ env.build_dir }}/zephyr/zephyr.dts.pre" ]
then
cat -s "${{ env.build_dir }}/zephyr/zephyr.dts.pre"
else
echo "No Devicetree output"
fi
if: ${{ !cancelled() }}
- name: Rename artifacts
shell: sh -x {0}
run: |
mkdir "${{ env.build_dir }}/artifacts"
if [ -f "${{ env.build_dir }}/zephyr/zmk.uf2" ]
then
cp "${{ env.build_dir }}/zephyr/zmk.uf2" "${{ env.build_dir }}/artifacts/${{ env.artifact_name }}.uf2"
elif [ -f "${{ env.build_dir }}/zephyr/zmk.${{ inputs.fallback_binary }}" ]
then
cp "${{ env.build_dir }}/zephyr/zmk.${{ inputs.fallback_binary }}" "${{ env.build_dir }}/artifacts/${{ env.artifact_name }}.${{ inputs.fallback_binary }}"
fi
- name: Upload (${{ env.display_name }})
uses: actions/upload-artifact@v4
with:
name: artifact-${{ env.artifact_name }}
path: ${{ env.build_dir }}/artifacts
cleanup:
runs-on: ubuntu-latest
continue-on-error: true
needs: build
name: Merge & Prune Artifacts (optional)
steps:
- name: Upload Charybdis ZMK Firmware (QWERTY BT)
continue-on-error: true
uses: actions/upload-artifact/merge@v4
with:
pattern: artifact-charybdis_qwerty_{left,right}
name: firmware-charybdis-qwerty
delete-merged: true
- name: Upload Charybdis ZMK Firmware (QWERTY Dongle)
continue-on-error: true
uses: actions/upload-artifact/merge@v4
with:
pattern: artifact-charybdis_qwerty_dongle*
name: firmware-charybdis-qwerty-dongle
delete-merged: true
- name: Upload Charybdis ZMK Firmware (Colemak BT)
continue-on-error: true
uses: actions/upload-artifact/merge@v4
with:
pattern: artifact-charybdis_colemak_{left,right}
name: firmware-charybdis-colemak
delete-merged: true
- name: Upload Charybdis ZMK Firmware (Colemak Dongle)
continue-on-error: true
uses: actions/upload-artifact/merge@v4
with:
pattern: artifact-charybdis_colemak_dongle*
name: firmware-charybdis-colemak-dongle
delete-merged: true
- name: Upload Firmware Reset (Nano v2)
continue-on-error: true
uses: actions/upload-artifact/merge@v4
with:
pattern: artifact-firmware_reset_nano_v2
name: firmware-reset-nanov2
delete-merged: true
- name: Delete keymap artifacts
continue-on-error: true
uses: geekyeggo/delete-artifact@v5
with:
name: keymap_files