Skip to content

Instantly share code, notes, and snippets.

@Stebalien
Last active September 21, 2017 22:34
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Stebalien/d4a32c4abc03376db903 to your computer and use it in GitHub Desktop.
Save Stebalien/d4a32c4abc03376db903 to your computer and use it in GitHub Desktop.
A post-commit hook to update a rust project's gh-pages.
#!/bin/bash
set -e
[[ "$(git symbolic-ref --short HEAD)" == "master" ]] || exit 0
msg() {
echo "> $@"
}
dir="$(pwd)"
tmp="$(mktemp -d)"
last_rev="$(git rev-parse HEAD)"
last_msg="$(git log -1 --pretty=%B)"
trap "cd \"$dir\"; rm -rf \"$tmp\"" EXIT
msg "Cloning into a temporary directory..."
git clone -qb gh-pages $dir $tmp
cd "$tmp"
git checkout -q master
ln -s $dir/target $tmp/target
msg "Generating documentation..."
cargo doc
# Switch to pages
msg "Replacing documentation..."
git checkout -q gh-pages
# Clean and replace
git rm -q --ignore-unmatch -rf .
git reset -q -- .gitignore
git checkout -q -- .gitignore
cp -a target/doc/* .
rm target
git add .
git commit -m "Update docs for $last_rev" -m "$last_msg"
git push -qu origin gh-pages
msg "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment