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