From a57c01e271b880cb0722dbea01aaa7c7bd6b673a Mon Sep 17 00:00:00 2001 From: Jeffery Date: Wed, 24 Jun 2026 10:44:23 +0000 Subject: [PATCH] =?UTF-8?q?fix(entrypoint):=20=E8=B7=B3=E9=81=8E=20Codex?= =?UTF-8?q?=20repo=20=E4=BF=A1=E4=BB=BB=E6=AA=A2=E6=9F=A5=E4=B8=A6?= =?UTF-8?q?=E6=B8=85=E7=90=86=20auth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entrypoint.sh | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1f6cba5..1580887 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,49 +2,63 @@ set -eo pipefail -if [[ -z "${OAUTH:-}" ]]; then - echo "OAUTH is required: provide base64 encoded Codex auth.json." >&2 +die() { + echo "$1" >&2 exit 1 +} + +cleanup() { + rm -f "${auth_file:-}" "${auth_path:-}" "${codex_output:-}" +} + +trap cleanup EXIT + +if [[ -z "${OAUTH:-}" ]]; then + die "OAUTH is required: provide base64 encoded Codex auth.json." fi if [[ -z "${MODEL:-}" ]]; then - echo "MODEL is required." >&2 - exit 1 + die "MODEL is required." fi CODEX_HOME="${CODEX_HOME:-/root/.codex}" PROMPT="${PROMPT:-請自我介紹}" -mkdir -p "$CODEX_HOME" +mkdir -p "$CODEX_HOME" || die "Unable to create CODEX_HOME." auth_file="$(mktemp "$CODEX_HOME/auth.XXXXXX")" -trap 'rm -f "$auth_file"' EXIT +auth_path="$CODEX_HOME/auth.json" -if ! printf '%s' "$OAUTH" | base64 -d > "$auth_file"; then - echo "OAUTH must be valid base64 encoded Codex auth.json." >&2 - exit 1 +if [[ -e "$auth_path" ]]; then + die "Refusing to overwrite existing Codex auth.json." +fi + +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 - echo "Decoded OAUTH must be a JSON object." >&2 - exit 1 + die "Decoded OAUTH must be a JSON object." fi -mv "$auth_file" "$CODEX_HOME/auth.json" -chmod 600 "$CODEX_HOME/auth.json" -trap - EXIT +install -m 600 "$auth_file" "$auth_path" +rm -f "$auth_file" codex_output="$(mktemp)" -trap 'rm -f "$codex_output"' EXIT set +e codex exec \ + --skip-git-repo-check \ --model "$MODEL" \ "$PROMPT" 2>&1 | tee "$codex_output" codex_status="${PIPESTATUS[0]}" set -e if [[ -n "${GITHUB_OUTPUT:-}" ]]; then - output_delimiter="CODEX_OUTPUT_$(date +%s)_$$" + if [[ -r /proc/sys/kernel/random/uuid ]]; then + output_delimiter="CODEX_OUTPUT_$(cat /proc/sys/kernel/random/uuid)" + else + output_delimiter="CODEX_OUTPUT_$(mktemp -u XXXXXXXXXXXXXXXX)" + fi if [[ "$codex_status" -eq 0 ]]; then echo "status=completed" >> "$GITHUB_OUTPUT"