Created
June 24, 2020 15:17
-
-
Save ChrisPenner/6b252efb676b860a3c6634656f4b6175 to your computer and use it in GitHub Desktop.
Fix Haddock Docs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Adapted from script by Dimitri Sabadie <[email protected]> | |
dist=$(stack path --dist-dir --stack-yaml ./stack.yaml) | |
packagename=$(awk '/^name:\s*(.*)/{ print $2 }' ./*.cabal) | |
packageversion=$(awk '/^version:\s*(.*)/{ print $2 }' ./*.cabal) | |
echo -e "\033[1;36mGenerating documentation for $packagename-$packageversion\033[0m" | |
if ! stack haddock; then | |
echo -e "\033[1;31m'stack haddock failed, are you in a stack project?\033[0m" | |
exit 1 | |
fi | |
echo "uploading docs to $packagename-$packageversion" | |
docdir=$dist/doc/html | |
cd "$docdir" || (echo "$docdir does not exist!"; exit 1) | |
doc="$packagename-$packageversion-docs" | |
echo -e "Compressing documentation from \033[1;34m$docdir\033[0m for \033[1;35m$packagename\033[0m-\033[1;33m$packageversion\033[1;30m" | |
cp -r "$packagename" "$doc" | |
tar -c -v -z --format=ustar -f "$doc.tar.gz" "$doc" | |
echo -e "\033[1;32mUploading to Hackage...\033[0m" | |
if [[ -f ~/.stack/upload/credentials.json ]]; then | |
username=$(perl -n -e'/"username":"(\w+)"/ && print $1' ~/.stack/upload/credentials.json) | |
password=$(perl -n -e'/"password":"(\w+)"/ && print $1' ~/.stack/upload/credentials.json) | |
else | |
read -r -p "Hackage username: " username | |
read -r -p "Hackage password: " -s password | |
fi | |
echo "" | |
curl -X PUT -H 'Content-Type: application/x-tar' -H 'Content-Encoding: gzip' --data-binary "@$doc.tar.gz" "https://$username:[email protected]/package/$packagename-$packageversion/docs" > /dev/null | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment