-
Notifications
You must be signed in to change notification settings - Fork 8
248 lines (220 loc) · 7.58 KB
/
build.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
# Copyright (C) 2023 Toitware ApS.
#
# Use of this source code is governed by a BSD0-style license that can be
# found in the LICENSE_BSD0 file.
name: Build
on:
workflow_dispatch:
inputs:
toit-version:
description: Toit SDK version to check out
required: true
type: string
branch:
description: Branch to check out (overrides toit-version)
required: false
type: string
default: ""
upload-release:
description: Upload release artifacts
required: true
type: boolean
default: false
variant:
description: Variant to build
required: false
type: string
gist:
description: Link to gist with variant files
required: false
type: string
jobs:
build:
name: "Build for SDK ${{ github.event.inputs.toit-version }}"
runs-on: ubuntu-latest
steps:
- name: Show inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- uses: actions/checkout@v4
# Use Go 1.20
- name: Switch to Go 1.20
shell: bash
run:
echo "$GOROOT_1_20_X64"/bin >> $GITHUB_PATH
# Get values for cache paths to be used in later steps
- name: Get Go paths
id: go-cache-paths
shell: bash
run: |
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
# Cache go build cache, used to speedup go test
- name: Go Build Cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-build-
# Cache go mod cache, used to speedup builds
- name: Go Mod Cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-mod-
- name: Ccache cache
uses: actions/cache@v4
# Store and retrieve the cache with the given sha.
# The 'restore-keys' prefix finds the most recent cache in case there
# is no match (which should almost always be the case).
with:
path: ${{ github.workspace }}/.ccache
key: envelope-ccache-${{ github.sha }}
restore-keys: envelope-ccache-
- name: Install dependencies - Linux
run: |
sudo apt-get update
sudo apt-get install ninja-build ccache
ninja --version
cmake --version
gcc --version
- name: Set the git version
run: |
echo "TOIT_GIT_VERSION=${{ github.event.inputs.toit-version }}" >> $GITHUB_ENV
- name: Fetch the Toit repository
run: |
# We allow the workflow dispatch to override the checked out branch.
# Note that we set the TOIT_GIT_VERSION env variable. The checked out branch
# thus doesn't influence the version of the SDK we build.
REF=${{ github.event.inputs.branch }}
if [[ -z "$REF" ]]; then
REF=${{ github.event.inputs.toit-version }}
fi
make TOIT_VERSION=$REF download-toit
- name: Ccache stats before SDK build
run: |
ccache -s
- name: Build the host SDK
env:
IDF_CCACHE_ENABLE: 1
CCACHE_DIR: ${{ github.workspace }}/.ccache
CCACHE_BASEDIR: ${{ github.workspace }}
CCACHE_COMPRESS: true
CCACHE_COMPRESSLEVEL: '6'
CCACHE_MAXSIZE: 600M
run: |
make build-host
- name: Ccache stats after SDK build
run: |
ccache -s
- name: Build the envelope tool
run: |
build/host/sdk/bin/toit.pkg install --project-root=tools
build/host/sdk/bin/toit.compile -o build/envelope-tool tools/main.toit
- name: Install ESP32 tools
run: |
toit/third_party/esp-idf/install.sh
- name: Setting the variants
run: |
VARIANTS=${{ github.event.inputs.variant }}
if [ -z "$VARIANTS" ]; then
if ! [ -z "${{ github.event.inputs.gist }}" ]; then
VARIANTS="gist"
else
VARIANTS=$(build/envelope-tool list)
if [ $? -ne 0 ]; then
echo "Failed to list variants"
exit 1
fi
fi
fi
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "VARIANTS<<$EOF" >> $GITHUB_ENV
echo "$VARIANTS" >> $GITHUB_ENV
echo "$EOF" >> $GITHUB_ENV
echo "VARIANTS_ROOT=variants" >> $GITHUB_ENV
- name: Download Gist
if: ${{ github.event.inputs.gist }}
run: |
GIST=${{ github.event.inputs.gist }}
mkdir -p "gist-variant/$VARIANTS"
build/envelope-tool download-gist -o "gist-variant/$VARIANTS" "$GIST"
echo "VARIANTS_ROOT=gist-variant" >> $GITHUB_ENV
find gist-variant
- name: Synthesize the variants
run: |
build/envelope-tool synthesize \
--ignore-errors \
--toit-root=toit \
--output-root=synthesized \
--sdk-path=build/host/sdk \
--variants-root=$VARIANTS_ROOT \
--build-root=build \
$VARIANTS
- name: Ccache stats before variants build
run: |
ccache -s
- name: Build the variants
env:
IDF_CCACHE_ENABLE: 1
CCACHE_DIR: ${{ github.workspace }}/.ccache
CCACHE_BASEDIR: ${{ github.workspace }}
CCACHE_COMPRESS: true
CCACHE_COMPRESSLEVEL: '6'
CCACHE_MAXSIZE: 600M
run: |
for variant in $VARIANTS; do
mkdir -p build/$variant
if [ -e synthesized/$variant/failed ]; then
echo "Skipping $variant to due failed synthesis."
touch build/$variant/failed
continue
fi
ccache -s
(cd synthesized/$variant && make) || touch build/$variant/failed
done
- name: Ccache stats after variants build
run: |
ccache -s
- name: Prepare envelopes for upload
run: |
mkdir envelopes
for variant in $VARIANTS; do
if [ -e build/$variant/failed ]; then
echo "Skipping $variant"
continue
fi
cp build/$variant/firmware.envelope envelopes/firmware-$variant.envelope
gzip -9 envelopes/firmware-$variant.envelope
done
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts
path: |
envelopes
- name: Release
if: ${{ github.event.inputs.upload-release == 'true' }}
uses: ncipollo/release-action@v1
with:
artifacts: |
envelopes/*
body: |
Envelopes for Toit SDK ${{ github.event.inputs.toit-version }}
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.toit-version }}
commit: main
- name: Report failed builds
if: ${{ github.event.inputs.upload-release == 'true' }}
run: |
build_failed=false
for variant in $VARIANTS; do
if [ -e build/$variant/failed ]; then
echo "Build of $variant failed"
build_failed=true
fi
done
if [ "$build_failed" = true ]; then
exit 1
fi