summary refs log tree commit diff
path: root/maintainers/scripts/haskell/update-stackage.sh
blob: b332e8d4dc61654891c3dd730c6074b99d390f54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/env bash

set -eu -o pipefail

tmpfile=$(mktemp "update-stackage.XXXXXXX")
# shellcheck disable=SC2064

config_file="pkgs/development/haskell-modules/configuration-hackage2nix.yaml"

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" $config_file | 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")

if [[ "$old_version" == "$version" ]]; then
   echo "No new stackage version"
   exit 0 # Nothing to do
fi

# Create a simple yaml version of the file.
sed -r \
    -e '/^--/d' \
    -e 's|^constraints:||' \
    -e 's|^ +|  - |' \
    -e 's|,$||' \
    -e '/installed$/d' \
    -e '/^$/d' \
    < "${tmpfile}" | sort --ignore-case >"${tmpfile}.new"

# Drop restrictions on some tools where we always want the latest version.
sed -r \
    -e '/ cabal-install /d' \
    -e '/ cabal2nix /d' \
    -e '/ cabal2spec /d' \
    -e '/ distribution-nixpkgs /d' \
    -e '/ git-annex /d' \
    -e '/ hindent /d' \
    -e '/ hledger/d' \
    -e '/ hlint /d' \
    -e '/ hoogle /d' \
    -e '/ hopenssl /d' \
    -e '/ jailbreak-cabal /d' \
    -e '/ json-autotype/d' \
    -e '/ language-nix /d' \
    -e '/ shake /d' \
    -e '/ ShellCheck /d' \
    -e '/ stack /d' \
    -e '/ weeder /d' \
    < "${tmpfile}.new" > "${tmpfile}"

# Drop the previous configuration ...
# shellcheck disable=SC1004
sed -e '/  # Stackage Nightly/,/^$/c \TODO\
'   -i $config_file

# ... and replace it with the new one.
sed -e "/TODO/r $tmpfile" \
    -e "s/TODO/  # Stackage Nightly $version/" \
    -i $config_file

if [[ "${1:-}" == "--do-commit" ]]; then
git add $config_file
git commit -F - << EOF
Stackage Nightly: $old_version -> $version

This commit has been generated by maintainers/scripts/haskell/update-stackage.sh
EOF
fi