Travis: travis_trigger.sh script.
authorJoel Martin <github@martintribe.org>
Fri, 31 May 2019 02:37:47 +0000 (21:37 -0500)
committerJoel Martin <github@martintribe.org>
Fri, 31 May 2019 03:16:46 +0000 (22:16 -0500)
.travis_test.sh
runtest.py
tests/travis_trigger.sh [new file with mode: 0755]

index a5111fc..aa814e5 100755 (executable)
@@ -5,25 +5,24 @@ set -ex
 ACTION=${1}
 IMPL=${2}
 
+# Environment variable configuration
 BUILD_IMPL=${BUILD_IMPL:-${IMPL}}
+TEST_OPTS="${TEST_OPTS} --debug-file ../${ACTION}.err"
 
-# Special tags/branches
-case "${TRAVIS_BRANCH}" in
-self-host-test)
+if [ "${DO_SELF_HOST}" ]; then
     MAL_IMPL=${IMPL}
     IMPL=mal
-    ;;
-esac
-
-mode_var=${MAL_IMPL:-${IMPL}}_MODE
-mode_val=${!mode_var}
+fi
+if [ "${DO_HARD}" ]; then
+    TEST_OPTS="${TEST_OPTS} --hard"
+fi
 
 echo "ACTION: ${ACTION}"
 echo "IMPL: ${IMPL}"
 echo "BUILD_IMPL: ${BUILD_IMPL}"
 echo "MAL_IMPL: ${MAL_IMPL}"
 
-if [ "${MAL_IMPL}" ]; then
+if [ "${DO_SELF_HOST}" ]; then
     if [ "${NO_SELF_HOST}" ]; then
         echo "Skipping ${ACTION} of ${MAL_IMPL} self-host"
         exit 0
@@ -34,6 +33,9 @@ if [ "${MAL_IMPL}" ]; then
     fi
 fi
 
+mode_var=${MAL_IMPL:-${IMPL}}_MODE
+mode_val=${!mode_var}
+
 MAKE="make ${mode_val:+${mode_var}=${mode_val}}"
 
 # If NO_DOCKER is blank then launch use a docker image, otherwise use
@@ -55,14 +57,14 @@ build)
     ${MAKE} -C ${BUILD_IMPL}
     ;;
 test|perf)
-    if ! ${MAKE} TEST_OPTS="--debug-file ../${ACTION}.err" \
+    [ "${ACTION}" = "perf" ] && STEP=
+    if ! ${MAKE} TEST_OPTS="${TEST_OPTS}" \
             ${MAL_IMPL:+MAL_IMPL=${MAL_IMPL}} \
-            ${ACTION}^${IMPL}; then
+            ${REGRESS:+REGRESS=${REGRESS}} \
+            ${ACTION}^${IMPL}${STEP:+^${STEP}}; then
         # print debug-file on error
         cat ${ACTION}.err
         false
     fi
     ;;
 esac
-
-
index 4da1907..8e9f12f 100755 (executable)
@@ -54,7 +54,7 @@ parser.add_argument('--log-file', type=str,
 parser.add_argument('--debug-file', type=str,
         help="Write all test interaction the named file")
 parser.add_argument('--hard', action='store_true',
-        help="Turn soft tests following a ';>>> soft=True' into hard failures")
+        help="Turn soft tests (soft, deferrable, optional) into hard failures")
 
 # Control whether deferrable and optional tests are executed
 parser.add_argument('--deferrable', dest='deferrable', action='store_true',
diff --git a/tests/travis_trigger.sh b/tests/travis_trigger.sh
new file mode 100755 (executable)
index 0000000..007f49f
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+set -e
+
+die() { echo "${*}"; exit 1; }
+usage() {
+    [ "${*}" ] && echo >&2 -e "${*}\n"
+    echo "Usage: $0 REPO BRANCH [VAR=VAL]...
+
+    Examples:
+
+      Trigger build/test in self-hosted mode:
+        $0 REPO BRANCH DO_SELF_HOST=1
+
+      Trigger build/test with stop on soft failures:
+        $0 REPO BRANCH DO_HARD=1
+
+      Trigger build/test using regress mode on stepA:
+        $0 REPO BRANCH REGRESS=1 STEP=stepA
+
+      Trigger build/test using regress mode on all steps:
+        $0 REPO BRANCH REGRESS=1
+    " | sed 's/^    //' >&2
+
+    exit 2
+}
+
+REPO="${1}"; shift || usage "REPO required"
+BRANCH="${1}"; shift || usage "BRANCH required"
+VARS="${*}"
+
+repo="${REPO/\//%2F}"
+vars=""
+[ "${VARS}" ] && vars="\"${VARS// /\", \"}\""
+
+body="{
+  \"request\": {
+    \"message\": \"Manual build. Settings: ${VARS}\",
+    \"branch\":\"${BRANCH}\",
+    \"config\": {
+      \"env\": {
+        \"global\": [${vars}]
+      }
+    }
+  }
+}"
+
+token="$(travis token --org --no-interactive)"
+
+curl -X POST \
+  -H "Content-Type: application/json" \
+  -H "Accept: application/json" \
+  -H "Travis-API-Version: 3" \
+  -H "Authorization: token ${token}" \
+  -d "$body" \
+  "https://api.travis-ci.org/repo/${repo}/requests"