forked from ExpressLRS/ExpressLRS
-
Notifications
You must be signed in to change notification settings - Fork 0
295 lines (251 loc) · 9.75 KB
/
build.yml
File metadata and controls
295 lines (251 loc) · 9.75 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
name: Build ExpressLRS
on: [push, pull_request]
jobs:
build-and-validate-artifacts:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
- name: Install dependencies
run: |
cd src/html
npm ci
- name: Build Web UI for all platforms
run: |
cd src/html
cp -r headers out
npm run build:all
- name: Validate artifacts
id: validate
run: |
cd src/html
if diff -qr out headers >/dev/null 2>&1; then
echo "::notice::Artifact check passed."
exit 0
else
exit_code=$?
if [ "$exit_code" -eq 1 ]; then
echo "::error title=Web UI Artifacts Error::Web UI artifacts have not been built and committed. Please build and commit them as part of this PR."
exit 1
else
echo "::warning::An unexpected error ($exit_code) occurred during file comparison."
exit 2
fi
fi
test:
runs-on: ubuntu-latest
steps:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v5
- name: Checkout
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Cache pip
uses: actions/cache@v5
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.target }}
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install platformio
pip install wheel
- name: Cache PlatformIO
uses: actions/cache@v5
with:
path: ~/.platformio
key: ${{ runner.os }}-platformio
- name: Run PlatformIO Tests
run: |
cd src
platformio pkg install --platform native
platformio pkg update
PLATFORMIO_BUILD_FLAGS="-DRegulatory_Domain_ISM_2400" pio test -e native
targets:
needs:
- build-and-validate-artifacts
- test
runs-on: ubuntu-latest
outputs:
targets: ${{ steps.set-targets.outputs.targets }}
steps:
- name: Checkout
uses: actions/checkout@v6
- id: set-targets
run: echo "targets=[$( (grep '\[env:.*UART\]' src/targets/unified.ini ; grep -r '\[env:.*STLINK\]' src/targets/) | sed 's/.*://' | sed s/.$// | egrep "(STLINK|UART)" | grep -v DEPRECATED | tr '\n' ',' | sed 's/,$/"\n/' | sed 's/,/","/'g | sed 's/^/"/')]" >> $GITHUB_OUTPUT
build:
needs: targets
strategy:
fail-fast: false
matrix:
target: ${{fromJSON(needs.targets.outputs.targets)}}
runs-on: ubuntu-latest
steps:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v5
- name: Checkout
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Cache pip
uses: actions/cache@v5
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.target }}
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install platformio
pip install wheel
- name: Cache PlatformIO
uses: actions/cache@v5
with:
path: ~/.platformio
key: ${{ runner.os }}-platformio
- name: Install Node
uses: actions/setup-node@v6
with:
node-version: 'latest'
- name: Cache node-modules
uses: actions/cache@v5
with:
path: src/html/node-modules
key: ${{ runner.os }}-node-modules
- name: Run PlatformIO
run: |
mkdir -p ~/artifacts/firmware
cd src
platformio pkg install --platform native
platformio pkg update
case ${{matrix.target}} in
*2400* | FM30*)
# release builds
PLATFORMIO_BUILD_FLAGS="-DRegulatory_Domain_EU_CE_2400" pio run -e ${{ matrix.target }}
OUTDIR=~/artifacts/firmware/LBT/`echo ${{ matrix.target }} | sed s/_via.*//`
mkdir -p $OUTDIR
mv .pio/build/${{ matrix.target }}/*.{elrs,bin} $OUTDIR >& /dev/null || :
PLATFORMIO_BUILD_FLAGS="-DRegulatory_Domain_ISM_2400" pio run -e ${{ matrix.target }}
OUTDIR=~/artifacts/firmware/FCC/`echo ${{ matrix.target }} | sed s/_via.*//`
mkdir -p $OUTDIR
mv .pio/build/${{ matrix.target }}/*.{elrs,bin} $OUTDIR >& /dev/null || :
;;
*LR1121*)
# release builds
PLATFORMIO_BUILD_FLAGS="-DRegulatory_Domain_EU_CE_2400 -DRegulatory_Domain_FCC_915" pio run -e ${{ matrix.target }}
OUTDIR=~/artifacts/firmware/LBT/`echo ${{ matrix.target }} | sed s/_via.*//`
mkdir -p $OUTDIR
mv .pio/build/${{ matrix.target }}/*.{elrs,bin} $OUTDIR >& /dev/null || :
PLATFORMIO_BUILD_FLAGS="-DRegulatory_Domain_FCC_915" pio run -e ${{ matrix.target }}
OUTDIR=~/artifacts/firmware/FCC/`echo ${{ matrix.target }} | sed s/_via.*//`
mkdir -p $OUTDIR
mv .pio/build/${{ matrix.target }}/*.{elrs,bin} $OUTDIR >& /dev/null || :
;;
*)
# release build
PLATFORMIO_BUILD_FLAGS="-DRegulatory_Domain_FCC_915" pio run -e ${{ matrix.target }}
OUTDIR=~/artifacts/firmware/FCC/`echo ${{ matrix.target }} | sed s/_via.*//`
mkdir -p $OUTDIR
mv .pio/build/${{ matrix.target }}/*.{elrs,bin} $OUTDIR >& /dev/null || :
;;
esac
- name: Store Artifacts
uses: actions/upload-artifact@v7
with:
name: temp-${{ matrix.target }}
path: ~/artifacts/**/*
retention-days: 1
continue-on-error: true
firmware:
needs: [build, test]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Checkout targets repo
uses: actions/checkout@v6
with:
repository: ExpressLRS/targets
path: src/hardware
- name: Get firmware artifacts
uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true
- name: Copy hardware files to firmware folder
run: |
cp -r src/hardware dist/firmware
jq 'del(.generic)' src/hardware/targets.json > dist/firmware/hardware/targets.json
- name: Copy Lua to to firmware folder
run: |
mkdir -p dist/firmware/lua
cp -r src/lua/elrs.lua dist/firmware/lua
- name: Copy bootloader files to firmware folder
run: cd src ; find bootloader -name \*.bin -o -name \*.frk | grep -v src/ | cpio -pdm ../dist/firmware
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Build flasher "binary" with shiv
run: |
cd src/python
pip install shiv==1.0.6
shiv -c flash -o ../../dist/firmware/flasher.pyz pyserial .
- name: Update firmware artifact
uses: actions/upload-artifact@v7
with:
name: firmware
path: dist/**/*
- name: Create firmware zip bundle
run: |
cd dist
zip -r -9 ../firmware.zip ./firmware
- name: Install downgraded AWS CLI
uses: unfor19/install-aws-cli-action@v1
with:
version: "2.22.35"
- name: Upload firmware bundle to ExpressLRS artifactory
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_ENDPOINT_URL: ${{ secrets.AWS_ENDPOINT_URL }}
AWS_REGION: "auto"
run: |
aws --version
if [[ -z $AWS_ACCESS_KEY_ID || -z $AWS_SECRET_ACCESS_KEY || -z $AWS_ENDPOINT_URL ]]; then
echo "::warning title=Artifactory Skip::Credentials not defined. Skipping upload (expected for PRs from forks)."
exit 0
fi
IS_TAG=$([[ "$GITHUB_REF_TYPE" == "tag" ]] && echo true || echo false)
ARTIFACT_EXISTS=$(aws s3api head-object --endpoint-url $AWS_ENDPOINT_URL --bucket expresslrs --key ExpressLRS/$GITHUB_SHA/firmware.zip > /dev/null 2>&1 && echo true || echo false)
if [ "$IS_TAG" = "true" ] || [ "$ARTIFACT_EXISTS" = "false" ]; then
echo "Uploading firmware to artifactory..."
aws s3 cp --endpoint-url $AWS_ENDPOINT_URL firmware.zip s3://expresslrs/ExpressLRS/$GITHUB_SHA/firmware.zip
echo "::group::Generating and Uploading Artifact Index"
aws s3 ls --endpoint-url $AWS_ENDPOINT_URL s3://expresslrs/ExpressLRS/ | awk '{print $2}' | sed s/\\/// > /tmp/hashes
echo '{' > index.json
echo '"branches": {' >> index.json
git branch --list --remotes --format '"%(refname:short)": "%(objectname)",' | grep origin/ | sed s/origin.// | grep -f /tmp/hashes | head -c-2 >> index.json
echo '' >> index.json
echo '},' >> index.json
echo '"tags": {' >> index.json
git tag --list --format '"%(refname:short)": "%(objectname)",' | grep -f /tmp/hashes | head -c-2 >> index.json
echo '' >> index.json
echo '}' >> index.json
echo '}' >> index.json
aws s3 cp --endpoint-url $AWS_ENDPOINT_URL index.json s3://expresslrs/ExpressLRS/index.json
echo "::endgroup::"
echo "::notice title=Artifactory Upload Success::Firmware for $GITHUB_SHA has been uploaded."
else
echo "::notice title=Artifactory Skip::Artifact already exists and this is not a tag push. Skipping overwrite."
fi