1
+ name : Reusable user config build
2
+
3
+ on :
4
+ workflow_call :
5
+ inputs :
6
+ build_matrix_path :
7
+ description : " Path to the build matrix file"
8
+ default : " build.yaml"
9
+ required : false
10
+ type : string
11
+ config_path :
12
+ description : " Path to the config directory"
13
+ default : " config"
14
+ required : false
15
+ type : string
16
+ fallback_binary :
17
+ description : " Fallback binary format, if no *.uf2 file was built"
18
+ default : " bin"
19
+ required : false
20
+ type : string
21
+ archive_name :
22
+ description : " Archive output file name"
23
+ default : " firmware"
24
+ required : false
25
+ type : string
26
+
27
+ jobs :
28
+ matrix :
29
+ runs-on : ubuntu-22.04
30
+ name : Fetch Build Keyboards
31
+ outputs :
32
+ build_matrix : ${{ env.build_matrix }}
33
+ steps :
34
+ - name : Checkout
35
+ uses : actions/checkout@v4
36
+
37
+ - name : Install yaml2json
38
+ run : python3 -m pip install remarshal
39
+
40
+ - name : Fetch Build Matrix
41
+ run : |
42
+ echo "build_matrix=$(yaml2json '${{ inputs.build_matrix_path }}' | jq -c .)" >> $GITHUB_ENV
43
+ yaml2json "${{ inputs.build_matrix_path }}" | jq
44
+
45
+ build :
46
+ runs-on : ubuntu-latest
47
+ container :
48
+ image : zmkfirmware/zmk-build-arm:stable
49
+ needs : matrix
50
+ name : Build
51
+ strategy :
52
+ fail-fast : false
53
+ matrix : ${{ fromJson(needs.matrix.outputs.build_matrix) }}
54
+ steps :
55
+ - name : Checkout
56
+ uses : actions/checkout@v4
57
+
58
+ - name : Create build directory
59
+ run : |
60
+ echo "build_dir=$(mktemp -d)" >> $GITHUB_ENV
61
+
62
+ - name : Prepare variables
63
+ shell : sh -x {0}
64
+ env :
65
+ board : ${{ matrix.board }}
66
+ shield : ${{ matrix.shield }}
67
+ artifact_name : ${{ matrix.artifact-name }}
68
+ snippet : ${{ matrix.snippet }}
69
+ run : |
70
+ if [ -e zephyr/module.yml ]; then
71
+ export zmk_load_arg=" -DZMK_EXTRA_MODULES='${GITHUB_WORKSPACE}'"
72
+ new_tmp_dir="${TMPDIR:-/tmp}/zmk-config"
73
+ mkdir -p "${new_tmp_dir}"
74
+ echo "base_dir=${new_tmp_dir}" >> $GITHUB_ENV
75
+ else
76
+ echo "base_dir=${GITHUB_WORKSPACE}" >> $GITHUB_ENV
77
+ fi
78
+
79
+ if [ -n "${snippet}" ]; then
80
+ extra_west_args="-S \"${snippet}\""
81
+ fi
82
+
83
+ echo "zephyr_version=${ZEPHYR_VERSION}" >> $GITHUB_ENV
84
+ echo "extra_west_args=${extra_west_args}" >> $GITHUB_ENV
85
+ echo "extra_cmake_args=${shield:+-DSHIELD=\"$shield\"}${zmk_load_arg}" >> $GITHUB_ENV
86
+ echo "display_name=${shield:+$shield - }${board}" >> $GITHUB_ENV
87
+ echo "artifact_name=${artifact_name:-${shield:+$shield-}${board}-zmk}" >> $GITHUB_ENV
88
+
89
+ - name : Copy config files to isolated temporary directory
90
+ run : |
91
+ if [ "${{ env.base_dir }}" != "${GITHUB_WORKSPACE}" ]; then
92
+ mkdir -p "${{ env.base_dir }}/${{ inputs.config_path }}"
93
+ cp -R ${{ inputs.config_path }}/* "${{ env.base_dir }}/${{ inputs.config_path }}/"
94
+ fi
95
+
96
+ - name : Cache west modules
97
+ uses : actions/cache@v4
98
+ continue-on-error : true
99
+ env :
100
+ cache_name : cache-zephyr-${{ env.zephyr_version }}-modules
101
+ with :
102
+ path : |
103
+ ${{ env.base_dir }}/modules/
104
+ ${{ env.base_dir }}/tools/
105
+ ${{ env.base_dir }}/zephyr/
106
+ ${{ env.base_dir }}/bootloader/
107
+ ${{ env.base_dir }}/zmk/
108
+ key : ${{ runner.os }}-build-${{ env.cache_name }}-${{ hashFiles('**/west.yml', '**/build.yaml') }}
109
+ restore-keys : |
110
+ ${{ runner.os }}-build-${{ env.cache_name }}-
111
+ ${{ runner.os }}-build-
112
+ ${{ runner.os }}-
113
+
114
+ - name : West Init
115
+ working-directory : ${{ env.base_dir }}
116
+ run : west init -l "${{ env.base_dir }}/${{ inputs.config_path }}"
117
+
118
+ - name : West Update
119
+ working-directory : ${{ env.base_dir }}
120
+ run : west update
121
+
122
+ - name : West Zephyr export
123
+ working-directory : ${{ env.base_dir }}
124
+ run : west zephyr-export
125
+
126
+ - name : West Build (${{ env.display_name }})
127
+ working-directory : ${{ env.base_dir }}
128
+ shell : sh -x {0}
129
+ run : west build -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 }}
130
+
131
+ - name : ${{ env.display_name }} Kconfig file
132
+ run : |
133
+ if [ -f "${{ env.build_dir }}/zephyr/.config" ]
134
+ then
135
+ grep -v -e "^#" -e "^$" "${{ env.build_dir }}/zephyr/.config" | sort
136
+ else
137
+ echo "No Kconfig output"
138
+ fi
139
+ if : ${{ !cancelled() }}
140
+
141
+ - name : ${{ env.display_name }} Devicetree file
142
+ run : |
143
+ if [ -f "${{ env.build_dir }}/zephyr/zephyr.dts" ]
144
+ then
145
+ cat "${{ env.build_dir }}/zephyr/zephyr.dts"
146
+ elif [ -f "${{ env.build_dir }}/zephyr/zephyr.dts.pre" ]
147
+ then
148
+ cat -s "${{ env.build_dir }}/zephyr/zephyr.dts.pre"
149
+ else
150
+ echo "No Devicetree output"
151
+ fi
152
+ if : ${{ !cancelled() }}
153
+
154
+ - name : Rename artifacts
155
+ shell : sh -x {0}
156
+ run : |
157
+ mkdir "${{ env.build_dir }}/artifacts"
158
+ if [ -f "${{ env.build_dir }}/zephyr/zmk.uf2" ]
159
+ then
160
+ cp "${{ env.build_dir }}/zephyr/zmk.uf2" "${{ env.build_dir }}/artifacts/${{ env.artifact_name }}.uf2"
161
+ elif [ -f "${{ env.build_dir }}/zephyr/zmk.${{ inputs.fallback_binary }}" ]
162
+ then
163
+ cp "${{ env.build_dir }}/zephyr/zmk.${{ inputs.fallback_binary }}" "${{ env.build_dir }}/artifacts/${{ env.artifact_name }}.${{ inputs.fallback_binary }}"
164
+ fi
165
+
166
+ - name : Archive (${{ env.display_name }})
167
+ uses : actions/upload-artifact@v4
168
+ with :
169
+ name : artifact-${{ env.artifact_name }}
170
+ path : ${{ env.build_dir }}/artifacts
171
+
172
+ merge :
173
+ runs-on : ubuntu-latest
174
+ needs : build
175
+ name : Merge Output Artifacts
176
+ steps :
177
+ - name : Merge Artifacts
178
+ uses : actions/upload-artifact/merge@v4
179
+ with :
180
+ name : ${{ inputs.archive_name }}
181
+ pattern : artifact-*
182
+ delete-merged : true
0 commit comments