Files
codex/action.yml
T
Jeffery a309afdf58
CI / Release Tag Version (pull_request) Successful in 3s
CI / Codex (pull_request) Successful in 20s
fix(codex): oauth 改回經 inputs.oauth 傳入
composite action 讀不到 secrets context,改回由呼叫端以 with: oauth:
${{ secrets.CODEX_OAUTH }} 經 inputs.oauth 傳入;action 從 inputs.oauth
讀取並保留空值把關,移除 job 層 CODEX_OAUTH env。
2026-06-29 13:42:36 +08:00

70 lines
1.8 KiB
YAML

name: 'Codex CLI'
description: 'Codex CLI 工具'
author: 'Jeffery'
inputs:
prompt:
description: '傳給 Codex CLI 的提示詞'
required: false
default: "請自我介紹"
oauth:
description: 'base64 編碼的 Codex OAuth token 檔案內容'
required: true
outputs:
text:
description: '輸出的文字'
value: ${{ steps.codex.outputs.text }}
runs:
using: 'composite'
steps:
- name: 安裝工具
env:
OAUTH: ${{ inputs.oauth }}
run: |
if [ -z "$OAUTH" ]; then
echo 'oauth input (secrets.CODEX_OAUTH) is required and must not be empty.' >&2
exit 1
fi
npm install -g @openai/codex
oauth_file="$HOME/.codex/auth.json"
install -d -m 700 "$(dirname "$oauth_file")"
printf '%s' "$OAUTH" | base64 -d > "$oauth_file"
chmod 600 "$oauth_file"
shell: bash
- name: 執行工具
id: codex
env:
MODEL: ${{ vars.CODEX_MODEL }}
PROMPT: ${{ inputs.prompt }}
run: |
if [ -z "$MODEL" ]; then
echo 'CODEX_MODEL repository variable is required.' >&2
exit 1
fi
text="$(codex exec --skip-git-repo-check -s danger-full-access --model "$MODEL" "$PROMPT")"
printf '%s\n' "$text"
{
echo 'text<<CODEX_OUTPUT'
printf '%s\n' "$text"
echo 'CODEX_OUTPUT'
} >> "$GITHUB_OUTPUT"
shell: bash
- name: 驗證登入帳號
env:
EXPECTED_EMAIL: ${{ vars.CODEX_EMAIL }}
run: |
if [ -z "$EXPECTED_EMAIL" ]; then
echo 'CODEX_EMAIL repository variable is required.' >&2
exit 1
fi
email="$(python3 "$GITHUB_ACTION_PATH/app/codex_account.py")"
if [ "$email" != "$EXPECTED_EMAIL" ]; then
echo '登入帳號與 CODEX_EMAIL 不符' >&2
exit 1
fi
echo '登入帳號驗證通過'
shell: bash