forked from jomjol/AI-on-the-edge-device
-
Notifications
You must be signed in to change notification settings - Fork 0
272 lines (235 loc) · 11 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
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 package for OTA Update
# Package to be used with OTA updater on WebUI
#
# Package contents:
# - /firmware.bin
# - (optional) /html/* (inkl. subfolders)
# - (optional) /config/*.tflite
#########################################################################################
- name: OTA update package - Prepare artifact
run: |
rm -rf ./update
mkdir -p ./update
cp "./code/.pio/build/${{ matrix.plat }}/firmware.bin" "update/firmware.bin"
cp -r ./html ./update/
rm -rf ./update/config/
mkdir -p ./update/config/
cp ./sd-card/config/*.tfl ./update/config/ 2>/dev/null || true
cp ./sd-card/config/*.tflite ./update/config/ 2>/dev/null || true
- name: OTA update package - Upload artifact
uses: actions/upload-artifact@v4
with:
name: "AI-on-the-edge-device__update__${{ matrix.plat }}__SLFork_${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
path: ./update
#########################################################################################
## Create package for Full Setup -> Complete fresh install
# Create a full setup with all binaries and sd-card files to do an full setup by USB
#
# Package contents:
# - /firmware.bin
# - /partitions.bin
# - /bootloader.bin
# - sd-card.zip (Content for sd-card -> extract to root folder)
#########################################################################################
- name: Manual setup package - Prepare artifact
run: |
rm -rf manual_setup
mkdir -p manual_setup
rm -rf manual_setup/*.zip
# copy builds to manual_setup folder
cp -f "./code/.pio/build/${{ matrix.plat }}/firmware.bin" "manual_setup/firmware.bin"
cp -f "./code/.pio/build/${{ matrix.plat }}/bootloader.bin" "manual_setup/bootloader.bin"
cp -f "./code/.pio/build/${{ matrix.plat }}/partitions.bin" "manual_setup/partitions.bin"
rm -rf ./sd-card/html
cp -r ./html ./sd-card/ # Overwrite the Web UI with the preprocessed files
cd sd-card; zip -r ../manual_setup/sd-card.zip *; cd ..
- name: Manual setup package - Upload artifact
uses: actions/upload-artifact@v4
with:
name: "AI-on-the-edge-device__manual-setup__${{ matrix.plat }}__SLFork_${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
path: ./manual_setup
#########################################################################################
## Create package for initial 2-step setup (Remote Setup)
# 1. WebUpdater: Install firmware binary
# 2. ESP Access Point: Install SD-Card content
#
# Package contents:
# - /html/*
# - /config/*
#########################################################################################
- name: Remote setup package - Prepare artifact
run: |
rm -rf ./remote_setup
mkdir -p ./remote_setup
cp -r ./html ./remote_setup/
rm -rf ./remote_setup/config/
mkdir -p ./remote_setup/config/
cp ./sd-card/config/* ./remote_setup/config/ 2>/dev/null || true
- name: Remote setup package - Upload artifact
uses: actions/upload-artifact@v4
with:
name: "AI-on-the-edge-device__remote-setup__${{ matrix.plat }}__SLFork_${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
path: ./remote_setup
#########################################################################################
## Create package with additional files for debugging purpose
#
# Package contents:
# - firmware.elf
# - sdkconfig.defaults
# - 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__debug-files__${{ matrix.plat }}__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
needs: [prepare-release, build]
if: ${{ needs.prepare-release.outputs.release_created }}
strategy:
fail-fast: false
matrix:
plat:
- esp32cam
- esp32cam-debug
# 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__update__${{ matrix.plat }}__SLFork_${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
zip -r ../release/AI-on-the-edge-device__update__${{ matrix.plat }}__SLFork_v${{ needs.prepare-release.outputs.version }}.zip *
cd ..
cd "AI-on-the-edge-device__manual-setup__${{ matrix.plat }}__SLFork_${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
zip -r ../release/AI-on-the-edge-device__manual-setup__${{ matrix.plat }}__SLFork_v${{ needs.prepare-release.outputs.version }}.zip *
cd ..
cd "AI-on-the-edge-device__remote-setup__${{ matrix.plat }}__SLFork_${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
zip -r ../release/AI-on-the-edge-device__remote-setup__${{ matrix.plat }}__SLFork_v${{ needs.prepare-release.outputs.version }}.zip *
cd ..
cd "AI-on-the-edge-device__debug-files__${{ matrix.plat }}__SLFork_${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
zip -r ../release/AI-on-the-edge-device__debug-files__${{ matrix.plat }}__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/*