-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·72 lines (60 loc) · 1.76 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·72 lines (60 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
set -Eeuo pipefail
: "${INPUT_TIMELIMIT:?Missing input: timelimit}"
: "${INPUT_COMMAND:?Missing input: command}"
: "${INPUT_SIGNAL:=TERM}"
: "${INPUT_KILL_AFTER:=30s}"
: "${INPUT_WORKING_DIRECTORY:=}"
: "${INPUT_QUIET:=false}"
quiet=0
case "${INPUT_QUIET}" in
true|TRUE|True|1) quiet=1 ;;
esac
log() { (( quiet )) || echo "$@" >&2; }
# Pick timeout binary
TIMEOUT_BIN=""
if command -v timeout >/dev/null 2>&1; then
TIMEOUT_BIN="timeout"
elif command -v gtimeout >/dev/null 2>&1; then
TIMEOUT_BIN="gtimeout"
else
echo "ERROR: Neither 'timeout' nor 'gtimeout' found. On macOS: set install-coreutils: true or run: brew install coreutils" >&2
exit 2
fi
# Move to working directory if provided
if [[ -n "${INPUT_WORKING_DIRECTORY}" ]]; then
cd "${INPUT_WORKING_DIRECTORY}"
fi
# Write the user commands to a temp script (multiline supported)
cmdfile="${RUNNER_TEMP:-/tmp}/run-bash-command-cmd.sh"
cat >"$cmdfile" <<'HEADER'
#!/usr/bin/env bash
set -Eeuo pipefail
HEADER
printf '%s\n' "${INPUT_COMMAND}" >>"$cmdfile"
chmod +x "$cmdfile"
log "run-bash-command: using ${TIMEOUT_BIN}, limit=${INPUT_TIMELIMIT}, signal=${INPUT_SIGNAL}, kill-after=${INPUT_KILL_AFTER}"
set +e
"$TIMEOUT_BIN" \
--signal="${INPUT_SIGNAL}" \
--kill-after="${INPUT_KILL_AFTER}" \
"${INPUT_TIMELIMIT}" \
bash "$cmdfile"
rc=$?
set -e
# Outputs (always emit)
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "exit_code=${rc}" >>"$GITHUB_OUTPUT"
fi
# coreutils: 124 indicates timeout
if [[ $rc -eq 124 ]]; then
log "run-bash-command: time limit reached -> treating as SUCCESS (exit 0)."
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "timed_out=true" >>"$GITHUB_OUTPUT"
fi
exit 0
fi
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "timed_out=false" >>"$GITHUB_OUTPUT"
fi
exit "$rc"