diff --git a/.travis.yml b/.travis.yml index 95ad563..de5bab6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,7 @@ install: - ./tlmgr.sh update --self --all || echo "ignore errors" - ./tlmgr.sh install collection-luatex collection-langjapanese collection-fontsrecommended type1cm mdframed needspace hyphenat quotchap framed everyhook svn-prov before_script: + - (cd the-rust-programming-language-ja && git checkout master && git pull origin master) - cp trpl_meta.yml trpl-ebook/ - "echo \"pub const RELEASE_DATE: &'static str = \\\"`date +%F`\\\";\" | cat - options.rs.template > options.rs" - cp options.rs trpl-ebook/src/convert_book/ @@ -42,14 +43,8 @@ after_success: - chmod 600 ~/.ssh/deploy.key - git config --global user.email "m@yyu.pw" - git config --global user.name "Yoshimura Yuu" - - git fetch origin gh-pages:gh-pages - - git stash -u - - git checkout gh-pages - - rm a4.pdf letter.pdf - - git stash pop - - git add a4.pdf letter.pdf - - git commit -a -m "auto commit on travis $TRAVIS_JOB_NUMBER $TRAVIS_COMMIT" - - git push git@github.com:rust-lang-ja/trpl-ja-pdf.git gh-pages:gh-pages + - ./ci-scripts/commit-trpl-submodule-revision.sh + - ./ci-scripts/publish-pdf.sh env: global: secure: ck1uVFgjw0jFayZgV9enDV3n4/D5PiyW3J/ahpHHhTaO9H4tGl6vKzlsbbo9zCPRmYpHyjH/mnEDcfWXViRE72o4wYxA4zbK+JNzJK5mFUuSZB4WrD44HC9jIL99u3mLU+9DnlK6gbE3oz6JRI04Ie9L48+LeCAX6HS4iAuj8ddRIgkVUEKoZPhJ7AbFNcBtU91uQqRmpLWXeLKgkwC9jSmD//zC0DkdTHGoCD2aUCARiwBbWLn17oV8nI37eUEgV/ZaPDmwoV1JSR9KFiokWTH4QiRwwKXnw5n2nHJPmBCmEs5LmQlsuu8puZmlXg6m8xUTIheW0vTbxejZeoNP71M+7MXGP0Ix6Z1rDrx767GORjUpwhSgVwmrz7VCSgZYwze9v2j0NWsDaDXD4kruxF4j7c7YdhzPA/+K6I+NdwVE3zGyRzG6KUySbVXGAFIMzIt/yofTN1PeSy779nrnMiNI9N8AyikYmiT1ocT91j7HzMYTab250yugm6Tl80+wwlpbk0ljYR7m0ZBIopAS8HzzeSrD9Qww6PAQ9EBPvnIlhG62ttUAjRFHe7zrDSzWaD2WvdM+jmeEGCdc1iqQLteWgvsLbXOJd5GJksOgRX/rRa++ioq2/+P/aGEyFeNXWMD3ru2V3eDDL2kBpnLv93JmsdRorGsFDOFsau2i0TI= diff --git a/ci-scripts/commit-trpl-submodule-revision.sh b/ci-scripts/commit-trpl-submodule-revision.sh new file mode 100755 index 0000000..2ca79a6 --- /dev/null +++ b/ci-scripts/commit-trpl-submodule-revision.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# This script commits trpl submodule's revision if it has been changed, and +# pushes the commit to the remote repository. +# +# Requires: `bash` -- because `local` and `pipefail` are used. + +set -u -e -o pipefail + +source ./ci-scripts/common-lib + +TRPL_DIR=the-rust-programming-language-ja + +function commit_and_push_trpl_submodule_revision() { + local current_branch + current_branch=$(current_travis_branch) + + # Get the revision of trpl submodule. + local revision + revision=$(cd ${TRPL_DIR}; git rev-parse --short HEAD) + + git checkout ${current_branch} + git add ${TRPL_DIR} + local ret + set +e + ret=$(git status | grep -q 'Changes to be committed:'; echo $?) + set -e + + if [ $ret -eq 0 ] ; then + echo "Committing trpl submodule's new revision ${revision}." + local commit_message; + commit_message=$(cat <&2 + ret_code=1 + else + echo ${branch} + ret_code=0 + fi + + eval ${opt_u_state} + return ${ret_code} +} + +function get_remote_ssh_repo_url() { + echo $(git remote get-url origin | sed -e 's#https://github.com/#git@github.com:#') +} + +function exit_if_not_ci() { + local opt_u_state + [ -o nounset ] && opt_u_state='set -u' || opt_u_state='set +u' + set +u + + if [ -z "${TRAVIS+x}" -o "x_${TRAVIS}" != "x_true" ]; then + echo "ERROR: Exiting because this script was not triggered by Travis CI." 1>&2 + exit 1 + fi + + eval ${opt_u_state} +} diff --git a/ci-scripts/publish-pdf.sh b/ci-scripts/publish-pdf.sh new file mode 100755 index 0000000..e6ae304 --- /dev/null +++ b/ci-scripts/publish-pdf.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +# This script checks if this build was performed on the `master` branch, +# and if so, it pushes the PDF files to `origin/gh-pages` branch. +# +# Requires: `bash` -- because `local` and `pipefail` are used. + +set -u -e -o pipefail + +source ./ci-scripts/common-lib + +function push_pdf_files_to_gh_pages() { + git fetch origin gh-pages:gh-pages + git stash -u + git checkout gh-pages + rm a4.pdf letter.pdf + git stash pop + git add a4.pdf letter.pdf + git commit -a -m "auto commit on travis $TRAVIS_JOB_NUMBER $TRAVIS_COMMIT [ci skip]" + local remote_url + remote_url=$(get_remote_ssh_repo_url) + echo "Pushing the PDF files to gh-pages branch of ${remote_url}." + git push ${remote_url} gh-pages:gh-pages +} + +exit_if_not_ci + +CURRENT_BRANCH=$(current_travis_branch) +if [ "x_${CURRENT_BRANCH}" = "x_master" ]; then + push_pdf_files_to_gh_pages +else + echo "Not pushing the PDF files to gh-pages because the current branch ${CURRENT_BRANCH} is not master branch." +fi