Skip to content

Commit 05fbabe

Browse files
author
Cory Schwartz
committed
testground github action
0 parents  commit 05fbabe

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Copy the binary from testground
2+
3+
# ARG TG_VERSION=v0.5.1
4+
ARG TG_VERSION=edge
5+
FROM iptestground/testground:${TG_VERSION}
6+
7+
## Runtime env
8+
9+
FROM alpine
10+
RUN apk add curl jq
11+
COPY --from=0 /testground /testground
12+
COPY entrypoint.sh /entrypoint.sh
13+
ENTRYPOINT ["/entrypoint.sh"]

action.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: 'testground-composition'
3+
description: 'Run a Testground composition'
4+
inputs:
5+
backend_addr:
6+
description: 'api endpoint for the testground daemon'
7+
required: true
8+
default: 'ci.testground.ipfs.team'
9+
backend_proto:
10+
description: 'protocol (i.e. http/https) to use when connecting to the backend'
11+
required: true
12+
default: 'https'
13+
plan_directory:
14+
description: 'testplan path relative to the root of the git directory'
15+
required: true
16+
composition_file:
17+
description: 'composition file path relative to the root of the git directory'
18+
required: true
19+
outputs:
20+
status:
21+
description: 'status of the testground run, i.e. completed/cancled'
22+
outcome:
23+
description: 'high-level result of the test'
24+
runs:
25+
using: 'docker'
26+
image: './Dockerfile'
27+
args:
28+
- ${{ inputs.backend }}
29+
- ${{ inputs.plan_directory }}
30+
- ${{ inputs.composition_file }}

entrypoint.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

Comments
 (0)