Skip to content

Commit 8164dd6

Browse files
committed
Setup the release locale for UTF-8
Not all release runners seem to have a locale that allows for unicode characters in module names. Let's make sure they all use some form of UTF-8.
1 parent 722b08a commit 8164dd6

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

.github/scripts/build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ uname
1111
pwd
1212
env
1313

14+
# setup the locale as HLS contains non-ascii modules and content.
15+
setup_locale
16+
1417
# ensure ghcup
1518
install_ghcup
1619

.github/scripts/common.sh

+30-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ install_ghcup() {
138138
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_MINIMAL=1 sh
139139
source "$(dirname "${GHCUP_BIN}")/env"
140140
# make sure we use the vanilla channel for installing binaries
141-
# see https://github.com/haskell/ghcup-metadata/pull/166#issuecomment-1893075575
141+
# see https://github.com/haskell/ghcup-metadata/pull/166#issuecomment-1893075575
142142
ghcup config set url-source https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-vanilla-0.0.8.yaml
143143
ghcup install cabal --set "${BOOTSTRAP_HASKELL_CABAL_VERSION}"
144144
fi
@@ -207,3 +207,32 @@ mktempdir() {
207207
;;
208208
esac
209209
}
210+
211+
# "Inspired" from GHC GitLab CI
212+
# https://gitlab.haskell.org/ghc/ghc/-/blob/214b2b6916f2d016ab9db0b766060e7828bb47a0/.gitlab/ci.sh#L60
213+
setup_locale() {
214+
# BSD grep terminates early with -q, consequently locale -a will get a
215+
# SIGPIPE and the pipeline will fail with pipefail.
216+
shopt -o -u pipefail
217+
if locale -a | grep -q C.UTF-8; then
218+
# Debian
219+
export LANG=C.UTF-8
220+
elif locale -a | grep -q C.utf8; then
221+
# Fedora calls it this
222+
export LANG=C.utf8
223+
elif locale -a | grep -q en_US.UTF-8; then
224+
# Centos doesn't have C.UTF-8
225+
export LANG=en_US.UTF-8
226+
elif locale -a | grep -q en_US.utf8; then
227+
# Centos doesn't have C.UTF-8
228+
export LANG=en_US.utf8
229+
else
230+
error "Failed to find usable locale"
231+
info "Available locales:"
232+
locale -a
233+
fail "No usable locale, aborting..."
234+
fi
235+
info "Using locale $LANG..."
236+
export LC_ALL=$LANG
237+
shopt -o -s pipefail
238+
}

0 commit comments

Comments
 (0)