-
Notifications
You must be signed in to change notification settings - Fork 11
295 lines (242 loc) · 9.19 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
---
name: CI
on:
push:
branches:
- main
tags:
- '*'
pull_request:
jobs:
cache-minimal-nix-dependencies:
name: Cache minimal Nix dependencies
runs-on: ubuntu-latest
needs: []
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Install Nix
uses: cachix/install-nix-action@v23
with:
extra_nix_config: |
## Access token to avoid triggering GitHub's rate limiting.
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Setup Nix caches
uses: cachix/cachix-action@v12
with:
name: tweag-cooked-validators
## This auth token will give write access to the cache, meaning that
## everything that happens in CI will be pushed at the end of the job.
authToken: '${{ secrets.CACHIX_TWEAG_COOKED_VALIDATORS_AUTH_TOKEN }}'
- name: Build Nix CI environment
run: |
nix develop .#ci --command true
cache-all-nix-dependencies:
name: Cache all Nix dependencies
runs-on: ubuntu-latest
needs: cache-minimal-nix-dependencies
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Install Nix
uses: cachix/install-nix-action@v23
with:
extra_nix_config: |
## Access token to avoid triggering GitHub's rate limiting.
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Setup Nix caches
uses: cachix/cachix-action@v12
with:
name: tweag-cooked-validators
## This auth token will give write access to the cache, meaning that
## everything that happens in CI will be pushed at the end of the job.
authToken: '${{ secrets.CACHIX_TWEAG_COOKED_VALIDATORS_AUTH_TOKEN }}'
- name: Build all Nix environments
run: |
## REVIEW: There might be a way to just build all the devShells? Also,
## we might want to consider building all the package dependencies?
nix develop .#ci --command true
nix develop --command true
build-and-test:
name: Build and run tests
runs-on: ubuntu-latest
needs: cache-minimal-nix-dependencies
steps:
- name: Check out repository code (from PR).
uses: actions/checkout@v3
- name: Install Nix
uses: cachix/install-nix-action@v23
with:
extra_nix_config: |
## Access token to avoid triggering GitHub's rate limiting.
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Setup Nix caches
uses: cachix/cachix-action@v12
with:
name: tweag-cooked-validators
## No auth token: read only cache.
## Example from
## https://github.com/actions/cache/blob/ac25611caef967612169ab7e95533cf932c32270/examples.md#haskell---cabal
- name: Accessing the Cabal cache
uses: actions/cache@v3
with:
path: |
~/.cabal/packages
~/.cabal/store
dist-newstyle
key: ${{ runner.os }}-${{ hashFiles('**/*.cabal', '**/cabal.project', '**/cabal.project.freeze', 'flake.nix', 'flake.lock') }}-build-and-test
## Steps below run a certain program and creates two files:
## `${proj}-${step}.res` and `${proj}-${step}.out`. The former contains a
## string encoding the return code of the tool whereas the latter contains
## a human-readable description of what happened.
##
## The point of this is that we will execute these steps but we "succeed"
## iff the build is ok. Another job will then check the resulting files
## for their exit codes. This is ugly but it ensures that the `cabal
## build` gets cached even if tests fail, which means we save a lot of
## time (and CI runner money) in the long run.
##
- name: Build and run tests
run: |
nix develop .#ci --command bash -c '
## NOTE: `-u` is here to help us avoid making mistakes.
## `-x` is here to help with debugging.
##
## NOTE: `-o pipefail` is important for the semantics of this
## script, because with pipe the result of `cabal build` and `cabal
## run tests` through `tee`. Without `-o pipefail`, this succeeds if
## and only if the `tee` command succeeds, while with `-o pipefail`
## this succeeds if and only if all the commands succeed, which is
## what we want.
set -xuo pipefail
cabal_build_ok=true
cabal update
echo "Running \`cabal build\`"
cabal_res=0
cabal build | tee cabal-build.out
cabal_res=$?
echo "cabal_build:$cabal_res" > cabal-build.res
if [ $cabal_res -ne 0 ]; then
cabal_build_ok=false
fi
echo "Running \`cabal run tests\`"
cabal_res=0
cabal run tests | tee cabal-test.out
cabal_res=$?
echo "run_cabal_test:$cabal_res" > cabal-test.res
if ! $cabal_build_ok; then
exit 1
fi
'
- name: Upload build and test outputs
uses: actions/upload-artifact@v3
with:
name: cooked-validators-checks
path: |
./*.out
./*.res
check-result:
name: Check tests output
runs-on: ubuntu-latest
needs: build-and-test
steps:
- name: Access build and test outputs
uses: actions/download-artifact@v3
with:
name: cooked-validators-checks
- name: Check tests output
run: |
is_ok=true
for step in cabal-build cabal-test; do
echo "!! output from $step"
cat $step.out
res=$(cat $step.res | cut -d':' -f2)
if [ "$res" -ne 0 ]; then
is_ok=false
fi
done
## Because there will be a lot of tests, we print a summary of the
## results
echo "Summary of results (1 is failure)"
cat cabal-build.res cabal-test.res
if $is_ok; then
exit 0
else
exit 1
fi
build-and-deploy-documentation:
name: Build and deploy documentation
runs-on: ubuntu-latest
needs: cache-minimal-nix-dependencies
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Install Nix
uses: cachix/install-nix-action@v23
with:
extra_nix_config: |
## Access token to avoid triggering GitHub's rate limiting.
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Setup Nix caches
uses: cachix/cachix-action@v12
with:
name: tweag-cooked-validators
## No auth token: read only cache.
## Example from
## https://github.com/actions/cache/blob/ac25611caef967612169ab7e95533cf932c32270/examples.md#haskell---cabal
- name: Accessing the Cabal cache
uses: actions/cache@v3
with:
path: |
~/.cabal/packages
~/.cabal/store
dist-newstyle
key: ${{ runner.os }}-${{ hashFiles('**/*.cabal', '**/cabal.project', '**/cabal.project.freeze', 'flake.nix', 'flake.lock') }}-haddock
- name: Build documentation
run: |
nix develop .#ci --command bash -c '
## NOTE: `-e` and `-u` are here to help us avoid making mistakes.
## `-x` is here to help with debugging.
set -eux
cabal update
cabal haddock \
--haddock-hyperlink-source \
--haddock-quickjump \
--haddock-html-location='https://hackage.haskell.org/package/$pkg-$version/docs' \
cooked-validators
mkdir -p docs
cp --force --recursive dist-newstyle/build/*/ghc-*/cooked-validators-*/doc/html/cooked-validators/* docs
'
- name: Upload documentation as artifact
uses: actions/upload-artifact@v3
with:
name: documentation
path: ./docs
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.ref == 'refs/heads/main' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
run-and-cache-flake-checks:
name: Run and cache flake checks
runs-on: ubuntu-latest
needs: []
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Install Nix
uses: cachix/install-nix-action@v23
with:
extra_nix_config: |
## Access token to avoid triggering GitHub's rate limiting.
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Setup Nix caches
uses: cachix/cachix-action@v12
with:
name: tweag-cooked-validators
## This auth token will give write access to the cache, meaning that
## everything that happens in CI will be pushed at the end of the job.
authToken: '${{ secrets.CACHIX_TWEAG_COOKED_VALIDATORS_AUTH_TOKEN }}'
- name: Run flake checks
run: nix flake check --print-build-logs