streamly/bin/run-ci.sh
2022-11-01 16:37:31 +05:30

335 lines
8.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# See dev/ci-tests.md
# TODO: (1) Detect if nix is available otherwise run with plain cabal,
# (2) Detect the platform and run tests applicable to the platform, (3)
# add a test for windows/msys
# TODO: tee the output to a log file
SCRIPT_DIR=$(cd "$(dirname "$0")" || exit; pwd)
SCRIPT_NAME=$(basename "$0")
CABAL_BUILD_OPTIONS="--flag limit-build-mem"
#------------------------------------------------------------------------------
# Prime version (GHC 8.10)
#------------------------------------------------------------------------------
# XXX take these from command line
GHC_PRIME_NIX="ghc922"
GHC_PRIME_VER="9.2.2"
JOBS=1
# Without cabal project file, it will not run any tests
# XXX Added DISABLE_SDIST_BUILD because of a cabal issue, need to remove it
ghc_prime_dist () {
nix-shell \
--argstr compiler "$GHC_PRIME_NIX" \
--run "\
packcheck.sh cabal-v2 \
GHCVER=$GHC_PRIME_VER \
CABAL_BUILD_OPTIONS=\"$CABAL_BUILD_OPTIONS --jobs=$JOBS\" \
CABAL_DISABLE_DEPS=y \
DISABLE_SDIST_BUILD=y \
CABAL_CHECK_RELAX=y"
}
# With cabal.project file, it will run the tests
# XXX Added DISABLE_SDIST_BUILD because of a cabal issue, need to remove it
ghc_prime_dist_tests () {
nix-shell \
--argstr compiler "$GHC_PRIME_NIX" \
--run "\
packcheck.sh cabal-v2 \
GHCVER=$GHC_PRIME_VER \
CABAL_BUILD_OPTIONS=\"$CABAL_BUILD_OPTIONS --jobs=$JOBS\" \
CABAL_PROJECT=cabal.project \
CABAL_DISABLE_DEPS=y \
DISABLE_SDIST_BUILD=y \
CABAL_CHECK_RELAX=y"
}
# With stack.yaml file, it will run the tests
ghc_prime_dist_tests_stack () {
nix-shell \
--argstr compiler "$GHC_PRIME_NIX" \
--run "\
packcheck.sh stack \
GHCVER=$GHC_PRIME_VER \
STACK_BUILD_OPTIONS=\"--jobs $JOBS --system-ghc\" \
STACK_YAML=stack.yaml"
}
# build-all, Werror, test, inspection, fusion-plugin. Note, inspection
# requires fusion-plugin.
PERF_FLAGS="--flag inspection --flag fusion-plugin"
ghc_prime_perf () {
nix-shell \
--argstr compiler "$GHC_PRIME_NIX" \
--argstr c2nix "--flag inspection" \
--run "\
bin/test-runner --cabal-build-options \
\"--jobs=$JOBS --project-file cabal.project.Werror $PERF_FLAGS\";\
bin/bench-runner --cabal-build-options \
\"--jobs=$JOBS --project-file cabal.project.Werror $PERF_FLAGS\" \
--quick --raw;"
}
ghc_prime_O0 () {
nix-shell \
--argstr compiler "$GHC_PRIME_NIX" \
--run "\
bin/test-runner --cabal-build-options \
\"--jobs=$JOBS --project-file cabal.project.O0\""
}
#------------------------------------------------------------------------------
# Check warnings, docs
#------------------------------------------------------------------------------
# XXX avoid rebuilding if nothing has changed in the source
# XXX run hlint only on changed files
lint () {
packcheck.sh cabal \
HLINT_OPTIONS="lint --cpp-include=src --cpp-include=test" \
HLINT_TARGETS="src test benchmark"
}
werror () {
nix-shell \
--argstr compiler "$GHC_PRIME_NIX" \
--run "cabal build --project-file cabal.project.Werror-nocode all"
}
ghc_prime_Werror () {
nix-shell \
--argstr compiler "$GHC_PRIME_NIX" \
--run "cabal build $CABAL_BUILD_OPTIONS --jobs=$JOBS --project-file cabal.project.Werror --enable-tests --enable-benchmarks all"
}
ghc_prime_doctests () {
nix-shell \
--argstr compiler "$GHC_PRIME_NIX" \
--run "cabal build $CABAL_BUILD_OPTIONS --jobs=$JOBS --project-file cabal.project.doctest all && cabal-docspec --timeout 60"
}
#------------------------------------------------------------------------------
# coverage
#------------------------------------------------------------------------------
# To upload the results to coveralls.io using hpc-coveralls
# hpc-coveralls --repo-token="$REPO_TOKEN" --coverage-mode=StrictlyFullLines
ghc_prime_coverage () {
nix-shell \
--argstr compiler "$GHC_PRIME_NIX" \
--run "bin/test-runner --cabal-build-options \"--jobs=$JOBS\" --coverage"
}
#------------------------------------------------------------------------------
# Flags
#------------------------------------------------------------------------------
ghc_prime_dev_test () {
nix-shell \
--argstr compiler "$GHC_PRIME_NIX" \
--run "\
bin/test-runner --cabal-build-options \
\"--jobs=$JOBS --flag dev\""
}
ghc_prime_dev_perf () {
nix-shell \
--argstr compiler "$GHC_PRIME_NIX" \
--run "\
bin/bench-runner --cabal-build-options \
\"--jobs=$JOBS --flag dev $PERF_FLAGS\" --quick --raw"
}
ghc_prime_debug () {
nix-shell \
--argstr compiler "$GHC_PRIME_NIX" \
--run "bin/test-runner --cabal-build-options \"--jobs=$JOBS --flag debug\""
}
#------------------------------------------------------------------------------
# Other GHC versions
#------------------------------------------------------------------------------
# build-all only
# $1 883
# $2 8.8.3
ghc () {
nix-shell \
--argstr compiler "ghc$1" \
--run "\
packcheck.sh cabal-v2 \
GHCVER=$2 \
CABAL_BUILD_OPTIONS=\"$CABAL_BUILD_OPTIONS --jobs=$JOBS\" \
CABAL_DISABLE_DEPS=y \
CABAL_CHECK_RELAX=y \
DISABLE_SDIST_BUILD=y \
DISABLE_TEST=y \
DISABLE_DOCS=y"
}
ghc901 () { ghc 901 9.0.1; }
ghc884 () { ghc 884 8.8.4; }
#------------------------------------------------------------------------------
# GHC Head
#------------------------------------------------------------------------------
ghcHEAD () {
nix-shell \
--argstr compiler "ghcHEAD" \
--run "\
packcheck.sh cabal-v2 \
GHCVER=9.3 \
CABAL_BUILD_OPTIONS="$CABAL_BUILD_OPTIONS --jobs=$JOBS" \
CABAL_CHECK_RELAX=y \
DISABLE_SDIST_BUILD=y \
CABAL_BUILD_OPTIONS=\"--allow-newer --project-file cabal.project.ghc-head"
}
#------------------------------------------------------------------------------
# ghcjs
#------------------------------------------------------------------------------
# Use the following nix expression for ghcjs
# nix-env -f https://github.com/composewell/nixpkgs/archive/refs/tags/22.05-composewell.tar.gz -iA pkgs.haskell.compiler.ghcjs
ghcjs () {
# We don't pass 'CABAL_BUILD_OPTIONS="--flag limit-build-mem"' here as
# ghcjs requires more memory to build. Adding a conditional for ghcjs in
# the cabal file is a maintainence overhead.
packcheck.sh cabal-v2 \
GHCVER=8.10.7 \
CABAL_BUILD_OPTIONS="--jobs=$JOBS" \
CABAL_CHECK_RELAX=y \
DISABLE_SDIST_BUILD=y \
DISABLE_TEST=y \
DISABLE_DOCS=y \
ENABLE_GHCJS=y
}
#-----------------------------------------------------------------------------
# Read command line
#-----------------------------------------------------------------------------
RELEASE_CI_TARGETS="\
ghc_prime_dist \
ghc_prime_dist_tests \
ghc_prime_dev_test \
ghc_prime_perf \
ghc_prime_O0 \
ghc_prime_Werror \
ghc_prime_doctests \
ghc_prime_coverage \
ghc_prime_debug \
ghc901 \
ghc884 \
ghcjs \
lint"
# XXX Include flaky tests flag in manual tests
ALL_TARGETS="\
$RELEASE_CI_TARGETS \
ghc_prime_dist_tests_stack \
ghc_prime_dev_perf \
ghcHEAD \
werror"
print_targets () {
echo "Available targets: all $ALL_TARGETS"
}
print_help () {
echo "Usage:"
echo "$SCRIPT_NAME --targets <space separated target names>"
echo "$SCRIPT_NAME --release"
print_targets
exit
}
RELEASE_CI=0
while test -n "$1"
do
case $1 in
# flags
-h|--help|help) print_help ;;
--release) RELEASE_CI=1; shift; break ;;
# options with arguments
--targets) shift; TARGETS=$1; shift ;;
--) shift; break ;;
-*) echo "Unknown flags: $*"; echo; print_help ;;
*) break ;;
esac
done
if test -z "$TARGETS"
then
if test "$RELEASE_CI" -eq 1
then
TARGETS="$RELEASE_CI_TARGETS"
else
echo "No targets specified"
print_help
fi
else
if test "$RELEASE_CI" -eq 1
then
echo "--targets and --release cannot be used together"
print_help
fi
fi
has_item () {
for i in $1
do
if test "$i" = "$2"
then
echo "$i"
break
fi
done
}
for i in $TARGETS
do
if test "$(has_item "$ALL_TARGETS" "$i")" != "$i"
then
echo "Unrecognized target: $i"
print_help
fi
done
if test "$(has_item "$TARGETS" help)" = "help"
then
print_targets
exit
fi
if test "$(has_item "$TARGETS" all)" = "all"
then
TARGETS="$ALL_TARGETS"
fi
# $1: msg
show_step () {
echo
echo "--------------------------------------------------"
echo "$1"
echo "--------------------------------------------------"
}
for i in $TARGETS
do
show_step "$i"
$i || { echo "$i failed."; exit 1; }
done