-
Notifications
You must be signed in to change notification settings - Fork 1
330 lines (276 loc) · 10.1 KB
/
workflow.yml
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
name: Build
run-name: >
${{ github.event_name == 'workflow_dispatch' &&
format('{0}{1}',
'Build',
(github.event.inputs.zephyr_version && format(' Zephyr: {0}', github.event.inputs.zephyr_version ) || '')
)
|| ''
}}
on:
workflow_dispatch:
inputs:
zephyr_version:
description: "Full SHA of Zephyr commit to be used."
required: true
default: ''
push:
env:
MATRIX_RUNNERS: 22
jobs:
Prepare-Workload:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- name: Handle manually-triggered workflows
if: ${{ github.event_name == 'workflow_dispatch' }}
env:
ZEPHYR_VERSION_OVERRIDE: ${{github.event.inputs.zephyr_version}}
run: |
echo "selected version: $ZEPHYR_VERSION_OVERRIDE"
sed -i "/ZEPHYR_VERSION=/c\export ZEPHYR_VERSION=$ZEPHYR_VERSION_OVERRIDE" .env
- name: Increase build space
run: |
echo "Before cleanup"
df -H
sudo rm -rf /usr/share/dotnet/*
sudo rm -rf /usr/local/lib/android/*
sudo rm -rf /opt/ghc/*
echo "After cleanup"
df -H
- name: Prepare Zephyr Enviroment
run: |
# Basic git config to apply patches
git config --global user.name 'CI'
git config --global user.email '<>'
source .env
# Download dependencies
./scripts/prepare_sources.sh
- name: Prepare Workload
id: set-matrix
run: |
source .env
./scripts/get_boards_samples_pairs.py -c zephyr.yaml | shuf > boards_sample_pairs
echo "matrix=`./scripts/generate_matrix.py`" >> $GITHUB_OUTPUT
ls -lah
- name: Create .tar.gz archive of the environment
run: |
tar czf env.tar.gz zephyrproject/ kenning-zephyr-workspace/ zephyr-sdk/ micropython/ boards_sample_pairs
- name: Upload environment artifact
uses: actions/upload-artifact@v4
with:
name: 'zephyr_env'
retention-days: 3
if-no-files-found: error
path: |
env.tar.gz
Build:
needs: Prepare-Workload
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJSON(needs.Prepare-Workload.outputs.matrix) }}
fail-fast: false
permissions:
contents: 'read'
id-token: write
steps:
- name: Increase build space
run: |
echo "Before cleanup"
df -H
sudo rm -rf /usr/share/dotnet/*
sudo rm -rf /usr/local/lib/android/*
sudo rm -rf /opt/ghc/*
echo "After cleanup"
df -H
- uses: actions/checkout@v3
- name: Download environment artifact
uses: actions/download-artifact@v4
with:
name: 'zephyr_env'
- name: Unpack the build env
run: |
tar xf env.tar.gz
ls -la
- name: Prepare build environment
run: |
source .env
# Install Zephyr SDK and pipeline dependencies
sudo apt -qq update
sudo apt -qq install --no-install-recommends git cmake ninja-build gperf \
ccache dfu-util device-tree-compiler wget \
python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 parallel
ls -lah
# Setup runtime (SDK)
cd zephyr-sdk
./setup.sh -t all -h -c
export ZEPHYR_SDK_INSTALL_DIR=$(pwd)
cd -
# Setup runtime (west)
cd zephyrproject/zephyr
pip3 -q install -r scripts/requirements.txt
cd ..
west zephyr-export
cd ..
# Install build script dependencies
pip3 -q install -r requirements.txt
# Split wokrload between all runners
split --numeric-suffixes=1 --suffix-length=3 -n l/${MATRIX_RUNNERS} boards_sample_pairs boards_sample_pairs-
# List workload
ls -l boards_sample_pairs-*
- name: Build matrix
run: |
source .env
echo Zephyr Matrix Runner @${{ matrix.runner }} of ${MATRIX_RUNNERS}
# Assign jobs to a runner
WORKLOAD=$(printf "%03d" ${{ matrix.runner }})
COUNT=$(wc -l < boards_sample_pairs-${WORKLOAD})
# Start building
parallel -j +0 --keep-order --col-sep " " --halt now,fail=1 ./scripts/build.py --config=zephyr.yaml {} -j {#} -J ${COUNT} :::: boards_sample_pairs-${WORKLOAD}
- name: Transfer build status results
uses: actions/upload-artifact@v4
with:
name: status
path: |
build/**/*-result.json
- id: gcp-auth
if: ${{github.event_name == 'push' && github.ref == 'refs/heads/main'}}
name: GCP Authentcation
uses: google-github-actions/auth@v1
with:
service_account: ${{ secrets.GCP_SA }}
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
cleanup_credentials: true
create_credentials_file: true
export_environment_variables: false
- name: Set up Cloud SDK
if: ${{github.event_name == 'push' && github.ref == 'refs/heads/main'}}
uses: google-github-actions/setup-gcloud@v1
env:
GOOGLE_GHA_CREDS_PATH: ${{ steps.gcp-auth.outputs.credentials_file_path }}
with:
version: '>= 363.0.0'
- name: Upload artifacts to GCP
if: ${{github.event_name == 'push' && github.ref == 'refs/heads/main'}}
run: |
source .env
gsutil -m rsync -r build/ gs://zephyr-samples-builder/zephyr/$ZEPHYR_VERSION
Update-version-info:
needs: Print-status
runs-on: ubuntu-latest
if: ${{github.event_name == 'push' && github.ref == 'refs/heads/main'}}
concurrency: update_version_info
permissions:
contents: 'read'
id-token: write
steps:
- uses: actions/checkout@v3
- name: Download environment artifact
uses: actions/download-artifact@v4
with:
name: 'zephyr_env'
- name: Unpack the build env
run: |
tar xf env.tar.gz
ls -la
- id: gcp-auth
name: GCP Authentcation
uses: google-github-actions/auth@v1
with:
service_account: ${{ secrets.GCP_SA }}
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
cleanup_credentials: true
create_credentials_file: true
export_environment_variables: false
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
env:
GOOGLE_GHA_CREDS_PATH: ${{ steps.gcp-auth.outputs.credentials_file_path }}
with:
version: '>= 363.0.0'
- name: Update the `latest` file in the bucket.
run: |
source .env
CURRENT_LATEST=""
LATEST_REMOTE_FILE="gs://zephyr-samples-builder/zephyr/latest"
# If the `latest` file exists, read its contents.
! gsutil -q stat $LATEST_REMOTE_FILE \
|| CURRENT_LATEST=$(gsutil cat $LATEST_REMOTE_FILE)
cd zephyrproject/zephyr
git fetch origin main
# if `latest doesn't exist or is older then ZEPHYR_VERSION that was built in this workflow.
if [ -z "$CURRENT_LATEST" ] || ! git merge-base --is-ancestor "$ZEPHYR_VERSION" "$CURRENT_LATEST"; then
echo $ZEPHYR_VERSION > latest
gsutil cp latest $LATEST_REMOTE_FILE
fi
- name: Update the `versions` file in the bucket.
run: |
source .env
VERSIONS_REMOTE_FILE="gs://zephyr-samples-builder/zephyr/versions"
touch versions
# If the `latest` file exists, read its contents.
! gsutil -q stat $VERSIONS_REMOTE_FILE \
|| gsutil cp $VERSIONS_REMOTE_FILE versions
COUNT_ENTRIES=$(wc -l < versions)
echo "The remote file has $COUNT_ENTRIES entries."
# Store information about the version.
if ! grep -q "$ZEPHYR_VERSION" versions; then
echo "New version candidate for the versions file:"
echo "$ZEPHYR_VERSION" | tee -a versions
gsutil cp versions $VERSIONS_REMOTE_FILE
else
echo "The version is already present in the versions file:"
echo "$ZEPHYR_VERSION"
fi
Print-status:
needs: Build
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: write
steps:
- uses: actions/checkout@v3
- name: Download build status results
uses: actions/download-artifact@v4
with:
name: status
path: build/
- name: Install python dependencies
run: |
pip3 -q install -r requirements.txt
- name: Print status
run: |
source .env
./scripts/generate_summary.py -c zephyr.yaml >> $GITHUB_STEP_SUMMARY
./scripts/generate_diff.py -c zephyr.yaml || true
- id: gcp-auth
if: ${{github.event_name == 'push' && github.ref == 'refs/heads/main'}}
name: GCP Authentcation
uses: google-github-actions/auth@v1
with:
service_account: ${{ secrets.GCP_SA }}
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
cleanup_credentials: true
create_credentials_file: true
export_environment_variables: false
- name: Set up Cloud SDK
if: ${{github.event_name == 'push' && github.ref == 'refs/heads/main'}}
uses: google-github-actions/setup-gcloud@v1
env:
GOOGLE_GHA_CREDS_PATH: ${{ steps.gcp-auth.outputs.credentials_file_path }}
with:
version: '>= 363.0.0'
- name: Upload artifacts to GCP
if: ${{github.event_name == 'push' && github.ref == 'refs/heads/main'}}
run: |
source .env
gsutil cp build/result.json gs://zephyr-samples-builder/zephyr/$ZEPHYR_VERSION
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: status
path: |
build/result.json