on master help sign in
streamly/bin/run-ci.sh
334 lines 8.7 kB history raw
1#!/usr/bin/env bash
3# See dev/ci-tests.md
5# TODO: (1) Detect if nix is available otherwise run with plain cabal,
6# (2) Detect the platform and run tests applicable to the platform, (3)
7# add a test for windows/msys
9# TODO: tee the output to a log file
11SCRIPT_DIR=$(cd "$(dirname "$0")" || exit; pwd)
12SCRIPT_NAME=$(basename "$0")
14CABAL_BUILD_OPTIONS="--flag limit-build-mem"
16#------------------------------------------------------------------------------
17# Prime version (GHC 8.10)
18#------------------------------------------------------------------------------
20# XXX take these from command line
21GHC_PRIME_NIX="ghc922"
22GHC_PRIME_VER="9.2.2"
23JOBS=1
25# Without cabal project file, it will not run any tests
26# XXX Added DISABLE_SDIST_BUILD because of a cabal issue, need to remove it
27ghc_prime_dist () {
28 nix-shell \
29 --argstr compiler "$GHC_PRIME_NIX" \
30 --run "\
31 packcheck.sh cabal-v2 \
32 GHCVER=$GHC_PRIME_VER \
33 CABAL_BUILD_OPTIONS=\"$CABAL_BUILD_OPTIONS --jobs=$JOBS\" \
34 CABAL_DISABLE_DEPS=y \
35 DISABLE_SDIST_BUILD=y \
36 CABAL_CHECK_RELAX=y"
39# With cabal.project file, it will run the tests
40# XXX Added DISABLE_SDIST_BUILD because of a cabal issue, need to remove it
41ghc_prime_dist_tests () {
42 nix-shell \
43 --argstr compiler "$GHC_PRIME_NIX" \
44 --run "\
45 packcheck.sh cabal-v2 \
46 GHCVER=$GHC_PRIME_VER \
47 CABAL_BUILD_OPTIONS=\"$CABAL_BUILD_OPTIONS --jobs=$JOBS\" \
48 CABAL_PROJECT=cabal.project \
49 CABAL_DISABLE_DEPS=y \
50 DISABLE_SDIST_BUILD=y \
51 CABAL_CHECK_RELAX=y"
54# With stack.yaml file, it will run the tests
55ghc_prime_dist_tests_stack () {
56 nix-shell \
57 --argstr compiler "$GHC_PRIME_NIX" \
58 --run "\
59 packcheck.sh stack \
60 GHCVER=$GHC_PRIME_VER \
61 STACK_BUILD_OPTIONS=\"--jobs $JOBS --system-ghc\" \
62 STACK_YAML=stack.yaml"
65# build-all, Werror, test, inspection, fusion-plugin. Note, inspection
66# requires fusion-plugin.
68PERF_FLAGS="--flag inspection --flag fusion-plugin"
70ghc_prime_perf () {
71 nix-shell \
72 --argstr compiler "$GHC_PRIME_NIX" \
73 --argstr c2nix "--flag inspection" \
74 --run "\
75 bin/test-runner --cabal-build-options \
76 \"--jobs=$JOBS --project-file cabal.project.Werror $PERF_FLAGS\";\
77 bin/bench-runner --cabal-build-options \
78 \"--jobs=$JOBS --project-file cabal.project.Werror $PERF_FLAGS\" \
79 --quick --raw;"
82ghc_prime_O0 () {
83 nix-shell \
84 --argstr compiler "$GHC_PRIME_NIX" \
85 --run "\
86 bin/test-runner --cabal-build-options \
87 \"--jobs=$JOBS --project-file cabal.project.O0\""
90#------------------------------------------------------------------------------
91# Check warnings, docs
92#------------------------------------------------------------------------------
94# XXX avoid rebuilding if nothing has changed in the source
95# XXX run hlint only on changed files
96lint () {
97 packcheck.sh cabal \
98 HLINT_OPTIONS="lint --cpp-include=src --cpp-include=test" \
99 HLINT_TARGETS="src test benchmark"
102werror () {
103 nix-shell \
104 --argstr compiler "$GHC_PRIME_NIX" \
105 --run "cabal build --project-file cabal.project.Werror-nocode all"
108ghc_prime_Werror () {
109 nix-shell \
110 --argstr compiler "$GHC_PRIME_NIX" \
111 --run "cabal build $CABAL_BUILD_OPTIONS --jobs=$JOBS --project-file cabal.project.Werror --enable-tests --enable-benchmarks all"
114ghc_prime_doctests () {
115 nix-shell \
116 --argstr compiler "$GHC_PRIME_NIX" \
117 --run "cabal build $CABAL_BUILD_OPTIONS --jobs=$JOBS --project-file cabal.project.doctest all && cabal-docspec --timeout 60"
120#------------------------------------------------------------------------------
121# coverage
122#------------------------------------------------------------------------------
124# To upload the results to coveralls.io using hpc-coveralls
125# hpc-coveralls --repo-token="$REPO_TOKEN" --coverage-mode=StrictlyFullLines
127ghc_prime_coverage () {
128 nix-shell \
129 --argstr compiler "$GHC_PRIME_NIX" \
130 --run "bin/test-runner --cabal-build-options \"--jobs=$JOBS\" --coverage"
133#------------------------------------------------------------------------------
134# Flags
135#------------------------------------------------------------------------------
137ghc_prime_dev_test () {
138 nix-shell \
139 --argstr compiler "$GHC_PRIME_NIX" \
140 --run "\
141 bin/test-runner --cabal-build-options \
142 \"--jobs=$JOBS --flag dev\""
145ghc_prime_dev_perf () {
146 nix-shell \
147 --argstr compiler "$GHC_PRIME_NIX" \
148 --run "\
149 bin/bench-runner --cabal-build-options \
150 \"--jobs=$JOBS --flag dev $PERF_FLAGS\" --quick --raw"
153ghc_prime_debug () {
154 nix-shell \
155 --argstr compiler "$GHC_PRIME_NIX" \
156 --run "bin/test-runner --cabal-build-options \"--jobs=$JOBS --flag debug\""
159#------------------------------------------------------------------------------
160# Other GHC versions
161#------------------------------------------------------------------------------
163# build-all only
164# $1 883
165# $2 8.8.3
166ghc () {
167 nix-shell \
168 --argstr compiler "ghc$1" \
169 --run "\
170 packcheck.sh cabal-v2 \
171 GHCVER=$2 \
172 CABAL_BUILD_OPTIONS=\"$CABAL_BUILD_OPTIONS --jobs=$JOBS\" \
173 CABAL_DISABLE_DEPS=y \
174 CABAL_CHECK_RELAX=y \
175 DISABLE_SDIST_BUILD=y \
176 DISABLE_TEST=y \
177 DISABLE_DOCS=y"
180ghc901 () { ghc 901 9.0.1; }
181ghc884 () { ghc 884 8.8.4; }
183#------------------------------------------------------------------------------
184# GHC Head
185#------------------------------------------------------------------------------
187ghcHEAD () {
188 nix-shell \
189 --argstr compiler "ghcHEAD" \
190 --run "\
191 packcheck.sh cabal-v2 \
192 GHCVER=9.3 \
193 CABAL_BUILD_OPTIONS="$CABAL_BUILD_OPTIONS --jobs=$JOBS" \
194 CABAL_CHECK_RELAX=y \
195 DISABLE_SDIST_BUILD=y \
196 CABAL_BUILD_OPTIONS=\"--allow-newer --project-file cabal.project.ghc-head"
199#------------------------------------------------------------------------------
200# ghcjs
201#------------------------------------------------------------------------------
203# Use the following nix expression for ghcjs
204# nix-env -f https://github.com/composewell/nixpkgs/archive/refs/tags/22.05-composewell.tar.gz -iA pkgs.haskell.compiler.ghcjs
205ghcjs () {
206 # We don't pass 'CABAL_BUILD_OPTIONS="--flag limit-build-mem"' here as
207 # ghcjs requires more memory to build. Adding a conditional for ghcjs in
208 # the cabal file is a maintainence overhead.
209 packcheck.sh cabal-v2 \
210 GHCVER=8.10.7 \
211 CABAL_BUILD_OPTIONS="--jobs=$JOBS" \
212 CABAL_CHECK_RELAX=y \
213 DISABLE_SDIST_BUILD=y \
214 DISABLE_TEST=y \
215 DISABLE_DOCS=y \
216 ENABLE_GHCJS=y
219#-----------------------------------------------------------------------------
220# Read command line
221#-----------------------------------------------------------------------------
223RELEASE_CI_TARGETS="\
224ghc_prime_dist \
225ghc_prime_dist_tests \
226ghc_prime_dev_test \
227ghc_prime_perf \
228ghc_prime_O0 \
229ghc_prime_Werror \
230ghc_prime_doctests \
231ghc_prime_coverage \
232ghc_prime_debug \
233ghc901 \
234ghc884 \
235ghcjs \
236lint"
238# XXX Include flaky tests flag in manual tests
239ALL_TARGETS="\
240$RELEASE_CI_TARGETS \
241ghc_prime_dist_tests_stack \
242ghc_prime_dev_perf \
243ghcHEAD \
244werror"
246print_targets () {
247 echo "Available targets: all $ALL_TARGETS"
250print_help () {
251 echo "Usage:"
252 echo "$SCRIPT_NAME --targets <space separated target names>"
253 echo "$SCRIPT_NAME --release"
254 print_targets
255 exit
258RELEASE_CI=0
260while test -n "$1"
261do
262 case $1 in
263 # flags
264 -h|--help|help) print_help ;;
265 --release) RELEASE_CI=1; shift; break ;;
266 # options with arguments
267 --targets) shift; TARGETS=$1; shift ;;
268 --) shift; break ;;
269 -*) echo "Unknown flags: $*"; echo; print_help ;;
270 *) break ;;
271 esac
272done
274if test -z "$TARGETS"
275then
276 if test "$RELEASE_CI" -eq 1
277 then
278 TARGETS="$RELEASE_CI_TARGETS"
279 else
280 echo "No targets specified"
281 print_help
282 fi
283else
284 if test "$RELEASE_CI" -eq 1
285 then
286 echo "--targets and --release cannot be used together"
287 print_help
288 fi
289fi
291has_item () {
292 for i in $1
293 do
294 if test "$i" = "$2"
295 then
296 echo "$i"
297 break
298 fi
299 done
302for i in $TARGETS
303do
304 if test "$(has_item "$ALL_TARGETS" "$i")" != "$i"
305 then
306 echo "Unrecognized target: $i"
307 print_help
308 fi
309done
311if test "$(has_item "$TARGETS" help)" = "help"
312then
313 print_targets
314 exit
315fi
317if test "$(has_item "$TARGETS" all)" = "all"
318then
319 TARGETS="$ALL_TARGETS"
320fi
322# $1: msg
323show_step () {
324 echo
325 echo "--------------------------------------------------"
326 echo "$1"
327 echo "--------------------------------------------------"
330for i in $TARGETS
331do
332 show_step "$i"
333 $i || { echo "$i failed."; exit 1; }
334done