From e53edf1fbb105a78345ca2f2bd6f075d93ad03c5 Mon Sep 17 00:00:00 2001 From: Danny Kim Date: Thu, 9 Jul 2026 08:24:27 +0900 Subject: [PATCH] Add initial files --- action.yml | 28 ++++++++++++++++++++++++++++ scripts/prompt.md | 20 ++++++++++++++++++++ scripts/run-codex.sh | 26 ++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 action.yml create mode 100644 scripts/prompt.md create mode 100644 scripts/run-codex.sh diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..1dfaf47 --- /dev/null +++ b/action.yml @@ -0,0 +1,28 @@ +name: Codex Bot +description: Run Codex CLI for approved Gitea issue/PR automation + +inputs: + gitea-token: + required: true + +runs: + using: composite + steps: + # This step assumes this is `node:24-bookworm` container. + - name: Install dependencies + shell: bash + run: | + apt-get update + apt-get install -y --no-install-recommends gettext-base jq + npm install -g @openai/codex + + - name: Run Codex Bot + shell: bash + run: bash "${ACTION_PATH}/scripts/run-codex.sh" + env: + ACTION_PATH: ${{ gitea.action_path }} + GITEA_API_URL: ${{ gitea.api_url }} + GITEA_REPOSITORY: ${{ gitea.repository }} + GITEA_TOKEN: ${{ inputs.gitea-token }} + ISSUE_INDEX: ${{ gitea.event.issue.number }} + COMMENT_BODY: ${{ gitea.event.comment.body }} diff --git a/scripts/prompt.md b/scripts/prompt.md new file mode 100644 index 0000000..2e96e0a --- /dev/null +++ b/scripts/prompt.md @@ -0,0 +1,20 @@ +You are Codex running inside Gitea Actions. + +First read `.codex-bot/context.md`. Treat the triggering comment body below as +the user's exact instruction. + +Write your final report to stdout. It will be posted back to Gitea as a comment +automatically after Codex exits. + +Install missing tools yourself when needed, including Rust, uv, Node, Deno, or +system packages. + +Prefer minimal, correct changes. Run relevant checks or tests if practical. +Commit your changes locally. Do not expose secrets. Finish by reporting what +changed and what tests ran. + +The triggering comment body is below. + +--- + +${COMMENT_BODY} diff --git a/scripts/run-codex.sh b/scripts/run-codex.sh new file mode 100644 index 0000000..804894a --- /dev/null +++ b/scripts/run-codex.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail + +git config --global user.name bot +git config --global user.email noreply@capsulizers.com + +FINAL_PROMPT="$(envsubst < "${ACTION_PATH}/scripts/prompt.md")" +OUTPUT_FILE="$(mktemp)" + +set +e +codex exec \ + --full-auto \ + --dangerously-bypass-approvals-and-sandbox \ + "${FINAL_PROMPT}" > "${OUTPUT_FILE}" 2>&1 +CODEX_STATUS="${?}" +set -e + +COMMENT_JSON="$(jq -n --rawfile body "${OUTPUT_FILE}" '{body: $body}')" +curl --fail-with-body --silent --show-error \ + -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + --data "${COMMENT_JSON}" \ + "${GITEA_API_URL}/repos/${GITEA_REPOSITORY}/issues/${ISSUE_INDEX}/comments" + +exit "${CODEX_STATUS}"