Skip to content

サブモジュール "the-rust-programming-language-ja" の自動更新 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -42,14 +43,8 @@ after_success:
- chmod 600 ~/.ssh/deploy.key
- git config --global user.email "[email protected]"
- 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 [email protected]: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=
49 changes: 49 additions & 0 deletions ci-scripts/commit-trpl-submodule-revision.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
auto commit on travis ${TRAVIS_JOB_NUMBER} [ci skip]

Update ${TRPL_DIR} submodule to ${revision}.
EOF
)
git commit -m "${commit_message}"
local remote_url
remote_url=$(get_remote_ssh_repo_url)
echo "Pushing to ${current_branch} branch of ${remote_url}."
git push ${remote_url} ${current_branch}:${current_branch}
else
echo "There is no change in trpl submodule. (revision: ${revision})"
fi
}

exit_if_not_ci
commit_and_push_trpl_submodule_revision
41 changes: 41 additions & 0 deletions ci-scripts/common-lib
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function current_travis_branch() {
local opt_u_state
[ -o nounset ] && opt_u_state='set -u' || opt_u_state='set +u'
set +u

local branch
if [ "x_{$TRAVIS_EVENT_TYPE}" = "x_pull_request" ]; then
branch=${TRAVIS_PULL_REQUEST_BRANCH}
else
branch=${TRAVIS_BRANCH}
fi

local ret_code
if [ "x_${branch}" = "x_" ]; then
echo "ERROR: TRAVIS_*BRANCH variable(s) seem undefined. Could not get the branch info." 1>&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/#[email protected]:#')
}

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}
}
33 changes: 33 additions & 0 deletions ci-scripts/publish-pdf.sh
Original file line number Diff line number Diff line change
@@ -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