forked from themactep/thingino-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
410 lines (366 loc) · 16.4 KB
/
firmware-module.yaml
File metadata and controls
410 lines (366 loc) · 16.4 KB
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
name: firmware-module
on:
schedule:
# 03:30 PST / Nightly
- cron: '30 10 * * *'
workflow_dispatch:
inputs:
tg_disabled:
type: boolean
description: 'Disable Telegram notifications'
required: false
default: true
tg_scratch:
type: boolean
description: 'Use TG scratch channel'
required: false
default: false
graph_enabled:
type: boolean
description: 'Enable build time graph'
required: false
default: false
teacup_only:
type: boolean
description: 'Only build Tea Cup profile'
required: false
default: false
debug_enabled:
type: boolean
description: 'Debug: Generate dummy image files'
required: false
default: false
env:
TAG_NAME: module
TERM: linux
BR2_DL_DIR: ~/dl
TG_TOKEN: ${{secrets.TELEGRAM_TOKEN_BOT_THINGINO}}
TG_CHANNEL: -1002083893006_14394
TG_TOPIC: 14394
TG_CHANNEL_SCRATCH: ${{secrets.TELEGRAM_CHANNEL_THINGINO_SCRATCH}}
FORCE_UNSAFE_CONFIGURE: 1
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TG_DISABLED: true
jobs:
notify-begin:
runs-on: ubuntu-latest
outputs:
start_time: ${{ steps.set_output.outputs.time }}
tg_disabled: ${{ steps.set_env.outputs.tg_disabled }}
steps:
- name: Set timezone
run: |
sudo timedatectl set-timezone "America/Los_Angeles"
- name: Save workflow start time to ENV
id: set_output
run: echo "time=$(date +%s)" >> $GITHUB_OUTPUT
- name: Configure Environment Variables
run: |
echo "TG_DISABLED=${{ github.event.inputs.tg_disabled || 'false' }}" >> $GITHUB_ENV
echo "tg_disabled=${{ github.event.inputs.tg_disabled || 'false' }}" >> $GITHUB_OUTPUT
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: "master"
fetch-depth: "1"
- name: Send build start notifcation via Telegram
if: env.TG_DISABLED == 'false'
run: |
if [[ "${{ github.event.inputs.tg_scratch }}" == 'true' ]]; then
TG_CHANNEL=${{ env.TG_CHANNEL_SCRATCH }}
export TG_TOPIC=""
fi
.github/scripts/tg-notify.sh -s $TG_TOKEN $TG_CHANNEL $TG_TOPIC start $TAG_NAME ${{ github.run_id }} ${{ github.repository }}
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Set timezone
run: |
sudo timedatectl set-timezone "America/Los_Angeles"
- name: Configure GH workspace
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: "master"
fetch-depth: "1"
- name: Generate device matrix
id: set-matrix
run: |
if [[ "${{ github.event.inputs.teacup_only }}" == 'true' ]]; then
CONFIGS=$(find configs/modules/ -type f | sort | awk -F '/' '{print $(NF)}' | awk NF | grep 't31zx_imx327_eth')
else
CONFIGS=$(find configs/modules/ -type f | sort | awk -F '/' '{print $(NF)}' | awk NF)
fi
JSON_MATRIX="{\"thingino-version\": ["
for CONFIG in $CONFIGS; do
JSON_MATRIX+="\"${CONFIG}\","
done
JSON_MATRIX="${JSON_MATRIX%,}]}"
echo "Matrix: $JSON_MATRIX"
echo "matrix=$JSON_MATRIX" >> $GITHUB_OUTPUT
buildroot:
name: ${{ matrix.thingino-version }}
needs: [generate-matrix, notify-begin]
runs-on: ubuntu-latest
outputs:
# Feed the hash of the commit we are building into the notify-completion release-notes step
GIT_HASH: ${{ steps.env.outputs.git_hash }}
TAG_NAME: ${{ steps.env.outputs.tag_name }}
defaults:
run:
shell: bash
container:
image: debian:bookworm
strategy:
fail-fast: false
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}
steps:
- name: Update package manager sources
run: |
apt-get update
- name: Install build dependencies
run: |
apt-get install -y --no-install-recommends --no-install-suggests build-essential bc cmake cpio curl ca-certificates file git make gawk jq p7zip-full procps rsync tzdata u-boot-tools unzip wget
- name: Set timezone
run: |
ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
echo "America/Los_Angeles" > /etc/timezone
DEBIAN_FRONTEND=noninteractive dpkg-reconfigure -f noninteractive tzdata
- name: Setup gh workspace in container
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Checkout repository source
uses: actions/checkout@v4
with:
submodules: 'true'
ref: "master"
fetch-depth: "1"
- name: Configure Environment Variables
id: env
run: |
echo "WEEK_NUMBER=$(date +%U)" >> $GITHUB_ENV
echo "CURRENT_YEAR=$(date +%Y)" >> $GITHUB_ENV
echo "GIT_HASH=$(git rev-parse --short ${GITHUB_SHA})" >> $GITHUB_ENV
echo "GIT_BRANCH=${GITHUB_REF_NAME}" >> $GITHUB_ENV
echo "TG_DISABLED=${{ github.event.inputs.tg_disabled || 'false' }}" >> $GITHUB_ENV
TAG_NAME="$TAG_NAME-$(date +'%Y-%m-%d')"
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
echo "GIT_HASH=$(git rev-parse --short ${GITHUB_SHA})" >> $GITHUB_OUTPUT
echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_OUTPUT
- name: Setup cache directories
run: |
mkdir -p ~/.ccache
mkdir -p ~/dl
- name: Restore build cache
uses: actions/cache@v4
if: always()
with:
path: ~/.ccache
key: ${{ runner.os }}-ccache-${{ matrix.thingino-version }}-${{ env.CURRENT_YEAR }}-week-${{ env.WEEK_NUMBER }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-ccache-${{ matrix.thingino-version }}-${{ env.CURRENT_YEAR }}-week-${{ env.WEEK_NUMBER }}
${{ runner.os }}-ccache-${{ matrix.thingino-version }}-${{ env.CURRENT_YEAR }}-week-
${{ runner.os }}-ccache-${{ matrix.thingino-version }}-
${{ runner.os }}-ccache-
${{ runner.os }}-ccache-shared-v1-${{ env.CURRENT_YEAR }}-week-${{ env.WEEK_NUMBER }}
- name: Fetch buildroot-dl-cache release
id: find_release
run: |
REPO="${{ github.repository }}"
# First try to find tag of the release with name "buildroot-dl-cache"
RELEASE_TAG=$(gh release list --repo "$REPO" --json name,tagName | jq -r '.[] | select(.name=="buildroot-dl-cache") | .tagName' || echo "")
# If not found, try to find tag starting with "update_cache"
if [ -z "$RELEASE_TAG" ]; then
echo "Could not find release with name 'buildroot-dl-cache', trying tags starting with 'update_cache'"
RELEASE_TAG=$(gh release list --repo "$REPO" --json tagName | jq -r '.[] | select(.tagName | startswith("update_cache")) | .tagName' | head -n 1 || echo "")
fi
# If we found a release, mark as successful
if [ -n "$RELEASE_TAG" ]; then
echo "Found release with tag: $RELEASE_TAG"
echo "release_tag=${RELEASE_TAG}" >> $GITHUB_OUTPUT
echo "release_found=true" >> $GITHUB_OUTPUT
else
echo "Warning: Could not find appropriate release, continuing without cache"
echo "release_found=false" >> $GITHUB_OUTPUT
fi
- name: Download buildroot-dl-cache files
id: download_cache
if: steps.find_release.outputs.release_found == 'true'
run: |
REPO="${{ github.repository }}"
RELEASE_TAG="${{ steps.find_release.outputs.release_tag }}"
# Create temporary directory for downloads
mkdir -p /tmp/dl-cache
# Try to download all assets from the release
echo "Downloading files from release with tag: $RELEASE_TAG"
set +e # Turn off exit-on-error
gh release download "$RELEASE_TAG" --repo "$REPO" --pattern "buildroot-dl-cache*" --dir "/tmp/dl-cache"
DOWNLOAD_EXIT_CODE=$?
set -e # Turn on exit-on-error again
if [ $DOWNLOAD_EXIT_CODE -ne 0 ]; then
echo "Warning: gh command exited with code $DOWNLOAD_EXIT_CODE."
echo "download_succeeded=false" >> $GITHUB_OUTPUT
elif [ ! "$(ls -A /tmp/dl-cache/)" ]; then
echo "Warning: Download directory is empty, no files were downloaded."
echo "download_succeeded=false" >> $GITHUB_OUTPUT
else
echo "Download successful!"
echo "download_succeeded=true" >> $GITHUB_OUTPUT
fi
# List downloaded files
echo "Downloaded files:"
ls -la /tmp/dl-cache/ || echo "No files found."
- name: Extract buildroot-dl-cache
if: steps.download_cache.outputs.download_succeeded == 'true'
run: |
# If there are split ZIP files, we need to ensure they're processed correctly
if ls /tmp/dl-cache/buildroot-dl-cache.zip.* &>/dev/null; then
# For split ZIP files, we need to extract from the first part
echo "Extracting split ZIP files..."
cd ~
7z x /tmp/dl-cache/buildroot-dl-cache.zip.001 -y
else
# For single ZIP file
echo "Extracting single ZIP file..."
cd ~
7z x /tmp/dl-cache/buildroot-dl-cache.zip -y
fi
# If files were extracted to a subdirectory called 'dl', move them up
if [ -d ~/dl/dl ]; then
echo "Moving files from ~/dl/dl to ~/dl"
mv ~/dl/dl/* ~/dl/
rm -rf ~/dl/dl
fi
# Verify extraction
echo "Verifying extraction:"
ls -la ~/dl/
echo "Number of files in ~/dl:"
find ~/dl -type f | wc -l
echo "DL cache restored successfully"
- name: Build firmware
if: ${{ github.event.inputs.debug_enabled != 'true' }}
run: |
BOARD=${{ matrix.thingino-version }} make fast
TIME=$(date -d @${SECONDS} +%M:%S)
echo "TIME=${TIME}" >> ${GITHUB_ENV}
- name: Generate debug dummy firmware for workflow testing
if: ${{ github.event.inputs.debug_enabled == 'true' }}
run: |
DYNAMIC_PART="${{ matrix.thingino-version }}"
mkdir -p ${HOME}/output/${DYNAMIC_PART}/images/
echo "debug" > ${HOME}/output/${DYNAMIC_PART}/images/thingino-${DYNAMIC_PART}.bin
echo "debug uboot" > ${HOME}/output/${DYNAMIC_PART}/images/u-boot-lzo-with-spl.bin
echo "debug kernel" > ${HOME}/output/${DYNAMIC_PART}/images/uImage
echo "debug rootfs" > ${HOME}/output/${DYNAMIC_PART}/images/rootfs.squashfs
echo "debug rootfs" > ${HOME}/output/${DYNAMIC_PART}/images/rootfs.tar
echo "debug sha" > ${HOME}/output/${DYNAMIC_PART}/images/thingino-${DYNAMIC_PART}.bin.sha256sum
echo "debug" > ${HOME}/output/${DYNAMIC_PART}/images/thingino-${DYNAMIC_PART}-update.bin
echo "debug sha" > ${HOME}/output/${DYNAMIC_PART}/images/thingino-${DYNAMIC_PART}-update.bin.sha256sum
echo "TIME=7:77" >> ${GITHUB_ENV}
- name: Generate build time graphs
if: ${{ github.event.inputs.graph_enabled == 'true' }}
run: |
apt-get install -y --no-install-recommends --no-install-suggests python3-numpy python3-matplotlib
BOARD=${{ matrix.thingino-version }} make br-graph-build
- name: Locate Built Firmware Artifacts
run: |
DYNAMIC_PART="${{ matrix.thingino-version }}"
FULL_FW=$(find ${HOME}/output/${DYNAMIC_PART}*/images/ -name "thingino-${DYNAMIC_PART}.bin" ! -name "*update.bin" | head -n 1)
FULL_FW_UBOOT=$(find ${HOME}/output/${DYNAMIC_PART}*/images/ -name "u-boot-lzo-with-spl.bin" | head -n 1)
FULL_FW_KERNEL=$(find ${HOME}/output/${DYNAMIC_PART}*/images/ -name "uImage" | head -n 1)
FULL_FW_ROOTFS=$(find ${HOME}/output/${DYNAMIC_PART}*/images/ -name "rootfs.squashfs" | head -n 1)
FULL_FW_ROOTFS_TAR=$(find ${HOME}/output/${DYNAMIC_PART}*/images/ -name "rootfs.tar" | head -n 1)
UPDATE_FW=$(find ${HOME}/output/${DYNAMIC_PART}*/images/ -name "thingino-${DYNAMIC_PART}-update.bin" | head -n 1)
echo "FULL_FW: $FULL_FW"
if [[ -n "$FULL_FW" ]]; then
echo "FULL_FW=${FULL_FW}" >> ${GITHUB_ENV}
echo "FULL_FW_UBOOT=${FULL_FW_UBOOT}" >> ${GITHUB_ENV}
echo "FULL_FW_KERNEL=${FULL_FW_KERNEL}" >> ${GITHUB_ENV}
echo "FULL_FW_ROOTFS=${FULL_FW_ROOTFS}" >> ${GITHUB_ENV}
echo "FULL_FW_ROOTFS_TAR=${FULL_FW_ROOTFS_TAR}" >> ${GITHUB_ENV}
echo "FULL_FW_SHA=${FULL_FW}.sha256sum" >> ${GITHUB_ENV}
echo "UPDATE_FW=${UPDATE_FW}" >> ${GITHUB_ENV}
echo "UPDATE_FW_SHA=${UPDATE_FW}.sha256sum" >> ${GITHUB_ENV}
else
echo "Matching .bin files not found."
exit 1
fi
- name: Upload duration graph artifact
if: ${{ github.event.inputs.graph_enabled == 'true' }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.thingino-version }}-build.hist-duration
path: |
~/output/${{ matrix.thingino-version }}/graphs/build.hist-duration.pdf
- name: Upload update firmware artifacts
uses: actions/upload-artifact@v4
with:
name: thingino-${{ matrix.thingino-version }}-update-firmware
path: |
${{ env.UPDATE_FW }}
${{ env.UPDATE_FW_SHA }}
- name: Upload full firmware artifacts
uses: actions/upload-artifact@v4
with:
name: thingino-${{ matrix.thingino-version }}-full-firmware
path: |
${{ env.FULL_FW }}
${{ env.FULL_FW_UBOOT }}
${{ env.FULL_FW_KERNEL }}
${{ env.FULL_FW_ROOTFS }}
${{ env.FULL_FW_ROOTFS_TAR }}
${{ env.FULL_FW_SHA }}
- name: Upload full firmware to release
uses: softprops/action-gh-release@master
with:
tag_name: ${{ env.TAG_NAME }}
make_latest: false
files: |
${{ env.FULL_FW }}
${{ env.FULL_FW_SHA }}
- name: Send firmware completion notifications with binaries
if: ${{ env.TG_DISABLED == 'false' && (env.FULL_FW) }}
run: |
if [[ "${{ github.event.inputs.tg_scratch }}" == 'true' ]]; then
TG_CHANNEL=${{ env.TG_CHANNEL_SCRATCH }}
export TG_TOPIC=""
fi
if [ -n "${{ env.FULL_FW }}" ]; then
.github/scripts/tg-notify.sh -s $TG_TOKEN $TG_CHANNEL $TG_TOPIC completed $TAG_NAME ${{ github.run_id }} ${{ github.repository }} ${GIT_HASH} ${GIT_BRANCH} ${TAG_NAME} ${TIME} ${FULL_FW}
fi
- name: Send error notification
if: ${{ env.TG_DISABLED == 'false' && failure() }}
run: |
if [[ "${{ github.event.inputs.tg_scratch }}" == 'true' ]]; then
TG_CHANNEL=${{ env.TG_CHANNEL_SCRATCH }}
export TG_TOPIC=""
fi
.github/scripts/tg-notify.sh -s $TG_TOKEN $TG_CHANNEL $TG_TOPIC error $TAG_NAME ${{ github.run_id }} ${{ github.repository }}
notify-completion:
needs: [buildroot, notify-begin]
runs-on: ubuntu-latest
if: always()
steps:
- name: Set timezone
run: |
sudo timedatectl set-timezone "America/Los_Angeles"
- name: Configure Environment
run: |
echo "TG_DISABLED=${{ github.event.inputs.tg_disabled || 'false' }}" >> $GITHUB_ENV
echo "GIT_HASH=${{ needs.buildroot.outputs.git_hash }}" >> $GITHUB_ENV
echo "TAG_NAME=${{ needs.buildroot.outputs.tag_name }}" >> $GITHUB_ENV
- name: Send completion summary
if: ${{ env.TG_DISABLED == 'false' }}
run: |
if [[ "${{ github.event.inputs.tg_scratch }}" == 'true' ]]; then
TG_CHANNEL=${{ env.TG_CHANNEL_SCRATCH }}
export TG_TOPIC=""
fi
START_TIME=${{ needs.notify-begin.outputs.start_time }}
END_TIME=$(date -u +%s)
ELAPSED=$((END_TIME - START_TIME))
ELAPSED_MIN=$((ELAPSED / 60))
ELAPSED_SEC=$((ELAPSED % 60))
.github/scripts/tg-notify.sh $TG_TOKEN $TG_CHANNEL $TG_TOPIC finish ${{ github.workflow }} "${ELAPSED_MIN}m ${ELAPSED_SEC}s" ${{ github.run_id }} ${{ github.repository }}