From a8fd459117f33fcb6f41ca29d3cb8fba766cef01 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Wed, 24 Jun 2026 10:25:41 +0000 Subject: [PATCH] =?UTF-8?q?feat(Codex=20CLI):=20=E6=96=B0=E5=A2=9E=20Codex?= =?UTF-8?q?=20CLI=20Docker=20Action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 22 +++++++++++++++++++--- action.yaml | 26 +++++++++++++++----------- entrypoint.sh | 23 ++++++++++++++++++----- 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index af3dacb..06c0dc3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,26 @@ FROM alpine:latest # 安裝必要的工具 -RUN apk add --no-cache --no-check-certificate bash - +RUN apk add --no-cache --no-check-certificate bash ca-certificates curl git + +# 設定安裝用的環境變數 +ENV CODEX_NON_INTERACTIVE=1 +ENV CODEX_INSTALL_DIR=/usr/local/bin +ENV CODEX_HOME=/root/.codex + +# 安裝 Codex CLI 工具 +RUN curl -fsSL https://chatgpt.com/codex/install.sh | sh + +# 安裝 doc 技能 +RUN codex plugin marketplace add https://gitea.jsc.idv.tw/plugins/doc.git \ + && codex plugin add jsc@doc + +# 安裝 code-review 技能 +RUN codex plugin marketplace add https://gitea.jsc.idv.tw/plugins/code-review.git \ + && codex plugin add jsc@code-review + COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/entrypoint.sh"] diff --git a/action.yaml b/action.yaml index f8849d0..11549ba 100644 --- a/action.yaml +++ b/action.yaml @@ -1,20 +1,24 @@ -name: 'Docker Action Template' -description: 'Docker Action 範本' +name: 'Codex CLI' +description: 'Codex CLI Action' author: 'Jeffery' inputs: - runner_token: - description: 'Gitea Runner Token' + oauth: + description: 'Base64 encoded Codex auth.json' required: true - text: - description: '輸入的文字' - default: "Hello, World!" + model: + description: 'Codex model name' + required: true + prompt: + description: 'Prompt for codex exec' + required: false + default: '請自我介紹' outputs: text: - description: '輸出的文字' + description: 'Execution result status' runs: using: 'docker' image: 'Dockerfile' env: - GITEA_SERVER_URL: ${{ gitea.server_url }} - GITEA_REPOSITORY: ${{ gitea.repository }} - RUNNER_TOKEN: ${{ inputs.runner_token || secrets.GITEA_TOKEN || secrets.RUNNER_TOKEN }} \ No newline at end of file + OAUTH: ${{ inputs.oauth }} + MODEL: ${{ inputs.model }} + PROMPT: ${{ inputs.prompt }} diff --git a/entrypoint.sh b/entrypoint.sh index 378b552..cc5e074 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,11 +1,24 @@ #!/bin/bash -echo "Gitea Server Url: $GITEA_SERVER_URL" +set -euo pipefail -echo "Gitea Repository: $GITEA_REPOSITORY" +if [[ -z "${OAUTH:-}" ]]; then + echo "OAUTH is required: provide base64 encoded Codex auth.json." >&2 + exit 1 +fi -echo "Gitea Runner Token: $RUNNER_TOKEN" +if [[ -z "${MODEL:-}" ]]; then + echo "MODEL is required." >&2 + exit 1 +fi -echo "Input Text: $INPUT_TEXT" +CODEX_HOME="${CODEX_HOME:-/root/.codex}" +mkdir -p "$CODEX_HOME" +printf '%s' "$OAUTH" | base64 -d > "$CODEX_HOME/auth.json" +chmod 600 "$CODEX_HOME/auth.json" -echo "text=$INPUT_TEXT" >> "$GITHUB_OUTPUT" \ No newline at end of file +codex exec --dangerously-bypass-approvals-and-sandbox --model "$MODEL" "$PROMPT" + +if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + echo "text=completed" >> "$GITHUB_OUTPUT" +fi