Last active
December 13, 2022 22:40
-
-
Save Fuuzetsu/8276421 to your computer and use it in GitHub Desktop.
Script for generating and uploading missing documentation for your Hackage packages. Now with fixed package links and contents page.
This file contains hidden or 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
#!/usr/bin/env bash | |
cabal configure && cabal build && cabal haddock --hyperlink-source \ | |
--html-location='/package/$pkg-$version/docs' \ | |
--contents-location='/package/$pkg' | |
S=$? | |
if [ "${S}" -eq "0" ]; then | |
cd "dist/doc/html" | |
DDIR="${1}-${2}-docs" | |
cp -r "${1}" "${DDIR}" && tar -c -v -z --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' --data-binary "@${DDIR}.tar.gz" "https://${3}:${4}@hackage.haskell.org/package/${1}-${2}/docs" | |
exit $? | |
else | |
echo "Error when packaging the documentation" | |
exit $CS | |
fi | |
else | |
echo "Error when trying to build the package." | |
exit $S | |
fi |
This ugly mess will get you namever=my-package-1.0.0
and name=my-package
:
namever=`cabal info . 2>/dev/null | sed -n 1p | awk '{ print $2; }'`
name=`printf "%s" "$namever" | sed 's/\(.\)-[0-9.]\{1,\}$/\1/'`
BTW adding -f
to curl
is useful for making sure HTTP errors reported by the server cause the command to return a nonzero exit code.
Also, it would be nice if the control flow of the script was restructured to be like this:
do_something
if failed; then
print_error_and_exit
fi
do_more_things
if failed; then
print_error_and_exit
fi
…
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@sol it could do that, sure, I just never bothered, this was a quick few minute hack that I think got a bit too popular
@soenkehahn I would be glad to incorporate any changes needed, just send me a diff
Everyone: please note that GitHub does not notify me on comments on gists, if you want me to make changes to this script, I'll happily do so (or link to a better one) but you'll have to contact me somehow, IRC, e-mail, whatever. It might take weeks/months for me to see things here.