Skip to content

Commit d72d993

Browse files
authored
Merge pull request #278 from tatsuya6502/triggering-trpl-ja-pdf
PDF 生成ジョブ(trpl-ja-pdf)の自動起動
2 parents fb31d86 + 41acec9 commit d72d993

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

circle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ deployment:
6666
# are updated from 1.6.
6767
- rm -rf docs/1.9
6868
- ./tools/circleci/push-to-master.sh
69+
- ./tools/circleci/trigger-trpl-pdf-ja.sh
6970
# - ./tools/circleci/publish-to-gh-pages.sh

tools/circleci/trigger-trpl-pdf-ja.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
3+
# This script triggers a Travis CI build on trpl-ja-pdf to generates
4+
# PDF files of TRPL. It does so by sending a request to Travis's API
5+
# server.
6+
#
7+
# This script referes to the following mandatory and optional
8+
# environment variables:
9+
#
10+
# - TRPL_JA_PDF_TRAVIS_AUTH_TOKEN (Mandatory):
11+
# The auth token required by Travis CI web API. Since this
12+
# variable carries a sensitive data, it should not be defined in
13+
# circle.yml. Instead, it should be defined at Circle CI's web
14+
# console at:
15+
# https://circleci.com/gh/rust-lang-ja/the-rust-programming-language-ja/edit#env-vars
16+
#
17+
# To obtain a Travis auth token, follow the instructions on:
18+
# https://docs.travis-ci.com/user/triggering-builds/
19+
#
20+
# - TRPL_JA_PDF_GITHUB_ORG (Optional):
21+
# The GitHub organization or user name of trpl-ja-pdf, default to
22+
# `rust-lanu-ja`. To override it, define this variable at
23+
# CirildCI's web console or in circle.yml.
24+
#
25+
# - TRPL_JA_PDF_GITHUB_REPO (Optional):
26+
# The GitHub repository name of trpl-ja-pdf, default to
27+
# `trpl-ja-pdf`. To override it, define this variable at
28+
# CircleCI's web console or in circle.yml.
29+
#
30+
# - TRPL_JA_PDF_GITHUB_BRANCH (Optional):
31+
# The GitHub branch of trpl-ja-pdf, default to `master`. To
32+
# override it, define this variable at CircleCI's web console or
33+
# in circle.yml.
34+
35+
set -e
36+
37+
if [ -z "${TRPL_JA_PDF_TRAVIS_AUTH_TOKEN+x}" ]; then
38+
echo "ERROR: Environment variable TRPL_JA_PDF_TRAVIS_AUTH_TOKEN is undefined."
39+
echo " If you want to trigger a Travis CI build for trpl-ja-pdf,"
40+
echo " please read comments in this script to define the variable."
41+
exit 1
42+
fi
43+
44+
GITHUB_ORG=${TRPL_JA_PDF_GITHUB_ORG:-rust-lang-ja}
45+
GITHUB_REPO=${TRPL_JA_PDF_GITHUB_REPO:-trpl-ja-pdf}
46+
GITHUB_BRANCH=${TRPL_JA_PDF_GITHUB_BRANCH:-master}
47+
48+
set -u
49+
50+
# Get the revision of current branch.
51+
REVISION=$(git rev-parse --short HEAD)
52+
53+
BUILD_PARAMS=$(cat <<EOF
54+
{
55+
"request": {
56+
"branch": "${GITHUB_BRANCH}",
57+
"message": "automatic build triggered by trpl-ja commit ${REVISION}"
58+
}
59+
}
60+
EOF
61+
)
62+
63+
echo "Triggering a build on Travis CI for ${GITHUB_BRANCH} branch of ${GITHUB_ORG}/${GITHUB_REPO}."
64+
65+
HTTP_RESPONSE=$(curl -s -X POST \
66+
-w " - HTTP Status %{http_code}" \
67+
-H "Content-Type: application/json" \
68+
-H "Accept: application/json" \
69+
-H "Travis-API-Version: 3" \
70+
-H "Authorization: token ${TRPL_JA_PDF_TRAVIS_AUTH_TOKEN}" \
71+
-d "$BUILD_PARAMS" \
72+
https://api.travis-ci.org/repo/${GITHUB_ORG}%2F${GITHUB_REPO}/requests)
73+
74+
if [[ "x_${HTTP_RESPONSE}" =~ "HTTP Status 202" ]]; then
75+
echo "Successfully triggered the Travis CI build:"
76+
echo "${HTTP_RESPONSE}"
77+
else
78+
echo "Failed to trigger the Travis CI build:"
79+
echo "${HTTP_RESPONSE}"
80+
exit 1
81+
fi

0 commit comments

Comments
 (0)