Finish step8
[jackhill/mal.git] / impls / tests / travis_trigger.sh
1 #!/bin/bash
2
3 # Reference: https://docs.travis-ci.com/user/triggering-builds/
4
5 set -e
6
7 die() { echo "${*}"; exit 1; }
8 usage() {
9 [ "${*}" ] && echo >&2 -e "${*}\n"
10 echo "Usage: $0 REPO BRANCH [VAR=VAL]...
11
12 Authorization:
13
14 If you have the travis program installed then it will be called
15 to get an API token (you need to have done 'travis login --org'
16 in the past). Alternately you can explicity pass a token using
17 the TRAVIS_TOKEN environment variable. You can see your API
18 token at https://travis-ci.org/account/preferences.
19
20 Travis .org vs .com:
21
22 By default 'api.travis-ci.org' is used for API calls. This can
23 be overridden by setting TRAVIS_HOST="api.travis-ci.com"
24
25 Examples:
26
27 Trigger build/test in self-hosted mode:
28 $0 REPO BRANCH DO_SELF_HOST=1
29
30 Trigger build/test with stop on soft failures:
31 $0 REPO BRANCH DO_HARD=1
32
33 Trigger build/test using regress mode on stepA:
34 $0 REPO BRANCH REGRESS=1 STEP=stepA
35
36 Trigger build/test using regress mode on all steps:
37 $0 REPO BRANCH REGRESS=1
38 " | sed 's/^ //' >&2
39
40 exit 2
41 }
42
43 TRAVIS_TOKEN="${TRAVIS_TOKEN:-}" # default to travis program
44 TRAVIS_HOST="${TRAVIS_HOST:-api.travis-ci.org}"
45
46 REPO="${1}"; shift || usage "REPO required"
47 BRANCH="${1}"; shift || usage "BRANCH required"
48 VARS="${*}"
49
50 repo="${REPO/\//%2F}"
51 vars=""
52 [ "${VARS}" ] && vars="\"${VARS// /\", \"}\""
53
54 body="{
55 \"request\": {
56 \"message\": \"Manual build. Settings: ${VARS}\",
57 \"branch\":\"${BRANCH}\",
58 \"config\": {
59 \"env\": {
60 \"global\": [${vars}]
61 }
62 }
63 }
64 }"
65
66 if [ -z "${TRAVIS_TOKEN}" ]; then
67 which travis >/dev/null \
68 || die "TRAVIS_TOKEN not set and travis command not found"
69 TRAVIS_TOKEN="$(travis token --org --no-interactive)"
70 fi
71
72 curl -X POST \
73 -H "Content-Type: application/json" \
74 -H "Accept: application/json" \
75 -H "Travis-API-Version: 3" \
76 -H "Authorization: token ${TRAVIS_TOKEN}" \
77 -d "$body" \
78 "https://${TRAVIS_HOST}/repo/${repo}/requests"