/** Bash helpers shared by every generated job script: step outputs/env files, hashFiles() and the R2-backed cache. */
const SOURCE = String.raw`__gitfor_re_heredoc='^([A-Za-z_][A-Za-z0-9_-]*)<<(.+)$'
__gitfor_re_kv='^([A-Za-z_][A-Za-z0-9_-]*)=(.*)$'
__gitfor_read_kv() {
[ -s "$1" ] || return 0
local __line __key __value __delim __more
while IFS= read -r __line || [ -n "$__line" ]; do
if [[ $__line =~ $__gitfor_re_heredoc ]]; then
__key="#{BASH_REMATCH[1]}"; __delim="#{BASH_REMATCH[2]}"; __value=""; __more=0
while IFS= read -r __line || [ -n "$__line" ]; do
[ "$__line" = "$__delim" ] && break
if [ $__more = 1 ]; then __value="$__value"$'\n'"$__line"; else __value="$__line"; __more=1; fi
done
elif [[ $__line =~ $__gitfor_re_kv ]]; then
__key="#{BASH_REMATCH[1]}"; __value="#{BASH_REMATCH[2]}"
else
continue
fi
"$2" "$__key" "$__value" "#{3:-}"
done < "$1"
}
__gitfor_set_output() { [ -n "$3" ] || return 0; export "GITFOR_STEPOUT_#{3}__#{1//-/_}=$2"; }
__gitfor_set_env() {
case "$1" in
*-*|__gitfor*|BASH_ENV|ENV|BASH_FUNC_*|SHELLOPTS|BASHOPTS|PS4|IFS|LD_*|DYLD_*|NODE_OPTIONS|PYTHONSTARTUP|PYTHONPATH|PYTHONHOME|PERL5OPT|PERL5LIB|RUBYOPT|GIT_*|GITFOR_*|GITHUB_*|ACTIONS_*|RUNNER_*|CI|HOME|PATH|SHELL|PROMPT_COMMAND|CDPATH|GLOBIGNORE|BASHPID|UID|EUID)
echo "Ignoring reserved environment variable $1 written to GITHUB_ENV"; return 0 ;;
esac
export "$1=$2"
}
__gitfor_reset_files() { : > "$__gitfor_tmp/output"; : > "$__gitfor_tmp/env"; : > "$__gitfor_tmp/path"; }
__gitfor_after_step() {
local __l __o=success __c=success
__gitfor_read_kv "$__gitfor_tmp/env" __gitfor_set_env
if [ -s "$__gitfor_tmp/path" ]; then
while IFS= read -r __l || [ -n "$__l" ]; do if [ -n "$__l" ]; then PATH="$__l:$PATH"; fi; done < "$__gitfor_tmp/path"
export PATH
fi
if [ -n "$1" ]; then
__gitfor_read_kv "$__gitfor_tmp/output" __gitfor_set_output "$1"
if [ "$2" -ne 0 ]; then __o=failure; [ "$3" = 1 ] || __c=failure; fi