|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +if [ "${RUNNER_OS}" = "Windows" ] ; then |
| 4 | + ext=".exe" |
| 5 | +else |
| 6 | + ext='' |
| 7 | +fi |
| 8 | + |
| 9 | +# Colors |
| 10 | +RED="0;31" |
| 11 | +LT_BROWN="1;33" |
| 12 | +LT_BLUE="1;34" |
| 13 | + |
| 14 | +ecabal() { |
| 15 | + cabal "$@" |
| 16 | +} |
| 17 | + |
| 18 | +sync_from() { |
| 19 | + if [ "${RUNNER_OS}" != "Windows" ] ; then |
| 20 | + cabal_store_path="$(dirname "$(cabal help user-config | tail -n 1 | xargs)")/store" |
| 21 | + fi |
| 22 | + |
| 23 | + cabal-cache sync-from-archive \ |
| 24 | + --host-name-override="${S3_HOST}" \ |
| 25 | + --host-port-override=443 \ |
| 26 | + --host-ssl-override=True \ |
| 27 | + --region us-west-2 \ |
| 28 | + $([ "${RUNNER_OS}" != "Windows" ] && echo --store-path="$cabal_store_path") \ |
| 29 | + --archive-uri "s3://haskell-language-server/${ARTIFACT}" |
| 30 | +} |
| 31 | + |
| 32 | +sync_to() { |
| 33 | + if [ "${RUNNER_OS}" != "Windows" ] ; then |
| 34 | + cabal_store_path="$(dirname "$(cabal help user-config | tail -n 1 | xargs)")/store" |
| 35 | + fi |
| 36 | + |
| 37 | + cabal-cache sync-to-archive \ |
| 38 | + --host-name-override="${S3_HOST}" \ |
| 39 | + --host-port-override=443 \ |
| 40 | + --host-ssl-override=True \ |
| 41 | + --region us-west-2 \ |
| 42 | + $([ "${RUNNER_OS}" != "Windows" ] && echo --store-path="$cabal_store_path") \ |
| 43 | + --archive-uri "s3://haskell-language-server/${ARTIFACT}" |
| 44 | +} |
| 45 | + |
| 46 | +sha_sum() { |
| 47 | + if [ "${RUNNER_OS}" = "FreeBSD" ] ; then |
| 48 | + sha256 "$@" |
| 49 | + else |
| 50 | + sha256sum "$@" |
| 51 | + fi |
| 52 | + |
| 53 | +} |
| 54 | + |
| 55 | +git_describe() { |
| 56 | + git config --global --get-all safe.directory | grep '^\*$' || git config --global --add safe.directory "*" |
| 57 | + git describe --always |
| 58 | +} |
| 59 | + |
| 60 | +download_cabal_cache() { |
| 61 | + ( |
| 62 | + set -e |
| 63 | + dest="$HOME/.local/bin/cabal-cache" |
| 64 | + url="" |
| 65 | + exe="" |
| 66 | + cd /tmp |
| 67 | + case "${RUNNER_OS}" in |
| 68 | + "Linux") |
| 69 | + case "${ARCH}" in |
| 70 | + "32") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/1.0.5.4/i386-linux-cabal-cache-1.0.5.4 |
| 71 | + ;; |
| 72 | + "64") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/1.0.5.4/x86_64-linux-cabal-cache-1.0.5.4 |
| 73 | + ;; |
| 74 | + "ARM64") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/1.0.5.4/aarch64-linux-cabal-cache-1.0.5.4 |
| 75 | + ;; |
| 76 | + "ARM") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/1.0.5.4/armv7-linux-cabal-cache-1.0.5.4 |
| 77 | + ;; |
| 78 | + esac |
| 79 | + ;; |
| 80 | + "FreeBSD") |
| 81 | + url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/1.0.5.4/x86_64-portbld-freebsd-cabal-cache-1.0.5.4 |
| 82 | + ;; |
| 83 | + "Windows") |
| 84 | + exe=".exe" |
| 85 | + url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/1.0.5.4/x86_64-mingw64-cabal-cache-1.0.5.4.exe |
| 86 | + ;; |
| 87 | + "macOS") |
| 88 | + case "${ARCH}" in |
| 89 | + "ARM64") url=https://downloads.haskell.org/ghcup/unofficial-bindists/cabal-cache/1.0.5.4/aarch64-apple-darwin-cabal-cache-1.0.5.4 |
| 90 | + ;; |
| 91 | + "64") url=https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-cache/1.0.5.4/x86_64-apple-darwin-cabal-cache-1.0.5.4 |
| 92 | + ;; |
| 93 | + esac |
| 94 | + ;; |
| 95 | + esac |
| 96 | + |
| 97 | + if [ -n "${url}" ] ; then |
| 98 | + case "${url##*.}" in |
| 99 | + "gz") |
| 100 | + curl -L -o - "${url}" | gunzip > cabal-cache${exe} |
| 101 | + ;; |
| 102 | + *) |
| 103 | + curl -o cabal-cache${exe} -L "${url}" |
| 104 | + ;; |
| 105 | + esac |
| 106 | + sha_sum cabal-cache${exe} |
| 107 | + mv "cabal-cache${exe}" "${dest}${exe}" |
| 108 | + chmod +x "${dest}${exe}" |
| 109 | + fi |
| 110 | + ) |
| 111 | +} |
| 112 | + |
| 113 | +build_with_cache() { |
| 114 | + ecabal configure "$@" |
| 115 | + ecabal build --dependencies-only "$@" --dry-run |
| 116 | + sync_from |
| 117 | + ecabal build --dependencies-only "$@" || sync_to |
| 118 | + sync_to |
| 119 | + ecabal build "$@" |
| 120 | + sync_to |
| 121 | +} |
| 122 | + |
| 123 | +install_ghcup() { |
| 124 | + find "$GHCUP_INSTALL_BASE_PREFIX" |
| 125 | + mkdir -p "$GHCUP_BIN" |
| 126 | + mkdir -p "$GHCUP_BIN"/../cache |
| 127 | + |
| 128 | + if [ "${RUNNER_OS}" = "FreeBSD" ] ; then |
| 129 | + curl -o ghcup https://downloads.haskell.org/ghcup/tmp/x86_64-portbld-freebsd-ghcup-0.1.18.1 |
| 130 | + chmod +x ghcup |
| 131 | + mv ghcup "$HOME/.local/bin/ghcup" |
| 132 | + else |
| 133 | + curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_MINIMAL=1 sh |
| 134 | + source "$(dirname "${GHCUP_BIN}")/env" |
| 135 | + ghcup install ghc --set "${BOOTSTRAP_HASKELL_GHC_VERSION}" |
| 136 | + ghcup install cabal --set "${BOOTSTRAP_HASKELL_CABAL_VERSION}" |
| 137 | + fi |
| 138 | +} |
| 139 | + |
| 140 | +strip_binary() { |
| 141 | + ( |
| 142 | + set -e |
| 143 | + local binary=$1 |
| 144 | + case "$(uname -s)" in |
| 145 | + "Darwin"|"darwin") |
| 146 | + ;; |
| 147 | + MSYS_*|MINGW*) |
| 148 | + ;; |
| 149 | + *) |
| 150 | + strip -s "${binary}" |
| 151 | + ;; |
| 152 | + esac |
| 153 | + ) |
| 154 | +} |
| 155 | + |
| 156 | +# GitLab Pipelines log section delimiters |
| 157 | +# https://gitlab.com/gitlab-org/gitlab-foss/issues/14664 |
| 158 | +start_section() { |
| 159 | + name="$1" |
| 160 | + echo -e "section_start:$(date +%s):$name\015\033[0K" |
| 161 | +} |
| 162 | + |
| 163 | +end_section() { |
| 164 | + name="$1" |
| 165 | + echo -e "section_end:$(date +%s):$name\015\033[0K" |
| 166 | +} |
| 167 | + |
| 168 | +echo_color() { |
| 169 | + local color="$1" |
| 170 | + local msg="$2" |
| 171 | + echo -e "\033[${color}m${msg}\033[0m" |
| 172 | +} |
| 173 | + |
| 174 | +error() { echo_color "${RED}" "$1"; } |
| 175 | +warn() { echo_color "${LT_BROWN}" "$1"; } |
| 176 | +info() { echo_color "${LT_BLUE}" "$1"; } |
| 177 | + |
| 178 | +fail() { error "error: $1"; exit 1; } |
| 179 | + |
| 180 | +run() { |
| 181 | + info "Running $*..." |
| 182 | + "$@" || ( error "$* failed"; return 1; ) |
| 183 | +} |
| 184 | + |
| 185 | +emake() { |
| 186 | + if command -v gmake >/dev/null 2>&1 ; then |
| 187 | + gmake "$@" |
| 188 | + else |
| 189 | + make "$@" |
| 190 | + fi |
| 191 | +} |
| 192 | + |
| 193 | +mktempdir() { |
| 194 | + case "$(uname -s)" in |
| 195 | + "Darwin"|"darwin") |
| 196 | + mktemp -d -t hls_ci.XXXXXXX |
| 197 | + ;; |
| 198 | + *) |
| 199 | + mktemp -d |
| 200 | + ;; |
| 201 | + esac |
| 202 | +} |
0 commit comments