forked from themactep/thingino-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
210 lines (185 loc) · 8.97 KB
/
firmware.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
name: firmware
on:
schedule:
# 01:15 PST / Nightly
- cron: '15 09 * * *'
workflow_dispatch:
env:
TAG_NAME: firmware
TERM: linux
BR2_DL_DIR: /tmp/dl
TG_TOKEN: ${{secrets.TELEGRAM_TOKEN_BOT_THINGINO}}
TG_CHANNEL: ${{secrets.TELEGRAM_CHANNEL_THINGINO_BUILD}}
TG_OPTIONS: -s -o /dev/null -w %{http_code}
TG_ENABLE: true
jobs:
notify-begin:
runs-on: ubuntu-latest
outputs:
start_time: ${{ steps.set_output.outputs.time }}
steps:
- name: Save workflow start time
id: set_output
run: echo "time=$(date +%s)" >> $GITHUB_OUTPUT
- name: Send build start notifcation
if: env.TG_ENABLE== 'true'
run: |
TG_MSG="Firmware build started:\nJob: [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})\n\n"
TG_ICON="\xF0\x9F\x9A\xA6 GitHub Actions"
TG_HEADER=$(echo -e ${TG_MSG}${TG_ICON})
HTTP=$(curl ${TG_OPTIONS} -H "Content-Type: multipart/form-data" -X POST https://api.telegram.org/bot${TG_TOKEN}/sendMessage -F parse_mode=MarkdownV2 -F chat_id=${TG_CHANNEL} -F text="${TG_HEADER}" -F disable_web_page_preview=true)
echo Telegram response: ${HTTP}
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Generate matrix
id: set-matrix
run: |
CONFIGS=$(.github/scripts/list_configs.sh)
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
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
submodules: 'true'
- name: Setup Environment
id: date
run: |
echo "WEEK_NUMBER=$(date +%U)" >> $GITHUB_ENV
echo "CURRENT_YEAR=$(date +%Y)" >> $GITHUB_ENV
export GIT_HASH=$(git rev-parse --short ${GITHUB_SHA})
export GIT_BRANCH=${GITHUB_REF_NAME}
echo "GIT_HASH=${GIT_HASH}" >> ${GITHUB_ENV}
echo "GIT_BRANCH=${GIT_BRANCH}" >> ${GITHUB_ENV}
- name: Setup cache directories
run: |
mkdir -p /tmp/ccache
mkdir -p /tmp/dl
ln -s /tmp/ccache ${HOME}/.ccache
ln -s /tmp/dl ${HOME}/dl
- name: Setup ccache
uses: actions/cache@v4
if: always()
with:
path: /tmp/ccache
key: ${{ runner.os }}-ccache-${{ matrix.thingino-version }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-ccache-${{ matrix.thingino-version }}-
- name: Setup buildroot download directory cache
uses: actions/cache@v4
if: always()
with:
path: /tmp/dl
key: ${{ runner.os }}-dl-shared-v1-${{ env.CURRENT_YEAR }}-week-${{ env.WEEK_NUMBER }}
restore-keys: |
${{ runner.os }}-dl-shared-v1-${{ env.CURRENT_YEAR }}-week-
- name: Setup repo sources for GCC13
run: |
sudo echo "deb http://archive.ubuntu.com/ubuntu/ lunar main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list
sudo tee -a /etc/apt/preferences.d/prefer-jammy <<EOF
Package: *
Pin: release a=jammy
Pin-Priority: 500
Package: *
Pin: release a=lunar
Pin-Priority: 100
EOF
- name: Update system sources
run: |
sudo apt-get update
- name: Install build dependencies
run: |
sudo apt-get install -y --no-install-recommends --no-install-suggests build-essential bc bison cpio curl file flex git libncurses-dev make rsync unzip wget whiptail gcc gcc-mipsel-linux-gnu lzop u-boot-tools ca-certificates ccache
- name: Install GCC13 dependencies
run: |
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --no-install-suggests libc6=2.37-0ubuntu2 libc-bin=2.37-0ubuntu2 libc6-mipsel-cross=2.37-0ubuntu1cross1 libc6-dev=2.37-0ubuntu2 libc-dev-bin=2.37-0ubuntu2 coreutils=9.1-1ubuntu2 libgmp10=2:6.2.1+dfsg1-1.1ubuntu1
- name: Build firmware
run: |
BOARD=${{ matrix.thingino-version }} make
TIME=$(date -d @${SECONDS} +%M:%S)
echo "TIME=${TIME}" >> ${GITHUB_ENV}
- name: Prepare full image
run: |
BOARD=${{ matrix.thingino-version }} make pack_full
- name: Rename image for release
run: |
# Extract the defconfig name to form a pattern for the file name, change _ to -
DYNAMIC_PART=$(echo "${{ matrix.thingino-version }}")
PATTERN="thingino-${DYNAMIC_PART}-*.bin"
# Find the binary file using the generated pattern
INGFW=$(find ${HOME}/output/${{ matrix.thingino-version }}*/images/ -name "${PATTERN}" | head -n 1)
echo "INGFW: $INGFW"
if [[ -n "${INGFW}" ]]; then
# Remove the numeric timestamp part from the filename
INGFW_BASENAME=$(echo "${INGFW}" | sed 's/-[0-9]\{12\}\.bin$/.bin/')
echo "INGFW_BASENAME: $INGFW_BASENAME"
mv "${INGFW}" "${INGFW_BASENAME}"
echo INGFW=${INGFW_BASENAME} >> ${GITHUB_ENV}
else
echo "Matching .bin file not found."
exit 1
fi
- name: Upload firmware as artifact
uses: actions/upload-artifact@v4
with:
name: thingino-${{ matrix.thingino-version }}
path: ${{ env.INGFW }}
- name: Upload firmware
if: github.event_name != 'pull_request'
uses: softprops/action-gh-release@master
with:
tag_name: ${{ env.TAG_NAME }}
files: ${{ env.INGFW }}
- name: Send completion notification with binary
if: github.event_name != 'pull_request' && env.INGFW && env.TG_ENABLE== 'true'
run: |
TG_MSG="Commit: [${GIT_HASH}](https://github.com/${GITHUB_REPOSITORY}/commit/${GIT_HASH})\nBranch: [${GIT_BRANCH}](https://github.com/${GITHUB_REPOSITORY}/tree/${GIT_BRANCH})\nTag: [${TAG_NAME}](https://github.com/${GITHUB_REPOSITORY}/releases/tag/${TAG_NAME})\nTime: ${TIME}\nJob: [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})\n\n"
TG_ICON="\xE2\x9C\x85 GitHub Actions"
TG_HEADER=$(echo -e ${TG_MSG}${TG_ICON})
HTTP=$(curl ${TG_OPTIONS} -H "Content-Type: multipart/form-data" -X POST https://api.telegram.org/bot${TG_TOKEN}/sendDocument -F parse_mode=MarkdownV2 -F chat_id=${TG_CHANNEL} -F caption="${TG_HEADER}" -F document=@${INGFW} -F disable_web_page_preview=true)
echo Telegram response: ${HTTP}
- name: Send error notification
if: github.event_name != 'pull_request' && failure()
run: |
TG_ESCAPED_VERSION=$(echo "${{ matrix.thingino-version }}" | sed 's/_/\\_/g')
TG_WARN="Error: ${TG_ESCAPED_VERSION}\n"
TG_MSG="Commit: [${GIT_HASH}](https://github.com/${GITHUB_REPOSITORY}/commit/${GIT_HASH})\nBranch: [${GIT_BRANCH}](https://github.com/${GITHUB_REPOSITORY}/tree/${GIT_BRANCH})\nTag: [${TAG_NAME}](https://github.com/${GITHUB_REPOSITORY}/releases/tag/${TAG_NAME})\nJob: [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})\n\n"
TG_ICON="\xE2\x9A\xA0 GitHub Actions"
TG_HEADER=$(echo -e ${TG_WARN}${TG_MSG}${TG_ICON})
HTTP=$(curl ${TG_OPTIONS} -H "Content-Type: multipart/form-data" -X POST https://api.telegram.org/bot${TG_TOKEN}/sendMessage -F parse_mode=MarkdownV2 -F chat_id=${TG_CHANNEL} -F text="${TG_HEADER}" -F disable_web_page_preview=true)
echo Telegram response: ${HTTP}
notify-completion:
needs: [buildroot, notify-begin]
runs-on: ubuntu-latest
if: always()
steps:
- name: Send completion summary
if: env.TG_ENABLE == 'true'
run: |
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))
TG_MSG="Firmware build completed:\nTotal elapsed time: ${ELAPSED_MIN}m ${ELAPSED_SEC}s\nJob: [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})\n\n"
TG_ICON="\xF0\x9F\x9A\xA9 GitHub Actions"
TG_HEADER=$(echo -e ${TG_MSG}${TG_ICON})
HTTP=$(curl ${TG_OPTIONS} -H "Content-Type: multipart/form-data" -X POST https://api.telegram.org/bot${TG_TOKEN}/sendMessage -F parse_mode=MarkdownV2 -F chat_id=${TG_CHANNEL} -F text="${TG_HEADER}" -F disable_web_page_preview=true)
echo Telegram response: ${HTTP}