forked from jomjol/AI-on-the-edge-device
-
Notifications
You must be signed in to change notification settings - Fork 0
283 lines (243 loc) · 10.9 KB
/
build-release.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
name: Build and Release
on:
push:
pull_request:
jobs:
#########################################################################################
## Create release - PART 1: Prepare Release PR / Create release tag
#
# Use of release-please action to create a 'Release PR' which gets maintained automatically.
# After merging the 'Release PR', a new tag and release is getting created.
#########################################################################################
prepare-release:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
upload_url: ${{ steps.release.outputs.upload_url }}
version: "${{steps.release.outputs.major}}.${{steps.release.outputs.minor}}.${{steps.release.outputs.patch}}"
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- uses: googleapis/release-please-action@v4
id: release
with:
target-branch: develop
config-file: .release-please-config.json
manifest-file: .release-please-manifest.json
#########################################################################################
## Build Firmware
#
# Build firmware and create artifact packages
#########################################################################################
build:
runs-on: ubuntu-latest
needs: [prepare-release]
strategy:
fail-fast: false
matrix:
plat:
- esp32cam
- xiao-esp32s3-sense
steps:
- name: Checkout branch
if: ${{ ! needs.prepare-release.outputs.release_created }}
uses: actions/checkout@v4
with:
submodules: recursive
- name: Checkout tag # checkout tagged version when build a release for this tag
if: ${{ needs.prepare-release.outputs.release_created }}
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare-release.outputs.tag_name }}
submodules: recursive
- name: Set variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
- name: Cache pip & platformIO cache files
uses: actions/cache@v4
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: platformio-${{ github.run_id }}
restore-keys: platformio # This matches above key as it is only used as a prefix. It restores the nearest cache
- name: Cache PIO build files
if: ${{ ! needs.prepare-release.outputs.release_created }} # do not use cached data when building a release
uses: actions/cache@v4
with:
path: ./code/.pio
key: build-${{ matrix.plat }}-${{ github.run_id }}
restore-keys: build-${{ matrix.plat }} # This matches above key as it is only used as a prefix. It restores the nearest cache
- name: Setup python environment
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install PlatformIO environment
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Build firmware
run: cd code; platformio run -e ${{ matrix.plat }}
- name: Prepare WebUI (Generate parameter tooltips, API docs and update hash)
run: |
python -m pip install markdown
python ./tools/parameter-tooltip-generator/generate-param-doc-tooltips.py
python ./tools/docs-generator/generate-api-docs.py
rm -rf ./html
mkdir ./html
cp -r ./sd-card/html/* ./html/
echo "Update hash..."
cd ./html; find . -type f -exec sed -i 's/$COMMIT_HASH/${{ steps.vars.outputs.sha_short }}/g' {} \;
#########################################################################################
## Create firmware package
# - Inital flashing using web installer, device's access point or serial console
# - OTA update using WebUI
#
# Package contents:
# - Firmware binaries (firmware.bin, partitions.bin, bootloader.bin)
# - WebUI Files (/html/* (inkl. subfolders))
# - Config Files (/config/templates/*, /config/models/*.tflite)
#########################################################################################
- name: Firmware package - Prepare artifact
run: |
rm -rf ./artifact
mkdir -p ./artifact
cp -f "./code/.pio/build/${{ matrix.plat }}/firmware.bin" "./artifact/firmware.bin"
cp -f "./code/.pio/build/${{ matrix.plat }}/bootloader.bin" "./artifact/bootloader.bin"
cp -f "./code/.pio/build/${{ matrix.plat }}/partitions.bin" "./artifact/partitions.bin"
cp -f "./docs/Installation/DeviceReadme/${{ matrix.plat }}.md" "./artifact/README.md"
cp -r ./html ./artifact/
rm -rf ./artifact/config/
mkdir -p ./artifact/config
mkdir -p ./artifact/config/templates
mkdir -p ./artifact/config/models
cp ./sd-card/config/templates/* ./artifact/config/templates/ 2>/dev/null || true
cp ./sd-card/config/models/*.tfl ./artifact/config/models/ 2>/dev/null || true
cp ./sd-card/config/models/*.tflite ./artifact/config/models/ 2>/dev/null || true
- name: Firmware package - Upload artifact
uses: actions/upload-artifact@v4
with:
name: "AI-on-the-edge-device__${{ matrix.plat }}__SLFork_${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}"
path: ./artifact
#########################################################################################
## Create package with additional files for debugging purpose
#
# Package contents:
# - firmware.elf
# - sdkconfig.${{ matrix.plat }}
#########################################################################################
- name: Debug files package - Prepare artifact
run: |
rm -rf ./debug
mkdir -p ./debug
cp -f "./code/.pio/build/${{ matrix.plat }}/firmware.elf" "debug/firmware.elf"
cp -f "./code/sdkconfig.${{ matrix.plat }}" "debug/sdkconfig.${{ matrix.plat }}"
- name: Debug files package - Upload artifact
uses: actions/upload-artifact@v4
with:
name: "AI-on-the-edge-device__${{ matrix.plat }}__debug-files__SLFork_${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}"
path: ./debug
#########################################################################################
## Create release - PART 2: Upload release related artifacts
#
# Artifacts will gets uploaded to newly created release tag.
#########################################################################################
upload-release-artifacts:
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.vars.outputs.branch }}
sha_short: ${{ steps.vars.outputs.sha_short }}
needs: [prepare-release, build]
if: ${{ needs.prepare-release.outputs.release_created }}
strategy:
fail-fast: false
matrix:
plat:
- esp32cam
- xiao-esp32s3-sense
# Sets permissions of the GITHUB_TOKEN to allow downloading artifacts
permissions:
actions: read
contents: write
steps:
- name: Checkout tag
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare-release.outputs.tag_name }}
- name: Set variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
- name: Pull artifacts
uses: actions/download-artifact@v4
- name: Prepare artifacts for release
run: |
rm -rf release
mkdir -p release
cd "AI-on-the-edge-device__${{ matrix.plat }}__SLFork_${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}"
zip -r ../release/AI-on-the-edge-device__${{ matrix.plat }}__SLFork_v${{ needs.prepare-release.outputs.version }}.zip *
cd ..
cd "AI-on-the-edge-device__${{ matrix.plat }}__debug-files__SLFork_${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}"
zip -r ../release/AI-on-the-edge-device__${{ matrix.plat }}__debug-files__SLFork_v${{ needs.prepare-release.outputs.version }}.zip *
cd ..
- name: Upload artifacts to release tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run:
gh release upload ${{ needs.prepare-release.outputs.tag_name }} release/*
#########################################################################################
## Update web installer (branch: gh-pages-webinstaller)
#
# Firmware files are commited to branch gh-pages-webinstaller
#########################################################################################
update-webinstaller:
runs-on: ubuntu-latest
needs: [prepare-release, build, upload-release-artifacts]
if: ${{ needs.prepare-release.outputs.release_created }}
strategy:
max-parallel: 1
fail-fast: false
matrix:
plat:
- esp32cam
- xiao-esp32s3-sense
# Sets permissions of the GITHUB_TOKEN to allow downloading artifacts
permissions:
actions: read
contents: write
steps:
- name: Checkout branch gh-pages-webinstaller
uses: actions/checkout@v4
with:
ref: gh-pages-webinstaller
- name: Pull artifact
uses: actions/download-artifact@v4
with:
name: "AI-on-the-edge-device__${{ matrix.plat }}__SLFork_${{ needs.upload-release-artifacts.outputs.branch }}_${{ needs.upload-release-artifacts.outputs.sha_short }}"
path: './artifacts/'
- name: Prepare data
run: |
echo "Updating files ..."
cd ./artifacts
ls
cd ..
cp -f ./artifacts/bootloader.bin ./firmware/${{ matrix.plat }}/bootloader.bin
cp -f ./artifacts/partitions.bin ./firmware/${{ matrix.plat }}/partitions.bin
cp -f ./artifacts/firmware.bin ./firmware/${{ matrix.plat }}/firmware.bin
echo "Updating version strings (index.html, manifest) ..."
sed -i -E 's/Firmware: .*./\Firmware: <b\>${{ needs.prepare-release.outputs.tag_name }}\<\/b\>/g' index.html
sed -i -E 's/"version":.*.,/"version": "${{ needs.prepare-release.outputs.tag_name }}",/g' manifest_${{ matrix.plat }}.json
- name: Commit data to branch gh-pages-webinstaller
shell: pwsh
run: |
& git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
& git config --local user.name "github-actions[bot]"
& git add .
& git diff HEAD --exit-code | Out-Null
if ($LASTEXITCODE -ne 0)
{
& git commit -m "${{ matrix.plat }}: Update firmware files to ${{ needs.prepare-release.outputs.tag_name }}"
& git push
}