Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Script for generating and uploading missing documentation for your Hackage packages. Now with fixed package links and contents page.
#!/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
@hvr

This comment has been minimized.

Show comment Hide comment
@hvr

hvr Jan 30, 2014

I would rather use relative urls, e.g. --html-location='/package/$pkg/docs'

hvr commented Jan 30, 2014

I would rather use relative urls, e.g. --html-location='/package/$pkg/docs'

@mtolly

This comment has been minimized.

Show comment Hide comment
@mtolly

mtolly Apr 27, 2014

What does the -Hustar in the tar command do? On OS X it was not recognized and I had to remove it.

mtolly commented Apr 27, 2014

What does the -Hustar in the tar command do? On OS X it was not recognized and I had to remove it.

@mtolly

This comment has been minimized.

Show comment Hide comment
@mtolly

mtolly Apr 27, 2014

Also note that you have to have documentation for all the linked packages on your local system, even though it's totally ignored. If you don't, then haddock won't create links for those packages.

mtolly commented Apr 27, 2014

Also note that you have to have documentation for all the linked packages on your local system, even though it's totally ignored. If you don't, then haddock won't create links for those packages.

@mtolly

This comment has been minimized.

Show comment Hide comment
@mtolly

mtolly Jun 30, 2014

/package/$pkg-version/docs should be /package/$pkg-$version/docs ($ in front of version).

mtolly commented Jun 30, 2014

/package/$pkg-version/docs should be /package/$pkg-$version/docs ($ in front of version).

@Fuuzetsu

This comment has been minimized.

Show comment Hide comment
@Fuuzetsu

Fuuzetsu Jul 29, 2014

@mtolly updated

Owner

Fuuzetsu commented Jul 29, 2014

@mtolly updated

@nh2

This comment has been minimized.

Show comment Hide comment
@nh2

nh2 Aug 31, 2014

@Fuuzetsu Can you switch the curl to https?

nh2 commented Aug 31, 2014

@Fuuzetsu Can you switch the curl to https?

@cheecheeo

This comment has been minimized.

Show comment Hide comment
@cheecheeo

cheecheeo Sep 23, 2014

curl -u ${3}:${4} worked better for me than inlining the user and password into the URL. I have a several URL metacharacters in my password.

curl -u ${3}:${4} worked better for me than inlining the user and password into the URL. I have a several URL metacharacters in my password.

@lfairy

This comment has been minimized.

Show comment Hide comment
@lfairy

lfairy Sep 24, 2014

I recommend also adding the --hoogle option to cabal haddock, so we get a Hoogle database as well.

lfairy commented Sep 24, 2014

I recommend also adding the --hoogle option to cabal haddock, so we get a Hoogle database as well.

@Fuuzetsu

This comment has been minimized.

Show comment Hide comment
@Fuuzetsu

Fuuzetsu Oct 19, 2014

@lfairy, the --hoogle Haddock flag is almost useless, the backend needs fixing severly

Owner

Fuuzetsu commented Oct 19, 2014

@lfairy, the --hoogle Haddock flag is almost useless, the backend needs fixing severly

@Fuuzetsu

This comment has been minimized.

Show comment Hide comment
@Fuuzetsu

Fuuzetsu Oct 19, 2014

@cheecheeo can you post the whole curl incantation you would like?

Owner

Fuuzetsu commented Oct 19, 2014

@cheecheeo can you post the whole curl incantation you would like?

@sol

This comment has been minimized.

Show comment Hide comment
@sol

sol Oct 22, 2014

@Fuuzetsu Have you tried to parse package name/version from cabal info ., so that $1/$2 can be omitted?

sol commented Oct 22, 2014

@Fuuzetsu Have you tried to parse package name/version from cabal info ., so that $1/$2 can be omitted?

@soenkehahn

This comment has been minimized.

Show comment Hide comment
@soenkehahn

soenkehahn Oct 23, 2014

Is the password sent over the wire as cleartext?

(I'm using a modified version of this in hope that it rectifies this: https://gist.github.com/soenkehahn/038701a58cfc0cacca57)

Is the password sent over the wire as cleartext?

(I'm using a modified version of this in hope that it rectifies this: https://gist.github.com/soenkehahn/038701a58cfc0cacca57)

@Fuuzetsu

This comment has been minimized.

Show comment Hide comment
@Fuuzetsu

Fuuzetsu Oct 28, 2014

@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.

Owner

Fuuzetsu commented Oct 28, 2014

@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.

@Rufflewind

This comment has been minimized.

Show comment Hide comment
@Rufflewind

Rufflewind Mar 19, 2016

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

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