refactor(entrypoint): 改用 Node.js 主程式執行 action
This commit is contained in:
+3
-81
@@ -1,85 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eo pipefail
|
||||
set -euo pipefail
|
||||
|
||||
die() {
|
||||
echo "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
cleanup() {
|
||||
rm -f "${auth_file:-}" "${auth_path:-}" "${auth_lock:-}" "${codex_output:-}"
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
if [[ -z "${OAUTH:-}" ]]; then
|
||||
die "OAUTH is required: provide base64 encoded Codex auth.json."
|
||||
fi
|
||||
|
||||
if [[ -z "${MODEL:-}" ]]; then
|
||||
die "MODEL is required."
|
||||
fi
|
||||
|
||||
CODEX_HOME="${CODEX_HOME:-/root/.codex}"
|
||||
PROMPT="${PROMPT:-請自我介紹}"
|
||||
mkdir -p "$CODEX_HOME" || die "Unable to create CODEX_HOME."
|
||||
umask 077
|
||||
|
||||
auth_file="$(mktemp "$CODEX_HOME/auth.XXXXXX")"
|
||||
auth_path="$CODEX_HOME/auth.json"
|
||||
auth_lock="$(mktemp "$CODEX_HOME/auth.lock.XXXXXX")"
|
||||
|
||||
exec 9>"$auth_lock"
|
||||
flock -n 9 || die "Unable to lock Codex auth.json."
|
||||
|
||||
if ! printf '%s\n' "$OAUTH" | base64 -d > "$auth_file"; then
|
||||
die "OAUTH must be valid base64 encoded Codex auth.json."
|
||||
fi
|
||||
|
||||
if ! jq -e 'type == "object"' "$auth_file" >/dev/null; then
|
||||
die "Decoded OAUTH must be a JSON object."
|
||||
fi
|
||||
|
||||
if [[ -e "$auth_path" ]]; then
|
||||
die "Refusing to overwrite existing Codex auth.json."
|
||||
fi
|
||||
|
||||
install -m 600 "$auth_file" "$auth_path"
|
||||
rm -f "$auth_file"
|
||||
|
||||
codex_output="$(mktemp)"
|
||||
|
||||
if codex exec \
|
||||
--dangerously-bypass-approvals-and-sandbox \
|
||||
--skip-git-repo-check \
|
||||
--model "$MODEL" \
|
||||
"$PROMPT" 2>&1 | tee "$codex_output"; then
|
||||
codex_status=0
|
||||
else
|
||||
codex_status="${PIPESTATUS[0]}"
|
||||
fi
|
||||
|
||||
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
|
||||
while :; do
|
||||
output_delimiter="CODEX_OUTPUT_$(mktemp -u XXXXXXXXXXXXXXXX)"
|
||||
|
||||
if ! grep -qxF "$output_delimiter" "$codex_output"; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$codex_status" -eq 0 ]]; then
|
||||
echo "status=completed" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "status=failed" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
{
|
||||
echo "output<<$output_delimiter"
|
||||
cat "$codex_output"
|
||||
echo "$output_delimiter"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
exit "$codex_status"
|
||||
exec node "$SCRIPT_DIR/app/main.js"
|
||||
|
||||
Reference in New Issue
Block a user