misc/scripts/haddock-upload
2018-08-05 18:53:07 +02:00

50 lines
1.4 KiB
Plaintext
Executable File

#!/usr/bin/env nix-script
#!>zsh
#! shell | zsh curl haskellPackages.cabal-install
# functions
conf(){ cat *.cabal | grep -Po "^$1:\s+\K.+" }
input(){ read "reply?$1 "; echo ${reply:-$2} }
inputpw(){ echo -n "$1 " >&2; scat --silent --nocode -n 24 -S $2; echo >&2 }
# parameters
package=$(conf name)
version=$(conf version)
author=$(conf author)
# authentication
user=$(input "user ($author):" $author)
password=$(inputpw "password:" hackage)
cabal configure &&
cabal build &&
cabal haddock \
--hyperlink-source \
--html-location='/package/$pkg-$version/docs' \
--contents-location='/package/$pkg'
S=$?
if [ "$S" = "0" ]; then
cd dist/doc/html
ddir="$package-$version-docs"
cp -rf $package $ddir &&
tar -cz --format=ustar -f "$ddir.tar.gz" $ddir
CS=$?
if [ "$CS" -eq "0" ]; then
echo "Uploading to Hackage..."
curl \
-X PUT \
-H 'Content-Type: application/x-tar' \
-H 'Content-Encoding: gzip' \
-u "$user:$password" \
--data-binary "@$ddir.tar.gz" \
"https://hackage.haskell.org/package/$package-$version/docs"
exit $?
else
echo "Error when packaging the documentation."
exit $CS
fi
else
echo "Error when trying to build the package."
exit $S
fi