|
| 1 | +#!/usr/bin/env sh |
| 2 | + |
| 3 | +PLANSHOME="${HOME}/testground/plans" |
| 4 | + |
| 5 | +# exit codes determine the result of the CheckRun |
| 6 | +# https://docs.github.com/en/actions/creating-actions/setting-exit-codes-for-actions |
| 7 | +SUCCESS=0 |
| 8 | +FAILURE=1 |
| 9 | + |
| 10 | +# For github to collect the action output, use these strings: |
| 11 | +OUTPUT_STATUS="::set-output name=status::" |
| 12 | +OUTPUT_OUTCOME="::set-output name=outcome::" |
| 13 | + |
| 14 | +BACKEND="${INPUT_BACKEND_PROTO}"'://'"${INPUT_BACKEND_ADDR}" |
| 15 | + |
| 16 | +# Make sure the input files exist. |
| 17 | +test -d "${INPUT_PLAN_DIRECTORY}" || exit "${FALURE}" |
| 18 | +test -f "${INPUT_COMPOSITION_FILE}" || exit "${FAILURE}" |
| 19 | + |
| 20 | +REAL_PLAN_DIR=$(realpath $INPUT_PLAN_DIRECTORY) |
| 21 | +REAL_COMP_FILE=$(realpath $INPUT_COMPOSITION_FILE) |
| 22 | + |
| 23 | +# link plan to testground home |
| 24 | +mkdir -p "${PLANSHOME}" |
| 25 | +ln -s "${REAL_PLAN_DIR}" "${PLANSHOME}" |
| 26 | + |
| 27 | +echo real quick ls |
| 28 | +ls -l "${PLANSHOME}" |
| 29 | + |
| 30 | +# Run test and wait until finished. |
| 31 | +# There is a --wait option, so it might work to use it like this |
| 32 | +# testground --endpoint "$BACKEND" run composition -f "$REAL_COMP_FILE" --wait |
| 33 | +# However, --wait doesn't always work well particularly for long-running jobs |
| 34 | +# so instead, do a long poll. |
| 35 | +/testground --endpoint "${BACKEND}" run composition -f "${REAL_COMP_FILE}" | tee testground.out |
| 36 | +TGID=$(awk '/run is queued with ID/ {print $10}' <testground.out) |
| 37 | + |
| 38 | +echo "Got testground ID ${TGID}" |
| 39 | +echo "Waiting for job to complete." |
| 40 | + |
| 41 | +while [ "${status}" != "complete" ] |
| 42 | +do |
| 43 | + sleep 30 |
| 44 | + status=$(/testground --endpoint "${BACKEND}" status -t "${TGID}" | awk '/Status/ {print $2}') |
| 45 | + echo "last polled status is ${status}" |
| 46 | + echo "${OUTPUT_STATUS}${status}" |
| 47 | +done |
| 48 | + |
| 49 | +echo getting extended status |
| 50 | +/testground --endpoint "${BACKEND}" status -t "${TGID}" --extended | tee extendedstatus.out |
| 51 | +# Get the extened status, which includes a "Result" section. |
| 52 | +# Capture the line that occurs after "Result" |
| 53 | +extstatus=$(awk '/Result/ {getline; print $0}' <extendedstatus.out) |
| 54 | + |
| 55 | +# First off, there are control characters in this output, and we need to remove that. |
| 56 | +extstatus=$(echo "${extstatus}" | tr -d "[:cntrl:]" | sed 's/\[0m //g') |
| 57 | + |
| 58 | +# test if we got a result at all. The result might be "null". A null result means most likely the |
| 59 | +# job was canceled before it began for some reason. |
| 60 | +if [ "${extstatus}" == "null" ] |
| 61 | +then |
| 62 | + echo "${OUTPUT_OUTCOME}failure/canceled" |
| 63 | + exit "$FAILURE" |
| 64 | +fi |
| 65 | + |
| 66 | +# Now find the outcome of the test. The extended result is going to look something like this: |
| 67 | +# {"journal":{"events":{},"pods_statuses":{}},"outcome":"success","outcomes":{"providers":{"ok":1,"total":1},"requestors":{"ok":1,"total":1}}} |
| 68 | + |
| 69 | +outcome=$(echo "${extstatus} | jq ".outcome") |
| 70 | +
|
| 71 | +echo "The outcome of this test was ${outcome}" |
| 72 | +echo "${OUTPUT_OUTCOME}${outcome}" |
| 73 | +
|
| 74 | +test "${outcome}" = "\"success\"" && exit "${SUCCESS}" || exit "${FAILURE}" |
0 commit comments