Skip to content

Commit 44c2d2d

Browse files
committed
Migrate to github CI
1 parent 686fa1a commit 44c2d2d

21 files changed

+1169
-918
lines changed

.cirrus.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
freebsd_instance:
2+
image_family: freebsd-13-1
3+
disk: 100
4+
5+
build_task:
6+
name: build
7+
timeout_in: 120m
8+
only_if: $CIRRUS_TAG != ''
9+
env:
10+
AWS_ACCESS_KEY_ID: ENCRYPTED[25d5e1d29570da70ceeb75e842b98be63d110824997b3c6b7bc0735b8acc686fbe0e9995cfe4d22a61d707a2e705d48b]
11+
AWS_SECRET_ACCESS_KEY: ENCRYPTED[7fc23de7b958e671dcb485ff0baef777b83fb472f0afdde940122c994bc1586710d69b9d25855768bfd201904f3654dd]
12+
S3_HOST: ENCRYPTED[d3fef1b5850e85d80dd1684370b53183df2218f2d36509108a2703371afd9ebd3f9596ad4de52487c15ea29baed606b7]
13+
TARBALL_EXT: "tar.xz"
14+
ARCH: 64
15+
ARTIFACT: "x86_64-freebsd"
16+
DISTRO: "na"
17+
RUNNER_OS: "FreeBSD"
18+
ADD_CABAL_ARGS: "--enable-split-sections"
19+
GITHUB_WORKSPACE: ${CIRRUS_WORKING_DIR}
20+
install_script: pkg install -y hs-cabal-install git bash misc/compat10x misc/compat11x misc/compat12x gmake patchelf tree
21+
script:
22+
- bash .github/scripts/build.sh
23+
- bash .github/scripts/test.sh
24+
# binaries_cache: &binaries_cache
25+
# folder: out
26+
# fingerprint_script:
27+
# - ghc --numeric-version
28+
# - cat cabal.project
29+
# - cat haskell-language-server.cabal
30+
# - cat dist-newstyle/cache/plan.json
31+
binaries_artifacts:
32+
path: "out/*"
33+
34+
# release_task:
35+
# name: "Release"
36+
# only_if: $CIRRUS_TAG != ''
37+
# depends_on: build
38+
# env:
39+
# GITHUB_TOKEN: ENCRYPTED[9d9b54424cb18abc9067436c729a77e0486805eff1903bc5b2c591696850f8db7cebac3f29cfa3b119ebb6fd2e98a839]
40+
# install_script: pkg install -y curl bash jq
41+
# binaries_cache: *binaries_cache
42+
# upload_script: |
43+
# #!/bin/bash
44+
#
45+
# if [[ "$CIRRUS_RELEASE" == "" ]]; then
46+
# NUM_TRIES=0
47+
# until [ $NUM_TRIES -eq 20 ]
48+
# do
49+
# echo "Retrying to find a release associated with this tag"
50+
# CIRRUS_RELEASE=$(curl -sL https://api.github.com/repos/$CIRRUS_REPO_FULL_NAME/releases/tags/$CIRRUS_TAG | jq -r '.id')
51+
# [[ "$CIRRUS_RELEASE" != "null" ]] && break
52+
# NUM_TRIES=$((NUM_TRIES+1))
53+
# sleep 30
54+
# done
55+
# fi
56+
#
57+
# if [[ "$GITHUB_TOKEN" == "" ]]; then
58+
# echo "Please provide GitHub access token via GITHUB_TOKEN environment variable!"
59+
# exit 1
60+
# fi
61+
#
62+
# for fpath in out/*
63+
# do
64+
# echo "Uploading $fpath..."
65+
# name=$(basename "$fpath")
66+
# url_to_upload="https://uploads.github.com/repos/$CIRRUS_REPO_FULL_NAME/releases/$CIRRUS_RELEASE/assets?name=$name"
67+
# echo "Uploading to $url_to_upload"
68+
# curl -X POST \
69+
# --data-binary @$fpath \
70+
# --header "Authorization: token $GITHUB_TOKEN" \
71+
# --header "Content-Type: application/x-xz-compressed-tar" \
72+
# $url_to_upload
73+
# done

.github/scripts/build.sh

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
download_cabal_cache "$HOME/.local/bin/cabal-cache"
21+
22+
23+
# build
24+
ecabal update
25+
26+
case "$(uname)" in
27+
MSYS_*|MINGW*)
28+
for ghc in $(cat bindist/ghcs-Msys) ; do
29+
GHC_VERSION="${ghc%,*}"
30+
args=( -O2 -w "ghc-$GHC_VERSION" --project-file cabal.project --disable-profiling --disable-tests --enable-executable-stripping ${ADD_CABAL_ARGS})
31+
ghcup install ghc "${GHC_VERSION}"
32+
ghcup set ghc "${GHC_VERSION}"
33+
"ghc-${GHC_VERSION}" --info
34+
"ghc" --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+
# create tarball/zip
65+
TARBALL_PREFIX="haskell-language-server"
66+
case "${TARBALL_EXT}" in
67+
zip)
68+
HLS_VERSION="$("$CI_PROJECT_DIR/out/haskell-language-server-8.10.7" --numeric-version)"
69+
cd "$CI_PROJECT_DIR/out/"
70+
zip "${TARBALL_PREFIX}-${HLS_VERSION}-${ARTIFACT}.zip" haskell-language-server-*
71+
find . -mindepth 1 -maxdepth 1 \! -name '*.zip' -exec rm -rf '{}' \;
72+
;;
73+
tar.xz)
74+
emake --version
75+
HLS_VERSION="$(emake -s -C out/bindist/haskell-language-server-* version)"
76+
emake TARBALL="${TARBALL_PREFIX}-${HLS_VERSION}-${ARTIFACT}.tar.xz" bindist-tar
77+
emake GHCUP=ghcup clean-ghcs
78+
find out -mindepth 1 -maxdepth 1 \! -name '*.tar.xz' -exec rm -rf '{}' \;
79+
;;
80+
*)
81+
fail "Unknown TARBALL_EXT: ${TARBALL_EXT}"
82+
;;
83+
esac
84+

.github/scripts/common.sh

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

Comments
 (0)