Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion scripts/swm-macos-runner/guest/run-job.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash
# Guest entrypoint: read the JIT config from stdin (never argv), then run the runner for one job.
set -euo pipefail
# Jobs inherit this PATH. Homebrew first, as on macos-latest: else bash is 3.2
# and python3 is CLT 3.9.
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
jit="$(cat)"
if [[ -z "${jit}" ]]; then
echo "run-job: JIT config on stdin is empty" >&2
exit 2
fi
cd /Users/admin/actions-runner
cd "${SWM_RUNNER_DIR:-/Users/admin/actions-runner}"
exec ./run.sh --jitconfig "${jit}"
46 changes: 46 additions & 0 deletions scripts/swm-macos-runner/tests/test-run-job.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# Tests guest/run-job.sh against a stub run.sh in a temp runner dir.
set -u
here="$(cd "$(dirname "$0")" && pwd)"
job="${here}/../guest/run-job.sh"
t="$(mktemp -d "${TMPDIR:-/tmp}/runjob.XXXXXX")"
trap 'rm -r "${t}"' EXIT
pass=0
fail=0
check() { # label command...
local label="$1"
shift
if "$@"; then
pass=$((pass + 1))
echo " PASS: ${label}"
else
fail=$((fail + 1))
echo " FAIL: ${label}"
fi
}

# The stub records the PATH and arguments the runner would get.
cat >"${t}/run.sh" <<'EOF'
#!/bin/bash
printf 'PATH=%s\n' "${PATH}" >"${OUT}"
printf 'ARG=%s\n' "$@" >>"${OUT}"
EOF
chmod +x "${t}/run.sh"

out="${t}/out"
printf 'jit-blob' | env -i PATH=/usr/bin:/bin OUT="${out}" SWM_RUNNER_DIR="${t}" /bin/bash "${job}"
rc=$?
check "exit 0 with a JIT config" test "${rc}" = 0
check "Homebrew bin comes first in the job PATH" grep -q '^PATH=/opt/homebrew/bin:' "${out}"
check "system dirs stay in the job PATH" grep -q ':/usr/bin:/bin:' "${out}"
check "JIT config passed as --jitconfig" grep -qx 'ARG=--jitconfig' "${out}"
check "JIT config value passed" grep -qx 'ARG=jit-blob' "${out}"

rm -f "${out}"
env -i PATH=/usr/bin:/bin OUT="${out}" SWM_RUNNER_DIR="${t}" /bin/bash "${job}" </dev/null 2>/dev/null
rc=$?
check "empty stdin exits 2" test "${rc}" = 2
check "empty stdin never starts the runner" test ! -e "${out}"

echo "run-job: ${pass} passed, ${fail} failed"
[[ "${fail}" == 0 ]]
Loading