ghc-mod/scripts/upload-metadata.hs

75 lines
1.8 KiB
Haskell
Raw Normal View History

2015-11-18 19:56:44 +00:00
#!/bin/sh
is_term() {
[ -t 0 ]
}
# Disable echo while typing the password if in a terminal
hidden_prompt() {
if is_term; then
settings=$(stty -g)
trap "stty '$settings'" 0
stty -echo
echo -n "$1: "
IFS="" read -r $2
echo
stty "$settings"
else
IFS="" read -r $2
fi
}
set -e
PACKAGE=$1
OUTDIR=$2
2016-11-01 23:48:51 +00:00
VERSIONS="$@"
2015-11-18 19:56:44 +00:00
read -p "Username: " user
hidden_prompt "Password" pw
2016-11-01 23:48:51 +00:00
if [ -z "$VERSIONS" ]; then
VERSIONS="$(curl https://hackage.haskell.org/package/"$PACKAGE"/preferred.json | jq '."normal-version"[]' -r)"
2016-06-02 18:15:59 +00:00
#versions="$(curl https://hackage.haskell.org/package/"$PACKAGE"/preferred.json | jq '."deprecated-version"[]' -r)"
2016-11-01 23:48:51 +00:00
fi
2016-06-02 18:15:59 +00:00
2016-11-01 23:48:51 +00:00
echo "Versions: $VERSIONS"
2015-11-18 19:56:44 +00:00
2016-11-01 23:48:51 +00:00
for v in $VERSIONS; do
2015-11-18 19:56:44 +00:00
rev=$(cat $OUTDIR/$PACKAGE-$v.cabal | grep -i "^x-revision:" | tr -s '[:blank:]*' '\t' | cut -f 2)
if [ -z "$rev" ]; then
rev=0
fi
2016-06-02 18:15:59 +00:00
echo -n "$PACKAGE v$v rev:$rev..."
2015-11-18 19:56:44 +00:00
content=$( ( echo "X-Revision: $((rev + 1))"; cat $OUTDIR/$PACKAGE-$v.cabal | sed '/^X-Revision:/Id' ) )
2016-06-02 18:15:59 +00:00
resp=$(curl -s --form-string "cabalfile=$content" -F "publish=Publish new revision" https://hackage.haskell.org/package/"${PACKAGE}-${v}"/"${PACKAGE}.cabal"/edit -u "$user:$pw")
2015-11-18 19:56:44 +00:00
changes=$(printf '%s\n' "$resp" | sed -n '/Changes in this revision/,/<\/ul>/p' | w3m -dump -T text/html)
errors=$(printf '%s\n' "$resp" | sed -n '/Errors/,/<\/form>/p')
2016-06-02 18:15:59 +00:00
if printf '%s\n' "$resp" | grep -q "Cannot publish new revision"; then
notpublished=1
fi
2015-11-18 19:56:44 +00:00
2016-06-02 18:15:59 +00:00
printf 'Changes:\n%s\n' "$changes"
2015-11-18 19:56:44 +00:00
if [ -z "$changes" -o -n "$notpublished" ]; then
if printf '%s\n' "$errors" | grep -q "No changes"; then
continue;
fi
printf '%s\n' "$resp" > /tmp/hackage-metadata-error
printf '%s\n' "$errors" | w3m -dump -T text/html
exit 1
fi
done