-
Notifications
You must be signed in to change notification settings - Fork 23
325 lines (278 loc) · 11.1 KB
/
ci.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
name: CI
# Limit concurrent runs of this workflow within a single PR
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
on:
workflow_dispatch:
inputs:
nothunks:
description:
Run the test run under NoThunks conditions instead of the default variant
type: boolean
default: false
nothunks-safe-only:
description:
Run only the test suites which are known to pass under NoThunks conditions
type: boolean
default: false
pull_request:
merge_group:
push:
branches:
- main
schedule:
# every night, at midnight
- cron: "0 0 * * *"
# on the first day of each month, at midnight
- cron: "0 0 1 * *"
jobs:
build-test-bench-haddocks:
name: Build and test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ghc: ["8.10.7", "9.6.6", "9.10.1"]
variant: [default, no-thunks]
test-set: [all, no-thunks-safe]
exclude:
- variant:
${{ (github.event_name == 'schedule' || inputs.nothunks) && 'default' || 'no-thunks' }}
- test-set:
${{ (github.event_name == 'schedule' || inputs.nothunks-safe-only) && 'all' || 'no-thunks-safe' }}
env:
# Modify this value to "invalidate" the Cabal cache.
CABAL_CACHE_VERSION: "2024-07-04"
CABAL: "3.12.1.0"
steps:
- uses: actions/checkout@v4
- name: Install base libraries
uses: input-output-hk/actions/base@latest
with:
use-sodium-vrf: false
- name: Install Haskell
uses: input-output-hk/actions/haskell@latest
id: setup-haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: $CABAL
- name: Configure Cabal
run: |
cp .github/workflows/cabal.project.${{ matrix.variant }}.local ./cabal.project.local
- name: Update Cabal (Hackage and CHaP)
run: |
cabal clean
cabal update
# We create a `dependencies.txt` file that can be used to index the cabal
# store cache.
#
# We do not use `plan.json` directly because adding a dependency to our
# Cabal files which was already present somewhere else would result in a
# diferent plan, even though the set of dependencies is the same.
#
# In the future we should consider using `cabal-cache` like in the
# `cardano-node`'s GitHub workflow.
- name: Record dependencies to be used as cache keys
id: record-deps
run: |
cabal build all --dry-run --minimize-conflict-set
cat dist-newstyle/cache/plan.json \
| jq '.["install-plan"][].id' \
| sort \
| uniq > dependencies.txt
# This is used for caching the cabal store.
- name: Store month number as environment variable
run: echo "MONTHNUM=$(/usr/bin/date -u '+%m')" >> $GITHUB_ENV
# Restore the cabal store cache. See `save-cabal-store`.
#
# When we restore a previous cache and store a new key, we store both files
# that were already in the cache, and new files that were created. To
# prevent the cache from growing to quickly, we reset the cache each month.
#
# NOTE: it's vital that all restore-keys include the month number.
# Otherwise, we could restore a cache from a previous month, which makes
# caches grow unboundedly.
- name: "Restore cache for cabal-store"
uses: actions/cache/restore@v4
id: restore-cabal-store
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: cabal-store-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ matrix.variant }}-${{ env.MONTHNUM }}-${{ hashFiles('dependencies.txt') }}
restore-keys: |
cabal-store-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ matrix.variant }}-${{ env.MONTHNUM }}-${{ hashFiles('dependencies.txt') }}
cabal-store-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ matrix.variant }}-${{ env.MONTHNUM }}-
- name: Build dependencies
id: build-dependencies
run: cabal build --only-dependencies all -j
# Save the cabal store cache if the dependencies were succesfully built,
# even if subsequent consensus builds/tests/benchmarks could fail. This
# should shave off some running time because dependencies don't have to be
# rebuilt if any of the later steps fail and the job has to be re-run.
#
# See https://github.com/actions/cache/tree/v3/save#always-save-cache.
- name: "Save cache for cabal-store"
uses: actions/cache/save@v4
id: save-cabal-store
if: steps.build-dependencies.outcome == 'success' && steps.restore-cabal-store.outputs.cache-hit != 'true'
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: ${{ steps.restore-cabal-store.outputs.cache-primary-key }}
- name: Build projects [build]
run: cabal build all -j
- name: Test
if: matrix.test-set == 'all'
run: cabal test all -j --test-show-details=streaming
- name: Test (NoThunks-safe tests only)
if: matrix.test-set == 'no-thunks-safe'
run: cabal test ouroboros-consensus:consensus-test ouroboros-consensus:doctest ouroboros-consensus:infra-test ouroboros-consensus:storage-test ouroboros-consensus-cardano:byron-test ouroboros-consensus-cardano:shelley-test ouroboros-consensus-diffusion:infra-test ouroboros-consensus-protocol:protocol-test -j --test-show-details=streaming
- name: Identify benchmark executables
run: |
cp $(cabal list-bin mempool-bench) mempool-bench
- name: Upload benchmark executables
uses: actions/upload-artifact@v4
with:
name: benchmark-exes-${{ runner.os }}-${{ matrix.ghc }}
path: mempool-bench
retention-days: 10
# NB: build the haddocks at the end to avoid unecessary recompilations.
# We build the haddocks only for one GHC version.
- name: Build Haddock documentation
if: |
github.event_name == 'push'
&& github.ref == 'refs/heads/main'
&& matrix.ghc=='9.6.6'
run: |
# need for latex, dvisvgm and standalone
sudo apt install texlive-latex-extra texlive-latex-base
# cabal-docspec doesn't work with XDG https://github.com/phadej/cabal-extras/issues/136
sed -i 's_-- store-dir:_store-dir: /home/runner/.local/state/cabal/store_g' ~/.config/cabal/config
export CABAL_CONFIG=~/.config/cabal/config
./scripts/docs/haddocks.sh
tar vzcf haddocks.tgz ./docs/website/static/haddocks
- name: Upload haddocks as an artifact
if: |
github.event_name == 'push'
&& github.ref == 'refs/heads/main'
&& matrix.ghc=='9.6.6'
uses: actions/upload-artifact@v4
with:
name: haddocks
path: haddocks.tgz
retention-days: 1
benchmarks:
name: Run benchmarks
needs: build-test-bench-haddocks
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ghc: ["8.10.7", "9.6.6", "9.10.1"]
steps:
- uses: actions/checkout@v4
- name: Install base libraries
uses: input-output-hk/actions/base@latest
with:
use-sodium-vrf: false
- name: Download benchmark executables
uses: actions/download-artifact@v4
with:
name: benchmark-exes-${{ runner.os }}-${{ matrix.ghc }}
- name: Set permissions for benchmark executables
run: |
chmod u+x mempool-bench
- name: Create baseline-benchmark
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
./mempool-bench \
--timeout=60 --csv mempool-benchmarks.csv \
+RTS -T
# TODO: we only care about saving the baseline results when we run on the
# main branch. However we need to restore the cache when we run the
# benchmarks during PRs. The caching mechanism of GitHub actions does not
# allow not to save a cache entry.
#
# The `run_id` is only relevant to store a new benchmarking result when we
# run on the `main` branch. If we run this workflow in the context of a PR,
# then we will save the same results we just restored.
- name: Cache benchmark baseline results
uses: actions/cache@v4
with:
path: baseline-mempool-benchmarks.csv
key: baseline-mempool-benchmarks-${{ runner.os }}-${{ matrix.ghc }}-${{ github.run_id }}
restore-keys: baseline-mempool-benchmarks-${{ runner.os }}-${{ matrix.ghc }}
# We only update the cache if we just ran a benchmark on main.
- name: Copy baseline-benchmark to cache
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: cp mempool-benchmarks.csv baseline-mempool-benchmarks.csv
# TODO: this will be necessary when we publish the benchmarks results.
# - name: Upload mempool benchmark baseline results
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# uses: actions/upload-artifact@v4
# with:
# name: baseline-mempool-benchmarks
# path: baseline-mempool-benchmarks.csv
# The `fail-if-slower` value is determined ad-hoc based on the variability
# we observed in our benchmarks.
- name: Run mempool benchmarks on pull requests
if: ${{ github.event_name == 'pull_request' }}
run: |
if [ -f baseline-mempool-benchmarks.csv ]; then
./mempool-bench \
--timeout=60 --baseline baseline-mempool-benchmarks.csv \
--fail-if-slower 100 \
+RTS -T
else
echo "No baseline benchmarks found. This likely happened when adding a new GHC version to the build matrix."
echo "Benchmarks comparison skipped."
fi
deploy-documentation:
name: Deploy documentation to GitHub Pages
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: build-test-bench-haddocks
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./docs/website
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
cache-dependency-path: './docs/website/yarn.lock'
- uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
accept-flake-config = true
- name: Build PDFs (Consensus report)
run: |
nix build -L .#consensus-pdfs
cp -r --no-preserve=mode,ownership result/ static/pdfs
- name: Download haddocks
uses: actions/download-artifact@v4
with:
name: haddocks
- name: Copy haddocks
run: |
cd ../../
tar vzxf haddocks.tgz
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build website
run: yarn build
- uses: actions/upload-pages-artifact@v3
with:
path: ./docs/website/build
- name: Deploy
id: deployment
uses: actions/deploy-pages@v4
# https://github.com/actions/deploy-pages
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}