forked from AgiosAndreas/krikun98-zmk-config
-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (180 loc) · 6.68 KB
/
build.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
name: User config build with custom names
on:
push:
pull_request:
workflow_dispatch:
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
fallback_binary:
description: "Fallback binary format, if no *.uf2 file was built"
default: "bin"
required: false
type: string
archive_name:
description: 'Archive output file name'
default: 'zmk_firmware'
required: false
type: string
jobs:
env-setup:
runs-on: ubuntu-latest
name: Prepare environment variables
outputs:
build_matrix_path: ${{ env.build_matrix_path }}
config_path: ${{ env.config_path }}
fallback_binary: ${{ env.fallback_binary }}
archive_name: ${{ env.archive_name }}
steps:
- name: Export
run: |
if [[ "${{ github.event_name }}" == 'workflow_dispatch' ]]
then
echo "build_matrix_path=${{ inputs.build_matrix_path }}" >> $GITHUB_ENV
echo "config_path=${{ inputs.config_path }}" >> $GITHUB_ENV
echo "fallback_binary=${{ inputs.fallback_binary }}" >> $GITHUB_ENV
echo "archive_name=${{ inputs.archive_name }}" >> $GITHUB_ENV
else
echo "build_matrix_path=build.yaml" >> $GITHUB_ENV
echo "config_path=config" >> $GITHUB_ENV
echo "fallback_binary=bin" >> $GITHUB_ENV
echo "archive_name=zmk_firmware" >> $GITHUB_ENV
fi
matrix:
runs-on: ubuntu-latest
name: Fetch Build Keyboards
needs: env-setup
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: |
chmod +x json_unwrapper.py
echo "build_matrix=$(yaml2json ${{ needs.env-setup.outputs.build_matrix_path }} | ./json_unwrapper.py | jq -c .)" >> $GITHUB_ENV
yaml2json ${{ needs.env-setup.outputs.build_matrix_path }} | ./json_unwrapper.py | jq
build:
runs-on: ubuntu-latest
container:
image: zmkfirmware/zmk-build-arm:stable
needs: [matrix, env-setup]
name: Build
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.matrix.outputs.build_matrix) }}
steps:
- name: Prepare variables
shell: bash -x {0}
env:
file_name_suffix: ""
run: |
if [ -n "${{ matrix.shield }}" ]
then
echo "extra_cmake_args=-DSHIELD=\"${{ matrix.shield }}\"" >> $GITHUB_ENV
echo "artifact_name=${{ matrix.shield }}-${{ matrix.board }}${{ matrix.file_name_suffix }}-zmk" >> $GITHUB_ENV
echo "display_name=${{ matrix.shield }} - ${{ matrix.board }}${{ matrix.file_name_suffix }}" >> $GITHUB_ENV
else
echo "extra_cmake_args=" >> $GITHUB_ENV
echo "artifact_name=${{ matrix.board }}${{ matrix.file_name_suffix }}-zmk" >> $GITHUB_ENV
echo "display_name=${{ matrix.board }}${{ matrix.file_name_suffix }}" >> $GITHUB_ENV
fi
echo "zephyr_version=${ZEPHYR_VERSION}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
- name: Cache west modules
uses: actions/cache@v4
continue-on-error: true
env:
cache_name: cache-zephyr-${{ env.zephyr_version }}-modules
with:
path: |
modules/
tools/
zephyr/
bootloader/
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
run: west init -l ${{ needs.env-setup.outputs.config_path }}
- name: West Update
run: west update
- name: West Zephyr export
run: west zephyr-export
- name: Insert name into config
if: ${{ matrix.name }}
shell: bash -x {0}
run: |
non_primary_re="_right$"
if [[ ( -n "${{ matrix.shield }}" && "${{ matrix.shield }}" =~ $non_primary_re ) || "${{ matrix.board }}" =~ $non_primary_re ]]
then
echo "name=" >> $GITHUB_ENV
else
echo "name=-DCONFIG_ZMK_KEYBOARD_NAME=\\\"${{ matrix.name }}\\\"" >> $GITHUB_ENV
fi
- name: Insert flags into config
if: ${{ matrix.flags }}
shell: bash -x {0}
run: |
echo "flags=${{ matrix.flags }}" >> $GITHUB_ENV
- name: West Build (${{ env.display_name }})
shell: sh -x {0}
run: west build -s zmk/app -b ${{ matrix.board }} -- -DZMK_CONFIG=${GITHUB_WORKSPACE}/${{ needs.env-setup.outputs.config_path }} ${{ env.extra_cmake_args }} ${{ matrix.cmake-args }} ${{ env.name }} ${{env.flags}}
- name: Remove name from config
if: ${{ matrix.name }}
shell: bash -x {0}
run: |
echo "name=" >> $GITHUB_ENV
- name: Remove flags from config
if: ${{ matrix.flags }}
shell: bash -x {0}
run: |
echo "flags=" >> $GITHUB_ENV
- name: ${{ env.display_name }} Kconfig file
run: grep -v -e "^#" -e "^$" build/zephyr/.config | sort
- name: Rename artifacts
shell: sh -x {0}
run: |
mkdir build/artifacts
if [ -f build/zephyr/zmk.uf2 ]
then
cp build/zephyr/zmk.uf2 "build/artifacts/${{ env.artifact_name }}.uf2"
elif [ -f build/zephyr/zmk.${{ needs.env-setup.outputs.fallback_binary }} ]
then
cp build/zephyr/zmk.${{ needs.env-setup.outputs.fallback_binary }} "build/artifacts/${{ env.artifact_name }}.${{ needs.env-setup.outputs.fallback_binary }}"
fi
# - name: Archive (${{ env.display_name }})
# uses: actions/upload-artifact@v3
# with:
# name: ${{ needs.env-setup.outputs.archive_name }}
# path: build/artifacts
- name: Archive (${{ env.display_name }})
uses: actions/upload-artifact@v4
with:
name: artifact-${{ env.artifact_name }}
path: ${{ env.build_dir }}/artifacts
merge:
runs-on: ubuntu-latest
needs: build
name: Merge Output Artifacts
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: ${{ inputs.archive_name }}
pattern: artifact-*
delete-merged: true