Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Jan 20, 2025
1 parent 4ea640e commit 49031bd
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 403 deletions.
13 changes: 2 additions & 11 deletions .github/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@ uname
pwd
env

# ensure ghcup
install_ghcup

# ensure cabal-cache
download_cabal_cache "$HOME/.local/bin/cabal-cache"


# build
ghcup install ghc "${GHC_VERSION}"
ghcup set ghc "${GHC_VERSION}"
sed -i.bak -e '/DELETE MARKER FOR CI/,/END DELETE/d' cabal.project # see comment in cabal.project
ecabal update
ecabal user-config diff
Expand Down Expand Up @@ -48,7 +39,7 @@ case "$(uname)" in
src/**/*.hs exe/*.hs

# shellcheck disable=SC2068
build_with_cache ${args[@]} exe:hls exe:hls-wrapper
ecabal build ${args[@]} exe:hls exe:hls-wrapper
cp dist-newstyle/cache/plan.json "$CI_PROJECT_DIR/out/plan.json/${ARTIFACT}-ghc-${GHC_VERSION}-plan.json"

# shellcheck disable=SC2068
Expand All @@ -58,7 +49,7 @@ case "$(uname)" in
;;
*)
emake --version
emake GHCUP=ghcup CABAL_CACHE_BIN=cabal-cache.sh S3_HOST="${S3_HOST}" S3_KEY="${ARTIFACT}" GHC_VERSION="${GHC_VERSION}" hls-ghc
emake GHCUP=ghcup GHC_VERSION="${GHC_VERSION}" hls-ghc
;;
esac

Expand Down
20 changes: 0 additions & 20 deletions .github/scripts/cabal-cache.sh

This file was deleted.

180 changes: 0 additions & 180 deletions .github/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,190 +2,10 @@

. .github/scripts/env.sh

# Colors
RED="0;31"
LT_BROWN="1;33"
LT_BLUE="1;34"

ecabal() {
cabal "$@"
}

nonfatal() {
"$@" || "$* failed"
}

# sync the relevant parts of cabal artifacts that are part of
# the current plan.json from an S3 bucket
sync_from() {
if [ "${RUNNER_OS}" != "Windows" ] ; then
cabal_store_path="$(dirname "$(cabal help user-config | tail -n 1 | xargs)")/store"
fi

cabal-cache.sh sync-from-archive \
--host-name-override="${S3_HOST}" \
--host-port-override=443 \
--host-ssl-override=True \
--region us-west-2 \
$([ "${RUNNER_OS}" != "Windows" ] && echo --store-path="$cabal_store_path") \
--archive-uri "s3://haskell-language-server/${ARTIFACT}"
}

# sync the relevant parts of cabal artifacts that are part of
# the current plan.json to an S3 bucket
sync_to() {
if [ "${RUNNER_OS}" != "Windows" ] ; then
cabal_store_path="$(dirname "$(cabal help user-config | tail -n 1 | xargs)")/store"
fi

cabal-cache.sh sync-to-archive \
--host-name-override="${S3_HOST}" \
--host-port-override=443 \
--host-ssl-override=True \
--region us-west-2 \
$([ "${RUNNER_OS}" != "Windows" ] && echo --store-path="$cabal_store_path") \
--archive-uri "s3://haskell-language-server/${ARTIFACT}"
}

sha_sum() {
if [ "${RUNNER_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
dest="$HOME/.local/bin/cabal-cache"
url=""
exe=""
cd /tmp
case "${RUNNER_OS}" in
"Linux")
case "${ARCH}" in
"32") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/i386-linux-cabal-cache
;;
"64") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/x86_64-linux-cabal-cache
;;
"ARM64") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/aarch64-linux-cabal-cache
;;
"ARM") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/armv7-linux-cabal-cache
;;
esac
;;
"FreeBSD")
url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/x86_64-portbld-freebsd-cabal-cache
;;
"Windows")
exe=".exe"
url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/x86_64-mingw64-cabal-cache
;;
"macOS")
case "${ARCH}" in
"ARM64") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/aarch64-apple-darwin-cabal-cache
;;
"64") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/experimental5/x86_64-apple-darwin-cabal-cache
;;
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
sha_sum cabal-cache${exe}
mv "cabal-cache${exe}" "${dest}${exe}"
chmod +x "${dest}${exe}"
fi

# install shell wrapper
cp "${CI_PROJECT_DIR}"/.github/scripts/cabal-cache.sh "$HOME"/.local/bin/
chmod +x "$HOME"/.local/bin/cabal-cache.sh
)
}

build_with_cache() {
ecabal configure "$@"
ecabal build --dependencies-only "$@" --dry-run
nonfatal sync_from
ecabal build "$@"
nonfatal sync_to
}

install_ghcup() {
# find "$GHCUP_INSTALL_BASE_PREFIX"
mkdir -p "$GHCUP_BIN"
mkdir -p "$GHCUP_BIN"/../cache

if [ "${RUNNER_OS}" = "FreeBSD" ] ; then
curl -o ghcup https://downloads.haskell.org/ghcup/tmp/x86_64-portbld-freebsd-ghcup-0.1.18.1
chmod +x ghcup
mv ghcup "$HOME/.local/bin/ghcup"
else
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_MINIMAL=1 sh
source "$(dirname "${GHCUP_BIN}")/env"
ghcup install cabal --set "${BOOTSTRAP_HASKELL_CABAL_VERSION}"
fi
}

strip_binary() {
(
set -e
local binary=$1
case "$(uname -s)" in
"Darwin"|"darwin")
;;
MSYS_*|MINGW*)
;;
*)
strip -s "${binary}"
;;
esac
)
}

# GitLab Pipelines log section delimiters
# https://gitlab.com/gitlab-org/gitlab-foss/issues/14664
start_section() {
name="$1"
echo -e "section_start:$(date +%s):$name\015\033[0K"
}

end_section() {
name="$1"
echo -e "section_end:$(date +%s):$name\015\033[0K"
}

echo_color() {
local color="$1"
local msg="$2"
echo -e "\033[${color}m${msg}\033[0m"
}

error() { echo_color "${RED}" "$1"; }
warn() { echo_color "${LT_BROWN}" "$1"; }
info() { echo_color "${LT_BLUE}" "$1"; }

fail() { error "error: $1"; exit 1; }

run() {
info "Running $*..."
"$@" || ( error "$* failed"; return 1; )
}

emake() {
if command -v gmake >/dev/null 2>&1 ; then
gmake "$@"
Expand Down
17 changes: 0 additions & 17 deletions .github/scripts/env.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
#!/bin/bash

mkdir -p "$HOME"/.local/bin

if [ "${RUNNER_OS}" = "Windows" ] ; then
ext=".exe"
else
ext=''
fi

export PATH="$HOME/.local/bin:$PATH"

export BOOTSTRAP_HASKELL_NONINTERACTIVE=1
export BOOTSTRAP_HASKELL_CABAL_VERSION="${CABAL_VER:-3.10.3.0}"
export BOOTSTRAP_HASKELL_ADJUST_CABAL_CONFIG=no
export BOOTSTRAP_HASKELL_INSTALL_NO_STACK=yes
export BOOTSTRAP_HASKELL_ADJUST_BASHRC=1

if [ "${RUNNER_OS}" = "Windows" ] ; then
# on windows use pwd to get unix style path
CI_PROJECT_DIR="$(pwd)"
export CI_PROJECT_DIR
export GHCUP_INSTALL_BASE_PREFIX="/c"
export GHCUP_BIN="$GHCUP_INSTALL_BASE_PREFIX/ghcup/bin"
export PATH="$GHCUP_BIN:$PATH"
export CABAL_DIR="C:\\Users\\runneradmin\\AppData\\Roaming\\cabal"
else
export CI_PROJECT_DIR="${GITHUB_WORKSPACE}"
export GHCUP_INSTALL_BASE_PREFIX="$CI_PROJECT_DIR"
export GHCUP_BIN="$GHCUP_INSTALL_BASE_PREFIX/.ghcup/bin"
export PATH="$GHCUP_BIN:$PATH"
export CABAL_DIR="$CI_PROJECT_DIR/cabal"
export CABAL_CACHE="$CI_PROJECT_DIR/cabal-cache"
fi

export DEBIAN_FRONTEND=noninteractive
Expand Down
Loading

0 comments on commit 49031bd

Please sign in to comment.