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