Skip to content

Commit

Permalink
Add script for deploying ldoc into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jirutka committed Dec 9, 2015
1 parent 1ee7ef5 commit f9d3d55
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ env:
# Travis uses virtualenv by default and venv rejects to install pip,
# although it should do it (maybe Ubuntu's fault).
- USE_PYTHON_VENV=no
# GH_TOKEN=xxx
- secure: X2bsMytt32eUi81MxuwnlZhYJmVijjbhs4EshlhxZdiUyPmI/MlXDpFf3FjPbkBW+loI8+EgcLb7jgZSqCDr/86/48/DCH2cvdaNgrh5s6WKjal7mqMOItI2PybrlMJWIJ01j8DJ8yPuaFU9BIdLbK7vV0oUIDKmBunBZV4H2jHl0oRlPtPK74c6zoZsbwWuQmSc17uwgZ46cRPFapTQzvmgX51OKdxxVwgmPg9Or+gE1gTAvKpdhg2OiGwn1lQHwDgY9ZwFktbSR+BwzixDpZd0u74/ggS/a4RSUcOJpxk/F2EZD/B5kKpB7JOkc8d6ycNy0YB5fLn5ht9YZNFkbic/zq3p52LyiGBKA3GSbaHkkKl4UKc0ryEjv3Abc2bYkuBWUeub6LTFZhNgXzW43mvb2cnAzodaZkLYIftVnFDJ4OBrvofIKzADj+DHM1Ej4tdWgKBOuEMZ88RMpgYhTwFf1qrSeKNGQwdjlBIfp3LAKUQazHgodaDPI93LuVenlgcF0kCLlUXXJ7mLCXx8z3/kNlD5wprvwg2Vrplv9upiITE1kPU+U6jHnM/xn6SwxSq4H5ke+xo9f/yMQyThbg3l49qRvG9jTHlhigu7Dk2zB8fBoJqrwdBFDHz/jbxzl8wJtojh3Rn6F1N4IV8spvifzdmkdWiQwA3ZoJCjrgg=
matrix:
- LUA_VERSION=luajit-2.0
- LUA_VERSION=luajit-2.1
Expand All @@ -24,5 +26,6 @@ install:
script:
- script/test
- script/test-integration
after_success: |
[ "$LUA_VERSION" = 'lua-5.1' ] && luacov-coveralls
after_success:
- '[ "$LUA_VERSION" = "lua-5.1" ] && luacov-coveralls'
- script/deploy-docs
4 changes: 4 additions & 0 deletions script/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ die() {
exit ${2:-2}
}

einfo() {
echo -e "\n$@"
}

exists() {
command -v "$1" &>/dev/null
}
Expand Down
86 changes: 86 additions & 0 deletions script/deploy-docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash
# vim: set ts=4:
#
# Generate docs using ldoc and deploy them to gh-pages branch in the repository.
#
set -e

DEPLOY_BRANCH='gh-pages'
SOURCE_BRANCH='master'

if [ -n "$TRAVIS" ]; then
export GIT_COMMITTER_NAME='Travis CI'
fi


#====================== Functions ======================#

has_changes() {
[ -n "$(git status --porcelain)" ]
}

postprocess_docs() {
# Remove Last updated timestamp.
LANG=C find "$1" -name '*.html' \
-exec sed -i.BAK 's/<i style="float:right;">Last updated.*//' {} \; \
-exec rm {}.BAK \; # sed -i behaves differently on BSD and GNU...
}

remote_url() {
if [ -n "$GH_TOKEN" ]; then
git config remote.origin.url \
| sed 's|^git:|https:|' \
| sed "s|^https://|https://${GH_TOKEN}@|"
else
git config remote.origin.url
fi
}

skip_push() {
[ -n "$TRAVIS" ] && [[ "$TRAVIS_PULL_REQUEST" != 'false' \
|| "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" \
|| "$TRAVIS_BUILD_NUMBER.1" != "$TRAVIS_JOB_NUMBER" ]]
}


#======================== Main =========================#

# Go to the project's root directory.
cd "$(dirname "$0")/.."

source script/common.sh
setup-path
script/bootstrap

einfo '==> Updating ldoc documentation...'

commit_rev="$(git rev-parse --short HEAD)"
commit_author="$(git log -n 1 --format='%aN <%aE>')"
commit_date="$(git log -n 1 --format='%aD')"
temp_dir="$(mktemp -q -d "$TEMP_DIR/doc.XXXX")"

git clone --branch="$DEPLOY_BRANCH" "$(remote_url)" "$temp_dir"

# This is needed for cleaning stale files; all docs will be regenerated.
rm -Rf -- "$temp_dir"/ldoc/*

einfo 'Running ldoc...'
ldoc --dir "$temp_dir/ldoc" --verbose .
postprocess_docs "$temp_dir/ldoc"

cd "$temp_dir"

has_changes || { einfo 'No changes'; exit 0; }
skip_push && { einfo 'Skipping push'; exit 0; }

einfo 'Commiting changes...'
git add --all
git commit \
--message="Built from $commit_rev" \
--author="$commit_author" --date="$commit_date"

einfo 'Pushing changes to repository...'
# --quite to not reveal GH_TOKEN!
git push --quiet "$(remote_url)" "${DEPLOY_BRANCH}:${DEPLOY_BRANCH}"

rm -Rf -- "$temp_dir"

0 comments on commit f9d3d55

Please sign in to comment.