-
-
Save michiel/2df9db91c22026eb9ab79b4482ae5c99 to your computer and use it in GitHub Desktop.
A post-commit hook to update a rust project's gh-pages.
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
#!/bin/bash | |
set -e | |
[[ "$(git symbolic-ref --short HEAD)" == "master" ]] || exit 0 | |
msg() { | |
echo "[1;34m> [1;32m$@[0m" | |
} | |
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