Skip to content

Commit abb0226

Browse files
committed
Migrate to github CI
1 parent f5db150 commit abb0226

19 files changed

+1059
-1254
lines changed

.cirrus.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
freebsd_instance:
2+
image_family: freebsd-13-1
3+
disk: 100
4+
5+
task:
6+
timeout_in: 120m
7+
env:
8+
AWS_ACCESS_KEY_ID: ENCRYPTED[ad041496e88a9588a0f53083f785b2c24ed86c2518cc9b2abfaae0864836a7a1f5795c27e27ea36b7e1ade2910d2a9d1]
9+
AWS_SECRET_ACCESS_KEY: ENCRYPTED[235c7b4f37059df072cfd59bface11c801195e1606c2bea7b1cc60f59bbd6b47a374a77e890e919cd3155db6dc395534]
10+
S3_HOST: ENCRYPTED[14d35aaef35056e40ce3a0d5c3f648ac0648588788f63c877b85ee602b937b9c08c3ecc56ef5bb0545fcc0a86ecbfff8]
11+
TARBALL_EXT: "tar.xz"
12+
ARCH: 64
13+
ARTIFACT: "x86_64-freebsd"
14+
DISTRO: "na"
15+
RUNNER_OS: "FreeBSD"
16+
ADD_CABAL_ARGS: "--enable-split-sections"
17+
GITHUB_WORKSPACE: ${CIRRUS_WORKING_DIR}
18+
install_script: pkg install -y hs-cabal-install git bash misc/compat10x misc/compat11x misc/compat12x gmake patchelf
19+
script:
20+
- bash .github/scripts/build.sh
21+
- bash .github/scripts/test.sh
22+
binaries_artifacts:
23+
path: "out/*"
24+

.github/scripts/build.sh

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
3+
set -eux
4+
5+
. .github/scripts/prereq.sh
6+
. .github/scripts/common.sh
7+
8+
uname -a
9+
uname -p
10+
uname
11+
pwd
12+
env
13+
14+
# ensure ghcup
15+
if ! command -v ghcup ; then
16+
install_ghcup
17+
fi
18+
19+
# ensure cabal-cache
20+
if ! cabal-cache version ; then
21+
download_cabal_cache "$HOME/.local/bin/cabal-cache"
22+
fi
23+
24+
25+
# build
26+
ecabal update
27+
28+
case "$(uname)" in
29+
MSYS_*|MINGW*)
30+
for ghc in $(cat bindist/ghcs-Msys) ; do
31+
GHC_VERSION="${ghc%,*}"
32+
args=( -O2 -w "ghc-$GHC_VERSION" --project-file cabal.project --disable-profiling --disable-tests --enable-executable-stripping ${ADD_CABAL_ARGS})
33+
ghcup install ghc "${GHC_VERSION}"
34+
"ghc-${GHC_VERSION}" --info
35+
# Shorten binary names
36+
sed -i.bak -e 's/haskell-language-server/hls/g' \
37+
-e 's/haskell_language_server/hls/g' \
38+
haskell-language-server.cabal cabal.project
39+
sed -i.bak -e 's/Paths_haskell_language_server/Paths_hls/g' \
40+
src/**/*.hs exe/*.hs
41+
42+
43+
# shellcheck disable=SC2068
44+
build_with_cache ${args[@]} exe:hls exe:hls-wrapper
45+
46+
mkdir -p "$CI_PROJECT_DIR/out"
47+
48+
# shellcheck disable=SC2068
49+
cp "$(cabal list-bin -v0 ${args[@]} exe:hls)" "$CI_PROJECT_DIR/out/haskell-language-server-${GHC_VERSION}"${ext}
50+
# shellcheck disable=SC2068
51+
cp "$(cabal list-bin -v0 ${args[@]} exe:hls-wrapper)" "$CI_PROJECT_DIR/out/haskell-language-server-wrapper"${ext}
52+
ghcup rm ghc "${GHC_VERSION}"
53+
done
54+
;;
55+
*)
56+
sed -i.bak -e '/DELETE MARKER FOR CI/,/END DELETE/d' cabal.project # see comment in cabal.project
57+
emake --version
58+
emake GHCUP=ghcup CABAL_CACHE_BIN=cabal-cache S3_HOST="${S3_HOST}" S3_KEY="${ARTIFACT}" hls
59+
emake GHCUP=ghcup bindist
60+
rm -rf out/*.*.*
61+
;;
62+
esac
63+
64+
cp dist-newstyle/cache/plan.json "$CI_PROJECT_DIR/out/plan.json"
65+
66+
67+
# create tarball/zip
68+
TARBALL_PREFIX="haskell-language-server"
69+
case "${TARBALL_EXT}" in
70+
zip)
71+
HLS_VERSION="$("$CI_PROJECT_DIR/out/haskell-language-server-8.10.7" --numeric-version)"
72+
cd "$CI_PROJECT_DIR/out/"
73+
zip "${TARBALL_PREFIX}-${HLS_VERSION}-${ARTIFACT}.zip" haskell-language-server-*
74+
find . -type f ! -name '*.zip' -delete
75+
;;
76+
tar.xz)
77+
emake --version
78+
HLS_VERSION="$(emake -s -C out/bindist/haskell-language-server-* version)"
79+
emake TARBALL="${TARBALL_PREFIX}-${HLS_VERSION}-${ARTIFACT}.tar.xz" bindist-tar
80+
rm -rf out/bindist
81+
;;
82+
*)
83+
fail "Unknown TARBALL_EXT: ${TARBALL_EXT}"
84+
;;
85+
esac
86+

.github/scripts/common.sh

+233
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
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

Comments
 (0)