-
Notifications
You must be signed in to change notification settings - Fork 134
267 lines (229 loc) · 8.5 KB
/
main.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
# Run this job on pushes to master and all PRs
name: Build and Test
on:
push:
branches:
- master
pull_request:
jobs:
build:
runs-on: ubuntu-latest
# Define the strategy for the build job. We generally want to cover each
# platform that we support here
strategy:
matrix:
platform: [generic, hifive_unmatched, cva6]
bits: [32, 64]
exclude:
# unmatched is not 32 bit
- platform: hifive_unmatched
bits: 32
# Output cache keys that were used so we can consolidate them later. Note
# that this is a matrix job, and job outputs for these are not well supported
# at all in Github Actions (https://github.com/orgs/community/discussions/26639).
# Essentially, the last job to set these output variables will win, which is
# not always great. In our case, though, this is actually fine since we don't
# necessarily need "precise" matching here -- any job's output should be good
# enough to serve as a future key into the cache.
outputs:
buildroot-dl-key: ${{ steps.restore-buildroot-dl.outputs.cache-primary-key }}
ccache-key: ${{ steps.restore-ccache.outputs.cache-primary-key }}
ymdh: ${{ steps.cache-keys.outputs.YMDH }}
steps:
###########
## Setup ##
###########
# First, we need to get the version of Keystone we are working on. We
# will also need submodules here since we are doing full builds
- name: Checkout Keystone
uses: actions/checkout@v3
with:
submodules: 'true'
# Get various keys for various caches
- name: Get cache keys
id: cache-keys
run: |
# Grab some timestamps for compiler caches
echo "YMDH=$(date -u +'%Y-%m-%d-%H')" >> "$GITHUB_OUTPUT"
echo "YMD=$(date -u +'%Y-%m-%d')" >> "$GITHUB_OUTPUT"
echo "YM=$(date -u +'%Y-%m')" >> "$GITHUB_OUTPUT"
echo "Y=$(date -u +'%Y')" >> "$GITHUB_OUTPUT"
# Install build dependencies
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y cpio rsync bc makeself
# Restore build and download caches. We key these based on timestamps and build
# target, since these essentially "accumulate" useful information (such as source
# packages or cached compiled objects) over time. With this scheme, we'll pretty
# much always be using the max Github Action cache limit (10GB), but this is okay
# since we really only care about keeping the latest cache anyways.
- name: Restore buildroot packages
id: restore-buildroot-dl
uses: actions/cache/restore@v3
with:
path: dl.tar
key: buildroot-dl-${{ steps.cache-keys.outputs.YMDH }}
restore-keys: |
buildroot-dl-${{ steps.cache-keys.outputs.YMD }}
buildroot-dl-${{ steps.cache-keys.outputs.YM }}
buildroot-dl-${{ steps.cache-keys.outputs.Y }}
buildroot-dl-
- name: Restore ccache
id: restore-ccache
uses: actions/cache/restore@v3
with:
path: ccache.tar.xz
key: ccache-${{ steps.cache-keys.outputs.YMDH }}
restore-keys: |
ccache-${{ steps.cache-keys.outputs.YMD }}
ccache-${{ steps.cache-keys.outputs.YM }}
ccache-${{ steps.cache-keys.outputs.Y }}
ccache-
- name: Decompress caches
run: |
if [[ -f dl.tar ]] ; then tar -xf dl.tar -C buildroot ; fi
if [[ -f ccache.tar.xz ]]; then tar -xf ccache.tar.xz -C ~ ; fi
##############
## Keystone ##
##############
# Build Keystone and upload the results log if we fail to do so
- name: Build Keystone
run: |
KEYSTONE_PLATFORM=${{ matrix.platform }} \
KEYSTONE_BITS=${{ matrix.bits }} make -j$(nproc)
- name: Upload build log
if: failure()
uses: actions/upload-artifact@v4
with:
name: build-keystone-${{ matrix.platform }}${{ matrix.bits }}.log
path: build-${{ matrix.platform }}${{ matrix.bits }}/build.log
# We need parts of the build directory for future tests
- name: Compress build directory
run: |
# Convenient vars
BASEDIR="build-${{ matrix.platform }}${{ matrix.bits }}/buildroot.build"
PERPACKAGEDIR="$BASEDIR/per-package"
# Needed by most tests
COMPRESSDIRS="$BASEDIR/host $BASEDIR/images"
# Needed by runtime build tests
COMPRESSDIRS="$COMPRESSDIRS $PERPACKAGEDIR/keystone-examples/host/usr/share/keystone/sdk"
# Needed by end-to-end tests
COMPRESSDIRS="$COMPRESSDIRS $BASEDIR/target/root/"
tar -cf - $COMPRESSDIRS | xz -9 -T0 > build.tar.xz
- name: Compress cache directories
run: |
tar -C buildroot --exclude='**/git' -cf dl.tar dl/
tar -C ~ -cf - .buildroot-ccache | xz -9 -T0 > ccache.tar.xz
- name: Upload build directory
uses: actions/upload-artifact@v4
with:
name: keystone-${{ matrix.platform }}${{ matrix.bits }}-builddir
path: build.tar.xz
retention-days: 1
compression-level: 0
- name: Upload buildroot download directory
uses: actions/upload-artifact@v4
with:
name: keystone-${{ matrix.platform }}${{ matrix.bits }}-buildroot-dl
path: dl.tar
retention-days: 1
compression-level: 0
- name: Upload ccache directory
uses: actions/upload-artifact@v4
with:
name: keystone-${{ matrix.platform }}${{ matrix.bits }}-ccache
path: ccache.tar.xz
retention-days: 1
compression-level: 0
###############
## Utilities ##
###############
# Combine cache directories to save space
combine-caches:
runs-on: ubuntu-latest
needs: build
steps:
- name: Install dependencies
run: |
sudo apt-get -y update && sudo apt-get -y install ccache
# First, fetch the caches themselves
- name: Prepare output directories
run: |
mkdir -p buildroot/dl/ ~/.buildroot-ccache/
- name: Fetch buildroot caches
uses: actions/download-artifact@v4
with:
pattern: keystone-*-buildroot-dl
- name: Fetch ccache caches
uses: actions/download-artifact@v4
with:
pattern: keystone-*-ccache
# Then, combine the caches
- name: Merge caches
run: |
for d in keystone-*-buildroot-dl; do
tar --skip-old-files -xf "$d/dl.tar" -C buildroot
done
RESULTDIR="$HOME/.buildroot-ccache"
for d in keystone-*-ccache; do
TMPDIR=$(mktemp -d)
tar -xf "$d/ccache.tar.xz" -C "$TMPDIR"
( cd "$TMPDIR/.buildroot-ccache" ; cp -a --parents ? "$RESULTDIR" )
rm -rf "$TMPDIR"
done
ccache -d "$RESULTDIR" -c
- name: Recompress caches
run: |
tar -C buildroot --exclude='**/git' -cf dl.tar dl/
tar -C ~ -cf - .buildroot-ccache | xz -9 -T0 > ccache.tar.xz
- name: Save buildroot download cache
uses: actions/cache/save@v3
with:
path: dl.tar
key: ${{ needs.build.outputs.buildroot-dl-key }}
- name: Save ccache
uses: actions/cache/save@v3
with:
path: ccache.tar.xz
key: ${{ needs.build.outputs.ccache-key }}
###########
## Tests ##
###########
# Generic runtime tests, which only need to run once (on the host)
test-runtime-format:
runs-on: ubuntu-latest
steps:
# We don't need submodules here since Keystone is a monorepo!
- name: Checkout Keystone
uses: actions/checkout@v3
with:
submodules: 'false'
- name: Check format
run: |
sudo apt-get update && sudo apt-get install -y clang-format
FORMAT=$(git help -a | grep clang-format | tail -n1)
cd runtime ; FORMAT_RESULT=$(git $FORMAT)
[ "$FORMAT_RESULT" = "no modified files to format" ] || [ "$FORMAT_RESULT" = "clang-format did not modify any files" ]
test-runtime-functionality:
runs-on: ubuntu-latest
steps:
- name: Checkout Keystone
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Run ctest
run: |
cd runtime
mkdir -p obj/test
pushd obj/test
cmake ../../test
make
ctest -VV || ( cat obj/test/Testing/Temporary/LastTest.log && false )
popd
# Build tests, which are run for each supported platform
test-runtime-build:
needs: build
uses: ./.github/workflows/build-runtime.yml
# System tests, which are run for simulatable platforms
test-system:
needs: build
uses: ./.github/workflows/test-system.yml