on master help sign in
Add a script to run CIs locally using nix/packcheck
commit1a51cab61aa1e577d128710111f7aa4c6e5a5036 authorHarendra Kumar <harendra@composewell.com> dateTue 9 Feb 2021, 15:42 (6 years ago) parent521d9cf
2 files changed+155
bin/run-ci.sh+154 streamly.cabal+1
bin/run-ci.shnew file+154
@@ -0,0 +1,154 @@
1+#!/usr/bin/env bash
2+
3+# TODO: (1) Detect if nix is available otherwise run with plain cabal,
4+# (2) Detect the platform and run tests applicable to the platform, (3)
5+# add a test for windows/msys
6+
7+SCRIPT_DIR=$(cd `dirname $0`; pwd)
8+source $SCRIPT_DIR/build-lib.sh
9+
10+#------------------------------------------------------------------------------
11+# GHC 8.10
12+#------------------------------------------------------------------------------
13+
14+# build-all, Werror, test, inspection, fusion-plugin. Note, inspection
15+# requires fusion-plugin.
16+
17+basic () {
18+ nix-shell \
19+ --argstr compiler "ghc8101" \
20+ --argstr c2nix "--flag inspection" \
21+ --run "\
22+ packcheck cabal-v2 \
23+ GHCVER=8.10.1 \
24+ CABAL_DISABLE_DEPS=y \
25+ CABAL_CHECK_RELAX=y \
26+ DISABLE_SDIST_BUILD=y \
27+ CABAL_PROJECT=cabal.project.ci \
28+ CABAL_BUILD_OPTIONS=\"--flag inspection --flag fusion-plugin\""
29+ }
30+
31+#------------------------------------------------------------------------------
32+# hlint
33+#------------------------------------------------------------------------------
34+
35+# XXX avoid rebuilding if nothing has changed in the source
36+# XXX run hlint only on changed files
37+hlint () {
38+ packcheck cabal \
39+ HLINT_OPTIONS="lint --cpp-include=src --cpp-include=test" \
40+ HLINT_TARGETS="src test benchmark"
41+}
42+
43+#------------------------------------------------------------------------------
44+# coverage
45+#------------------------------------------------------------------------------
46+
47+coverage () {
48+ nix-shell \
49+ --argstr compiler "ghc8101" \
50+ --run "bin/test.sh --coverage"
51+}
52+
53+# To upload the results to coveralls.io using hpc-coveralls
54+# hpc-coveralls --repo-token="$REPO_TOKEN" --coverage-mode=StrictlyFullLines
55+
56+#------------------------------------------------------------------------------
57+# GHC 8.8
58+#------------------------------------------------------------------------------
59+
60+# chart builds from the nix cache for 8.8, 8.10 requires building
61+# XXX Use a separate build-dir for this
62+# build-all only, throw in most flags except fusion-plugin, inspection, opt
63+flags () {
64+ nix-shell \
65+ --argstr compiler "ghc883" \
66+ --argstr c2nix "--flag dev" \
67+ --run "\
68+ packcheck cabal-v2 \
69+ GHCVER=8.8.3 \
70+ CABAL_DISABLE_DEPS=y \
71+ CABAL_CHECK_RELAX=y \
72+ DISABLE_SDIST_BUILD=y \
73+ DISABLE_TEST=y \
74+ DISABLE_DOCS=y \
75+ DISABLE_BENCH=y \
76+ CABAL_BUILD_OPTIONS=\"--flag streamk --flag debug --flag use-c-malloc --flag dev\""
77+}
78+
79+# build-all only
80+# $1 883
81+# $2 8.8.3
82+ghc () {
83+ nix-shell \
84+ --argstr compiler "ghc$1" \
85+ --run "\
86+ packcheck cabal-v2 \
87+ GHCVER=$2 \
88+ CABAL_DISABLE_DEPS=y \
89+ CABAL_CHECK_RELAX=y \
90+ DISABLE_SDIST_BUILD=y \
91+ DISABLE_TEST=y \
92+ DISABLE_DOCS=y "
93+}
94+
95+ghc883 () { ghc 883 8.8.3; }
96+ghc865 () { ghc 865 8.6.5; }
97+ghc844 () { ghc 865 8.4.4; }
98+
99+#------------------------------------------------------------------------------
100+# ghcjs
101+#------------------------------------------------------------------------------
102+
103+#nix-shell \
104+# --argstr compiler "ghcjs" \
105+# --run "\
106+# packcheck cabal-v2 \
107+# GHCVER=8.6.0 \
108+# CABAL_DISABLE_DEPS=y \
109+# CABAL_CHECK_RELAX=y \
110+# DISABLE_SDIST_BUILD=y \
111+# DISABLE_TEST=y \
112+# DISABLE_DOCS=y \
113+# ENABLE_GHCJS=y " || exit 1
114+
115+#-----------------------------------------------------------------------------
116+# Read command line
117+#-----------------------------------------------------------------------------
118+
119+while test -n "$1"
120+do
121+ case $1 in
122+ -h|--help|help) print_help ;;
123+ # options with arguments
124+ --targets) shift; TARGETS=$1; shift ;;
125+ --) shift; break ;;
126+ -*|--*) echo "Unknown flags: $*"; echo; print_help ;;
127+ *) break ;;
128+ esac
129+done
130+
131+ALL_TARGETS="all basic hlint coverage flags ghc883 ghc864 ghc844"
132+
133+if test "$(has_item "$TARGETS" help)" = "help"
134+then
135+ echo "Available targets: $ALL_TARGETS"
136+ exit
137+fi
138+
139+if test "$(has_item "$TARGETS" help)" = "all"
140+then
141+ TARGETS="$ALL_TARGETS"
142+fi
143+
144+if test -z "$TARGETS"
145+then
146+ echo "Usage: $0 --targets <space separated target names>"
147+ echo "Available targets: $ALL_TARGETS"
148+ exit
149+fi
150+
151+for i in $TARGETS
152+do
153+ $i || { echo "$i failed."; exit 1; }
154+done
streamly.cabal+1
@@ -124,6 +124,7 @@ extra-source-files:
124124 bin/bench-exec-one.sh
125125 bin/build-lib.sh
126126 bin/ghc.sh
127+ bin/run-ci.sh
127128 bin/mk-hscope.sh
128129 bin/mk-tags.sh
129130 bin/targets.sh