Skip to content

Commit 14ec179

Browse files
committed
Brush up CircleCI job to trigger a Travis CI job for trpl-ja-pdf
- Add an env variable: TRPL_JA_PDF_GITHUB_BRANCH - Fix `curl` params and the way to parse response.
1 parent 2d77cd4 commit 14ec179

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@
1717
# To obtain a Travis auth token, follow the instructions on:
1818
# https://docs.travis-ci.com/user/triggering-builds/
1919
#
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+
#
2025
# - TRPL_JA_PDF_GITHUB_REPO (Optional):
2126
# The GitHub repository name of trpl-ja-pdf, default to
2227
# `trpl-ja-pdf`. To override it, define this variable at
2328
# CircleCI's web console or in circle.yml.
2429
#
25-
# - TRPL_JA_PDF_GITHUB_ORG (Optional):
26-
# The GitHub organization or user name of trpl-ja-pdf, default to
27-
# `rust-lanu-ja`. To override it, define this variable at
28-
# CirildCI's web console or in circle.yml.
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.
2934

3035
set -e
3136

@@ -36,37 +41,41 @@ if [ -z "${TRPL_JA_PDF_TRAVIS_AUTH_TOKEN+x}" ]; then
3641
exit 1
3742
fi
3843

39-
GITHUB_REPO=${TRPL_JA_PDF_GITHUB_REPO:-tarpl-ja-pdf}
4044
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}
4147

4248
set -u
4349

4450
# Get the revision of current branch.
4551
REVISION=$(git rev-parse --short HEAD)
4652

47-
BUILD_PARAMS='{
53+
BUILD_PARAMS=$(cat <<EOF
54+
{
4855
"request": {
49-
"branch": "master"
56+
"branch": "${GITHUB_BRANCH}",
5057
"message": "automatic build triggered by trpl-ja commit ${REVISION}"
5158
}
52-
}'
59+
}
60+
EOF
61+
)
5362

54-
echo "Triggering a build on Travis CI for ${GITHUB_ORG}/${GITHUB_REPO}."
63+
echo "Triggering a build on Travis CI for ${GITHUB_BRANCH} branch of ${GITHUB_ORG}/${GITHUB_REPO}."
5564

56-
set +e
57-
curl -s -X POST \
65+
HTTP_RESPONSE=$(curl -s -X POST \
66+
-w " - HTTP Status %{http_code}" \
5867
-H "Content-Type: application/json" \
5968
-H "Accept: application/json" \
6069
-H "Travis-API-Version: 3" \
6170
-H "Authorization: token ${TRPL_JA_PDF_TRAVIS_AUTH_TOKEN}" \
6271
-d "$BUILD_PARAMS" \
63-
https://api.travis-ci.org/repo/${GITHUB_ORG}%2F${GITHUB_REPO}/requests
64-
RET=$?
65-
set -e
72+
https://api.travis-ci.org/repo/${GITHUB_ORG}%2F${GITHUB_REPO}/requests)
6673

67-
if [ $RET -eq 0 ]; then
68-
echo "Successfully triggered the Travis CI build."
74+
if [[ "x_${HTTP_RESPONSE}" =~ "HTTP Status 202" ]]; then
75+
echo "Successfully triggered the Travis CI build:"
76+
echo "${HTTP_RESPONSE}"
6977
else
70-
echo "Failed to trigger the Travis CI build."
78+
echo "Failed to trigger the Travis CI build:"
79+
echo "${HTTP_RESPONSE}"
7180
exit 1
7281
fi

0 commit comments

Comments
 (0)