forked from CatalaLang/catala
-
Notifications
You must be signed in to change notification settings - Fork 0
333 lines (316 loc) · 12.8 KB
/
ci.yml
File metadata and controls
333 lines (316 loc) · 12.8 KB
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
331
332
333
name: CI
on:
push:
branches: [master]
tags: ["*.*.*"]
workflow_dispatch:
pull_request_target:
# It is important to use `pull_request_target` and not `pull_request` here: it
# means the version of this file from master is used rather than the one from
# the PR. This allows writing to the docker caches, etc. from PRs ; but mind
# that if you attempt modification in a PR, of course.
# don't use the default fetch source, as with 'pull_request_target' that will
# test the target branch only!
env:
GIT_FETCH_REF: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
COLUMNS: "165"
# Ensures the side-by-side diff isn't truncated to less than 80 cols
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
name: Build Catala and generate CI Docker image
runs-on: self-hosted
permissions:
packages: write
outputs:
image: ghcr.io/catalalang/catala@${{ steps.image.outputs.digest }}
version: ${{ steps.describe.outputs.version }}
steps:
- name: Checkout
# This is *only* needed to extract the git version...
# Approaches like proudust/gh-describe@v1 don't work
uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full commit history for 'git describe'
ref: ${{ env.GIT_FETCH_REF }}
- name: Get git-describe version
id: describe
run: |
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
echo "version=$(git describe --tags)" >> "$GITHUB_OUTPUT"
- name: Get an image tag that Docker accepts
id: branch
run: sed 's/[^a-zA-Z0-9-]/-/g; s/^/tag=/' <<<"${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Make build context image
uses: docker/build-push-action@v5
with:
# The default context would fetch the default source (ie master on
# 'pull_request_target' to master >:( ) ; we have already fetched
# anyway so use the current dir
context: .
target: dev-build-context
# Caching using GH cache doesn't work, use registry caching directly
# instead
cache-from: |
type=registry,ref=ghcr.io/catalalang/catala:dev-cache-master
type=registry,ref=ghcr.io/catalalang/catala:dev-cache-${{ steps.branch.outputs.tag }}
cache-to: |
type=registry,ref=ghcr.io/catalalang/catala:dev-cache-${{ steps.branch.outputs.tag }},mode=max
- name: Build and push
id: image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ghcr.io/catalalang/catala:${{ steps.describe.outputs.version }}
build-args: "CATALA_VERSION=${{ steps.describe.outputs.version }}"
labels: org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
cache-from: |
type=registry,ref=ghcr.io/catalalang/catala:build-cache-master
type=registry,ref=ghcr.io/catalalang/catala:build-cache-${{ steps.branch.outputs.tag }}
cache-to: |
type=registry,ref=ghcr.io/catalalang/catala:build-cache-${{ steps.branch.outputs.tag }},mode=max
tests:
name: Run integrated tests
needs: build
runs-on: self-hosted
container:
image: ${{ needs.build.outputs.image }}
options: --user root
steps:
- name: Fix home
# We need to run as root as a Workaround Github actions issues
# (https://github.com/actions/checkout/issues/1014) but need ~ocaml as
# home.
# And we need yet another workaround for git to accept to work with the
# resulting file ownership issues
run: |
HOME=/home/ocaml
sudo sh -c "echo HOME=$HOME >> ${GITHUB_ENV}"
git config --global --add safe.directory /home/ocaml/catala
- name: Check promoted files
run: |
cd /home/ocaml/catala && opam exec -- make check-promoted && git diff --exit-code
- name: Run base tests
if: ${{ always() }}
run: cd /home/ocaml/catala && opam exec -- make unit-tests backend-tests testsuite-base
- name: Run extra tests
if: ${{ always() }}
run: cd /home/ocaml/catala && opam exec -- dune exec -- clerk test tests-extra doc
- name: Generate test report
if: ${{ always() }}
run: |
cd /home/ocaml/catala
opam exec -- dune exec -- clerk report --xml _build/*@test _build/test-*/*@test >report.junit.xml
- name: Test web interpreter
run: |
cd /home/ocaml/catala && opam exec -- dune build @runtest-js
- name: Validate Python runtime
if: ${{ always() }}
run: cd /home/ocaml/catala && opam exec -- make validate-py-runtime
- name: Test Summary
uses: test-summary/action@v2
with:
paths: /home/ocaml/catala/report.junit.xml
if: ${{ always() }}
examples:
name: Build catala-examples and generate artifacts
needs: build
runs-on: self-hosted
container:
image: ${{ needs.build.outputs.image }}
options: --user root
env:
DUNE_PROFILE: release
OPAMSWITCH: /home/ocaml/catala
steps:
- name: Fix home
# Workaround Github actions issue, see
# https://github.com/actions/runner/issues/863
run: sudo sh -c "echo HOME=/home/ocaml >> ${GITHUB_ENV}"
- name: Install LaTeX deps
# This is done late because caching would not benefit compared to
# installation through apk (1,5G upload is slow)
run: sudo apk add typst texlive-xetex texmf-dist-latexextra texmf-dist-binextra texmf-dist-pictures texmf-dist-fontsrecommended font-dejavu groff libpng
# Fewer texmf deps should be required once
# https://gitlab.alpinelinux.org/alpine/aports/-/issues/16190 is fixed
- name: Build Catala extra docs
run: |
cd ~/catala
opam --cli=2.1 exec -- make syntax
opam --cli=2.1 exec -- make doc
- name: Checkout examples repo
# Github fetch action is expected to work for containers, but doesn't
# (permission issues)
run: |
git clone https://github.com/CatalaLang/catala-examples --depth 1 ~/catala-examples -b "${{ github.head_ref || github.ref_name }}" ||
git clone https://github.com/CatalaLang/catala-examples --depth 1 ~/catala-examples
- name: Build examples
run: |
cd ~/catala-examples
. ~/catala/_python_venv/bin/activate && opam --cli=2.1 exec -- make all testsuite
- name: Generate examples test report
if: ${{ always() }}
run: |
cd ~/catala-examples
opam exec -- clerk report --xml _build/clerk_tests/*@test _build/clerk_tests/test-*/*@test >report.junit.xml
- name: Test Summary
uses: test-summary/action@v2
with:
paths: "/home/ocaml/catala-examples/report.junit.xml"
if: ${{ always() }}
- name: Gather all artifacts
run: |
cd
mkdir -p artifacts
mv catala/_build/default/_doc/_html artifacts/api-doc
mv catala/doc/syntax/syntax.pdf artifacts/
mv catala/_build/default/*.html artifacts/
mv catala/_build/default/compiler/web/catala_web_interpreter.bc.js artifacts/catala_web_interpreter.js
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: Catala examples
path: /home/ocaml/artifacts/*
language-server:
name: Build and test the language server
needs: build
runs-on: self-hosted
container:
image: ${{ needs.build.outputs.image }}
options: --user root
env:
DUNE_PROFILE: release
OPAMSWITCH: /home/ocaml/catala
steps:
- name: Fix home
# Workaround Github actions issue, see
# https://github.com/actions/runner/issues/863
run: sudo sh -c "echo HOME=/home/ocaml >> ${GITHUB_ENV}"
- name: Checkout language server repo
# Github fetch action is expected to work for containers, but doesn't
# (permission issues)
run: |
git clone https://github.com/CatalaLang/catala-language-server --depth 1 ~/catala-language-server -b "${{ github.head_ref || github.ref_name }}" ||
git clone https://github.com/CatalaLang/catala-language-server --depth 1 ~/catala-language-server
- name: Build the language server
run: |
cd ~/catala-language-server
opam install conf-npm -y
npm install
opam install . --ignore-constraints-on=catala --ignore-pin-depends --with-test -y
opam exec -- dune runtest
# binaries:
# name: Build static binaries
# runs-on: self-hosted
# if: ${{ github.event_name != 'pull_request_target' }}
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# with:
# fetch-depth: 0 # Need full commit history for 'git describe'
# ref: ${{ env.GIT_FETCH_REF }}
# - name: Get git-describe version
# id: describe
# run: echo "version=$(git describe --tags)" >> "$GITHUB_OUTPUT"
# - name: Build release binaries
# run: |
# mkdir -p artifacts
# export CATALA_VERSION="${{ steps.describe.outputs.version }}"
# ./build_release.sh -C artifacts
# - name: Upload artifacts
# uses: actions/upload-artifact@v4
# with:
# name: Catala binaries
# path: artifacts/*
pages:
name: Publish static content to github-pages
# Doesn't really depend on tests, but we don't want to publish if they fail
needs: [examples, tests] # FIXME: add binaries
# Only triggers on the `master` branch
if: ${{ github.event_name != 'pull_request_target' && github.ref == 'refs/heads/master' }}
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Download artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: artifacts/
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: tree
version: 1.0
- name: Generate HTML index
run: |
cd artifacts
tree -H . -L 1 --noreport --dirsfirst -T 'Catala latest development artifacts' --charset utf-8 -o index.html
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: "artifacts/"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
windows-build:
name: Build Catala on Windows
runs-on: windows-latest
env:
OPAMCONFIRMLEVEL: unsafe-yes
OPAMSWITCH: ${{ github.workspace }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.GIT_FETCH_REF }}
- name: Set up OCaml
uses: ocaml/setup-ocaml@v3
with:
ocaml-compiler: "5.3.0"
opam-local-packages: catala.opam
- name: Pre-install conf-pkg-config
run: |
# Avoids a race: without this, opam install recompiles mingw-w64-shims
# (to add pkgconf shims) while building catala's deps in parallel,
# racing on the GCC shim executable.
opam install conf-pkg-config
- name: Build and install Catala through opam
run: |
opam install ./catala.opam
- name: Run built-in tests
run: |
opam exec -- dune exec -- clerk test tests doc
opam exec -- dune exec -- clerk test tests --backend ocaml -c--disable-warnings --vars CC=x86_64-w64-mingw32-gcc
- name: Clone catala-examples
run: |
$ErrorActionPreference = 'Stop'
$dst = "$env:USERPROFILE\catala-examples"
if (Test-Path $dst) { Remove-Item -Recurse -Force $dst }
git clone https://github.com/CatalaLang/catala-examples --depth 1 $dst -b "${{ github.head_ref || github.ref_name }}" ||
git clone https://github.com/CatalaLang/catala-examples --depth 1 $dst
- name: Run clerk test in catala-examples
run: |
Push-Location "$env:USERPROFILE\catala-examples"
opam exec -- clerk test
Pop-Location