Skip to content

Commit ca7a938

Browse files
committed
Check the GHC and cabal-install version which are used to build the release
1 parent 976e0f9 commit ca7a938

File tree

1 file changed

+61
-11
lines changed

1 file changed

+61
-11
lines changed

.gitlab/ci.sh

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,70 @@ set -Eeuo pipefail
44

55
source "$CI_PROJECT_DIR/.gitlab/common.sh"
66

7-
## Figure out how to get the Haskell toolchain.
8-
9-
# For backport, the centos image no longer has the right GHC version, so use
10-
# ghcup.
11-
if [[ -f /etc/os-release && "$(grep ^ID /etc/os-release)" =~ "centos" ]]; then
12-
. "$CI_PROJECT_DIR/.gitlab/ghcup.sh"
13-
# All the other ones are fine.
14-
elif [[ "$(uname)" == "Linux" ]]; then
15-
export PATH="/opt/ghc/${GHC_VERSION}/bin:${PATH}"
16-
# Not all runners use ci-images, so ghcup is used.
7+
# Required arguments to the script
8+
: "${GHC_VERSION:?Need to set GHC_VERSION}"
9+
: "${CABAL_INSTALL_VERSION:?Need to set CABAL_INSTALL_VERSION}"
10+
11+
# If GHC is set, extract its directory and add it to PATH
12+
# The linux images set the GHC variable to specify the location of the GHC installation.
13+
if [[ -n "${GHC:-}" ]]; then
14+
echo "GHC variable is set to: $GHC"
15+
export PATH="$(dirname "$GHC"):$PATH"
16+
else
17+
GHC="ghc"
18+
fi
19+
20+
echo "Checking toolchain versions..."
21+
22+
# GHC check
23+
ghc_version_ok=false
24+
if command -v ghc &>/dev/null; then
25+
current_ghc_version=$(ghc --numeric-version)
26+
if [[ "$current_ghc_version" == "$GHC_VERSION" ]]; then
27+
ghc_version_ok=true
28+
else
29+
echo "Wrong GHC version: found $current_ghc_version, expected $GHC_VERSION"
30+
fi
1731
else
18-
. "$CI_PROJECT_DIR/.gitlab/ghcup.sh"
32+
echo "GHC executable '$GHC' not found on PATH"
1933
fi
2034

35+
# cabal check
36+
cabal_version_ok=false
37+
if command -v cabal &>/dev/null; then
38+
current_cabal_version=$(cabal --numeric-version)
39+
if [[ "$current_cabal_version" == "$CABAL_INSTALL_VERSION" ]]; then
40+
cabal_version_ok=true
41+
else
42+
echo "Wrong cabal version: found $current_cabal_version, expected $CABAL_INSTALL_VERSION"
43+
fi
44+
else
45+
echo "cabal not found on PATH"
46+
fi
47+
48+
# If either is wrong, install via ghcup
49+
if ! $ghc_version_ok || ! $cabal_version_ok; then
50+
echo "Installing correct GHC and/or cabal via ghcup..."
51+
. "$CI_PROJECT_DIR/.gitlab/ghcup.sh"
52+
fi
53+
54+
# Final verification (ghc and cabal must now be on PATH)
55+
echo "Verifying installed versions..."
56+
57+
actual_ghc_version=$(ghc --numeric-version)
58+
actual_cabal_version=$(cabal --numeric-version)
59+
60+
if [[ "$actual_ghc_version" != "$GHC_VERSION" ]]; then
61+
fail "Incorrect GHC version (actual: $actual_ghc_version, expected: $GHC_VERSION)"
62+
fi
63+
64+
if [[ "$actual_cabal_version" != "$CABAL_INSTALL_VERSION" ]]; then
65+
fail "Incorrect cabal version (actual: $actual_cabal_version, expected: $CABAL_INSTALL_VERSION)"
66+
fi
67+
68+
echo "Using GHC version: $actual_ghc_version"
69+
echo "Using cabal-install version: $actual_cabal_version"
70+
2171
export CABAL_DIR="$CI_PROJECT_DIR/cabal"
2272

2373
case "$(uname)" in

0 commit comments

Comments
 (0)