maintainers/haskell/update-stackage.sh: make solver configurable

Accept either Nightly or LTS as the solver configuration variable in the
script. The Stackage version is now considered a tuple of solver and
version, allowing the script to handle updates and switches between
solvers gracefully.

Tested updating Nightly and updating from Nightly to LTS.
This commit is contained in:
sternenseemann 2022-03-20 10:58:00 +01:00
parent e3ab27de78
commit 22ced213c0

View file

@ -3,6 +3,15 @@
set -eu -o pipefail
# Stackage solver to use, LTS or Nightly
# (should be capitalized like the display name)
SOLVER=Nightly
readonly SOLVER
toLower() {
printf "%s" "$1" | tr '[:upper:]' '[:lower:]'
}
tmpfile=$(mktemp "update-stackage.XXXXXXX")
# shellcheck disable=SC2064
@ -11,16 +20,16 @@ stackage_config="pkgs/development/haskell-modules/configuration-hackage2nix/stac
trap "rm ${tmpfile} ${tmpfile}.new" 0
touch "$tmpfile" "$tmpfile.new" # Creating files here so that trap creates no errors.
curl -L -s "https://stackage.org/nightly/cabal.config" >"$tmpfile"
old_version=$(grep "# Stackage Nightly" $stackage_config | sed -E 's/.*([0-9]{4}-[0-9]{2}-[0-9]{2}).*/\1/')
version=$(sed -rn "s/^--.*http:..(www.)?stackage.org.snapshot.nightly-//p" "$tmpfile")
curl -L -s "https://stackage.org/$(toLower "$SOLVER")/cabal.config" >"$tmpfile"
old_version=$(grep '^# Stackage' $stackage_config | sed -e 's/.\+ \([A-Za-z]\+ [0-9.-]\+\)$/\1/g')
version="$SOLVER $(sed -rn "s/^--.*http:..(www.)?stackage.org.snapshot.$(toLower "$SOLVER")-//p" "$tmpfile")"
if [[ "$old_version" == "$version" ]]; then
echo "No new stackage version"
exit 0 # Nothing to do
fi
echo "Updating Stackage Nightly from $old_version to $version."
echo "Updating Stackage from $old_version to $version."
# Create a simple yaml version of the file.
sed -r \
@ -33,7 +42,7 @@ sed -r \
< "${tmpfile}" | sort --ignore-case >"${tmpfile}.new"
cat > $stackage_config << EOF
# Stackage Nightly $version
# Stackage $version
# This file is auto-generated by
# maintainers/scripts/haskell/update-stackage.sh
default-package-overrides:
@ -51,7 +60,7 @@ sed -r \
if [[ "${1:-}" == "--do-commit" ]]; then
git add $stackage_config
git commit -F - << EOF
haskellPackages: stackage-nightly $old_version -> $version
haskellPackages: stackage $old_version -> $version
This commit has been generated by maintainers/scripts/haskell/update-stackage.sh
EOF