From f9d3d5531c08f75a7b894198810be95200cd0360 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Wed, 9 Dec 2015 16:28:40 +0100 Subject: [PATCH] Add script for deploying ldoc into gh-pages --- .travis.yml | 7 ++-- script/common.sh | 4 +++ script/deploy-docs | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100755 script/deploy-docs diff --git a/.travis.yml b/.travis.yml index cabc589..d6addc2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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 diff --git a/script/common.sh b/script/common.sh index c3c569a..a734af2 100644 --- a/script/common.sh +++ b/script/common.sh @@ -10,6 +10,10 @@ die() { exit ${2:-2} } +einfo() { + echo -e "\n$@" +} + exists() { command -v "$1" &>/dev/null } diff --git a/script/deploy-docs b/script/deploy-docs new file mode 100755 index 0000000..90fcaee --- /dev/null +++ b/script/deploy-docs @@ -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/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"