generate perf analysis
[jackhill/mal.git] / impls / tests / travis_trigger.sh
CommitLineData
108d07a2
JM
1#!/bin/bash
2
4aa1c85b
JM
3# Reference: https://docs.travis-ci.com/user/triggering-builds/
4
108d07a2
JM
5set -e
6
7die() { echo "${*}"; exit 1; }
8usage() {
4aa1c85b
JM
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.
108d07a2 19
4aa1c85b 20 Travis .org vs .com:
108d07a2 21
4aa1c85b
JM
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"
108d07a2 24
4aa1c85b 25 Examples:
108d07a2 26
4aa1c85b
JM
27 Trigger build/test in self-hosted mode:
28 $0 REPO BRANCH DO_SELF_HOST=1
108d07a2 29
4aa1c85b
JM
30 Trigger build/test with stop on soft failures:
31 $0 REPO BRANCH DO_HARD=1
108d07a2 32
4aa1c85b
JM
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
108d07a2
JM
41}
42
4aa1c85b
JM
43TRAVIS_TOKEN="${TRAVIS_TOKEN:-}" # default to travis program
44TRAVIS_HOST="${TRAVIS_HOST:-api.travis-ci.org}"
45
108d07a2
JM
46REPO="${1}"; shift || usage "REPO required"
47BRANCH="${1}"; shift || usage "BRANCH required"
48VARS="${*}"
49
50repo="${REPO/\//%2F}"
51vars=""
52[ "${VARS}" ] && vars="\"${VARS// /\", \"}\""
53
54body="{
55 \"request\": {
56 \"message\": \"Manual build. Settings: ${VARS}\",
57 \"branch\":\"${BRANCH}\",
58 \"config\": {
59 \"env\": {
60 \"global\": [${vars}]
61 }
62 }
63 }
64}"
65
4aa1c85b
JM
66if [ -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)"
70fi
108d07a2
JM
71
72curl -X POST \
73 -H "Content-Type: application/json" \
74 -H "Accept: application/json" \
75 -H "Travis-API-Version: 3" \
4aa1c85b 76 -H "Authorization: token ${TRAVIS_TOKEN}" \
108d07a2 77 -d "$body" \
4aa1c85b 78 "https://${TRAVIS_HOST}/repo/${repo}/requests"