ghcup-hs/.github/scripts/common.sh

150 lines
3.7 KiB
Bash
Raw Normal View History

2022-11-22 11:41:44 +00:00
#!/bin/sh
2023-01-14 13:00:32 +00:00
. .github/scripts/env.sh
2022-11-22 11:41:44 +00:00
ecabal() {
cabal "$@"
}
2023-01-14 13:00:32 +00:00
nonfatal() {
2023-01-18 14:04:02 +00:00
"$@" || "$* failed"
2022-12-20 06:00:26 +00:00
}
2022-11-22 11:41:44 +00:00
sync_from() {
if [ "${RUNNER_OS}" != "Windows" ] ; then
cabal_store_path="$(dirname "$(cabal help user-config | tail -n 1 | xargs)")/store"
fi
cabal-cache sync-from-archive \
2022-12-15 16:21:53 +00:00
--host-name-override=${S3_HOST} \
2022-11-22 11:41:44 +00:00
--host-port-override=443 \
--host-ssl-override=True \
--region us-west-2 \
$([ "${RUNNER_OS}" != "Windows" ] && echo --store-path="$cabal_store_path") \
--archive-uri "s3://ghcup-hs/${RUNNER_OS}-${ARCH}-${DISTRO}"
}
sync_to() {
if [ "${RUNNER_OS}" != "Windows" ] ; then
cabal_store_path="$(dirname "$(cabal help user-config | tail -n 1 | xargs)")/store"
fi
cabal-cache sync-to-archive \
2022-12-15 16:21:53 +00:00
--host-name-override=${S3_HOST} \
2022-11-22 11:41:44 +00:00
--host-port-override=443 \
--host-ssl-override=True \
--region us-west-2 \
$([ "${RUNNER_OS}" != "Windows" ] && echo --store-path="$cabal_store_path") \
--archive-uri "s3://ghcup-hs/${RUNNER_OS}-${ARCH}-${DISTRO}"
}
raw_eghcup() {
"$GHCUP_BIN/ghcup${ext}" -v -c "$@"
}
eghcup() {
if [ "${OS}" = "Windows" ] ; then
"$GHCUP_BIN/ghcup${ext}" -c -s "file:/$CI_PROJECT_DIR/data/metadata/ghcup-${JSON_VERSION}.yaml" "$@"
else
"$GHCUP_BIN/ghcup${ext}" -c -s "file://$CI_PROJECT_DIR/data/metadata/ghcup-${JSON_VERSION}.yaml" "$@"
fi
}
sha_sum() {
if [ "${OS}" = "FreeBSD" ] ; then
sha256 "$@"
else
sha256sum "$@"
fi
}
git_describe() {
git config --global --get-all safe.directory | grep '^\*$' || git config --global --add safe.directory "*"
git describe --always
}
download_cabal_cache() {
(
set -e
2023-01-14 13:00:32 +00:00
mkdir -p "$HOME/.local/bin"
2022-11-22 11:41:44 +00:00
dest="$HOME/.local/bin/cabal-cache"
url=""
exe=""
cd /tmp
case "${RUNNER_OS}" in
"Linux")
2023-01-02 11:59:43 +00:00
case "${ARCH}" in
2023-01-04 13:08:10 +00:00
"32") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/i386-linux-cabal-cache
2023-01-02 11:59:43 +00:00
;;
2023-01-04 13:08:10 +00:00
"64") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/x86_64-linux-cabal-cache
2023-01-02 11:59:43 +00:00
;;
2023-01-04 13:08:10 +00:00
"ARM64") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/aarch64-linux-cabal-cache
2022-11-22 11:41:44 +00:00
;;
2023-01-04 13:08:10 +00:00
"ARM") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/armv7-linux-cabal-cache
2022-11-22 11:41:44 +00:00
;;
esac
;;
"FreeBSD")
2023-01-04 13:08:10 +00:00
url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/x86_64-portbld-freebsd-cabal-cache
2022-11-22 11:41:44 +00:00
;;
"Windows")
exe=".exe"
2023-01-04 13:08:10 +00:00
url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/x86_64-mingw64-cabal-cache
2022-11-22 11:41:44 +00:00
;;
"macOS")
case "${ARCH}" in
2023-01-04 13:08:10 +00:00
"ARM64") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/aarch64-apple-darwin-cabal-cache
2022-11-22 11:41:44 +00:00
;;
2023-01-04 13:08:10 +00:00
"64") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/x86_64-apple-darwin-cabal-cache
2022-11-22 11:41:44 +00:00
;;
esac
;;
esac
if [ -n "${url}" ] ; then
case "${url##*.}" in
"gz")
curl -L -o - "${url}" | gunzip > cabal-cache${exe}
;;
*)
curl -o cabal-cache${exe} -L "${url}"
;;
esac
2023-01-02 11:59:43 +00:00
sha_sum cabal-cache${exe}
mv "cabal-cache${exe}" "${dest}${exe}"
chmod +x "${dest}${exe}"
2022-11-22 11:41:44 +00:00
fi
)
}
build_with_cache() {
ecabal configure "$@"
ecabal build --dependencies-only "$@" --dry-run
2023-01-14 13:00:32 +00:00
sync_from
ecabal build --dependencies-only "$@" || sync_to
sync_to
2022-11-22 11:41:44 +00:00
ecabal build "$@"
2023-01-14 13:00:32 +00:00
sync_to
2022-11-22 11:41:44 +00:00
}
install_ghcup() {
2023-01-14 13:00:32 +00:00
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 BOOTSTRAP_HASKELL_MINIMAL=1 BOOTSTRAP_HASKELL_INSTALL_NO_STACK=yes sh
2022-11-22 11:41:44 +00:00
}
strip_binary() {
(
set -e
2022-12-21 05:44:31 +00:00
local binary=$1
case "$(uname -s)" in
"Darwin"|"darwin")
;;
MSYS_*|MINGW*)
;;
*)
2022-11-22 11:41:44 +00:00
strip -s "${binary}"
2022-12-21 05:44:31 +00:00
;;
esac
2022-11-22 11:41:44 +00:00
)
}