git.iko.soy/typeable/servant-swagger-ui
on v0.2.4.3.0.20 help sign in
78 lines 2.1 kB history raw
1#!/bin/bash
2set -e
4# This if stack-enabled fork of https://github.com/ekmett/lens/blob/master/scripts/hackage-docs.sh
6if [ "$#" -ne 1 ]; then
7 echo "Usage: scripts/hackage-docs.sh HACKAGE_USER"
8 exit 1
9fi
11user=$1
13cabal_file=$(find . -maxdepth 1 -name "*.cabal" -print -quit)
14if [ ! -f "$cabal_file" ]; then
15 echo "Run this script in the top-level package directory"
16 exit 1
17fi
19pkg=$(awk -F ":[[:space:]]*" 'tolower($1)=="name" { print $2 }' < "$cabal_file")
20ver=$(awk -F ":[[:space:]]*" 'tolower($1)=="version" { print $2 }' < "$cabal_file")
22if [ -z "$pkg" ]; then
23 echo "Unable to determine package name"
24 exit 1
25fi
27if [ -z "$ver" ]; then
28 echo "Unable to determine package version"
29 exit 1
30fi
32echo "Detected package: $pkg-$ver"
34dir=$(mktemp -d build-docs.XXXXXX)
35trap 'rm -r "$dir"' EXIT
37export PATH=$(stack path --bin-path)
39ghc --version
40cabal --version
41stack --version
43if haddock --hyperlinked-source >/dev/null
44then
45 echo "Using fancy hyperlinked source"
46 HYPERLINK_FLAG="--haddock-option=--hyperlinked-source"
47else
48 echo "Using boring hyperlinked source"
49 HYPERLINK_FLAG="--hyperlink-source"
50fi
52# Cabal dist in temporary location
53builddir=$dir/dist
55# Build dependencies haddocks with stack, so we get links
56stack haddock --only-dependencies
58# Configure using stack databases
59snapshotpkgdb=$(stack path --snapshot-pkg-db)
60localpkgdb=$(stack path --local-pkg-db)
61cabal configure -v2 --builddir=$builddir --package-db=clear --package-db=global --package-db=$snapshotpkgdb --package-db=$localpkgdb
63# Build Hadckage compatible docs
64cabal haddock -v2 --builddir=$builddir $HYPERLINK_FLAG --html-location='/package/$pkg-$version/docs' --contents-location='/package/$pkg-$version'
66# Copy into right directory
67cp -R $builddir/doc/html/$pkg/ $dir/$pkg-$ver-docs
69# Tar and gzip
70tar cvz -C $dir --format=ustar -f $dir/$pkg-$ver-docs.tar.gz $pkg-$ver-docs
72# Upload
73curl -X PUT \
74 -H 'Content-Type: application/x-tar' \
75 -H 'Content-Encoding: gzip' \
76 -u "$user" \
77 --data-binary "@$dir/$pkg-$ver-docs.tar.gz" \
78 "https://hackage.haskell.org/package/$pkg-$ver/docs"