Skip to content

Commit

Permalink
Setup the release locale for UTF-8
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fendor committed Feb 26, 2024
1 parent 722b08a commit 8164dd6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ uname
pwd
env

# setup the locale as HLS contains non-ascii modules and content.
setup_locale

# ensure ghcup
install_ghcup

Expand Down
31 changes: 30 additions & 1 deletion .github/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ install_ghcup() {
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_MINIMAL=1 sh
source "$(dirname "${GHCUP_BIN}")/env"
# make sure we use the vanilla channel for installing binaries
# see https://github.com/haskell/ghcup-metadata/pull/166#issuecomment-1893075575
# see https://github.com/haskell/ghcup-metadata/pull/166#issuecomment-1893075575
ghcup config set url-source https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-vanilla-0.0.8.yaml
ghcup install cabal --set "${BOOTSTRAP_HASKELL_CABAL_VERSION}"
fi
Expand Down Expand Up @@ -207,3 +207,32 @@ mktempdir() {
;;
esac
}

# "Inspired" from GHC GitLab CI
# https://gitlab.haskell.org/ghc/ghc/-/blob/214b2b6916f2d016ab9db0b766060e7828bb47a0/.gitlab/ci.sh#L60
setup_locale() {
# BSD grep terminates early with -q, consequently locale -a will get a
# SIGPIPE and the pipeline will fail with pipefail.
shopt -o -u pipefail
if locale -a | grep -q C.UTF-8; then
# Debian
export LANG=C.UTF-8
elif locale -a | grep -q C.utf8; then
# Fedora calls it this
export LANG=C.utf8
elif locale -a | grep -q en_US.UTF-8; then
# Centos doesn't have C.UTF-8
export LANG=en_US.UTF-8
elif locale -a | grep -q en_US.utf8; then
# Centos doesn't have C.UTF-8
export LANG=en_US.utf8
else
error "Failed to find usable locale"
info "Available locales:"
locale -a
fail "No usable locale, aborting..."
fi
info "Using locale $LANG..."
export LC_ALL=$LANG
shopt -o -s pipefail
}

0 comments on commit 8164dd6

Please sign in to comment.