citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

hackage-docs (1428B)


      1 #!/usr/bin/env bash
      2 set -e
      3 
      4 if [ "$#" -ne 1 ]; then
      5   echo "Usage: scripts/hackage-docs.sh HACKAGE_USER"
      6   exit 1
      7 fi
      8 
      9 user=$1
     10 
     11 cabal_file=$(find . -maxdepth 1 -name "*.cabal" -print -quit)
     12 if [ ! -f "$cabal_file" ]; then
     13   echo "Run this script in the top-level package directory"
     14   exit 1
     15 fi
     16 
     17 pkg=$(awk -F ":[[:space:]]*" 'tolower($1)=="name"    { print $2 }' < "$cabal_file")
     18 ver=$(awk -F ":[[:space:]]*" 'tolower($1)=="version" { print $2 }' < "$cabal_file")
     19 
     20 if [ -z "$pkg" ]; then
     21   echo "Unable to determine package name"
     22   exit 1
     23 fi
     24 
     25 if [ -z "$ver" ]; then
     26   echo "Unable to determine package version"
     27   exit 1
     28 fi
     29 
     30 echo "Detected package: $pkg-$ver"
     31 
     32 dir=$(mktemp -d build-docs.XXXXXX)
     33 trap 'rm -r "$dir"' EXIT
     34 
     35 
     36 if haddock --hyperlinked-source >/dev/null
     37 then
     38   echo "Using fancy hyperlinked source"
     39   HYPERLINK_FLAG="--haddock-option=--hyperlinked-source"
     40 else
     41   echo "Using boring hyperlinked source"
     42   HYPERLINK_FLAG="--hyperlink-source"
     43 fi
     44 
     45 cabal haddock --hoogle $HYPERLINK_FLAG --html-location='/package/$pkg-$version/docs' --contents-location='/package/$pkg-$version'
     46 
     47 cp -R dist/doc/html/$pkg/ $dir/$pkg-$ver-docs
     48 
     49 tar cvz -C $dir --format=ustar -f $dir/$pkg-$ver-docs.tar.gz $pkg-$ver-docs
     50 
     51 curl -X PUT \
     52      -H 'Content-Type: application/x-tar' \
     53      -H 'Content-Encoding: gzip' \
     54      -u "$user" \
     55      --data-binary "@$dir/$pkg-$ver-docs.tar.gz" \
     56      "https://hackage.haskell.org/package/$pkg-$ver/docs"