chore(Docker action): 整理 Docker action 執行設定

This commit is contained in:
2026-06-29 10:49:22 +00:00
parent 0b59ca6023
commit 45b6abacc8
4 changed files with 29 additions and 96 deletions
+9 -30
View File
@@ -26,7 +26,7 @@ jobs:
id: release-tag-version
uses: https://gitea.jsc.idv.tw/composite-actions/release-tag-version@${{ vars.ACTION_RELEASE_TAG_VERSION }}
with:
is_beta: 'true'
is_beta: true
# job 識別碼:ai-code-review
ai-code-review:
# job 顯示名稱
@@ -34,43 +34,22 @@ jobs:
needs: release-tag-version
# 指定執行環境的 runner 標籤:ubuntu
runs-on: ubuntu
# 此 job 所需的權限設定
permissions:
# 對 repository 內容的寫入權限(讀寫程式碼/檔案)
contents: write
# 對 pull request 的寫入權限(讓 AI 可在 PR 上留言/審查)
pull-requests: write
# 對 issues 的寫入權限(建立/更新 issue 留言所需)
issues: write
# job 的執行步驟
steps:
- name: 取得程式碼
uses: actions/checkout@${{ vars.ACTION_CHECKOUT_VERSION }}
- name: 安裝 AI 工具
uses: https://gitea.jsc.idv.tw/composite-actions/codex@${{ vars.ACTION_CODEX_VERSION }}
with:
oauth: ${{ secrets.CODEX_OAUTH }}
- name: 檢查 AI 助理 CLI
shell: bash
run: |
set -e
tools="$(node --input-type=module -e "import { getLLMCLICommands } from './app/config.js'; console.log(getLLMCLICommands().join(' '));")"
found=""
for tool in $tools; do
if command -v "$tool" >/dev/null 2>&1; then
found="${found} ${tool}"
"$tool" --version || true
fi
done
if [ -z "$found" ]; then
echo "找不到可用的 AI 助理 CLI(需要 ${tools} 其中之一)" >&2
exit 1
fi
echo "可用 AI 助理 CLI:${found}"
- name: AI 程式碼審查
# 使用外部 composite action 執行審查邏輯。
# 版本由 release-tag-version 計算,便於在 PR 中測試目前 action 版本。
uses: https://gitea.jsc.idv.tw/docker-actions/ai-code-review@v${{ needs.release-tag-version.outputs.version }}
# 此 job 所需的權限設定
permissions:
# 對 repository 內容的寫入權限(讀寫程式碼/檔案)
contents: write
# 對 pull request 的寫入權限(讓 AI 可在 PR 上留言/審查)
pull-requests: write
# 對 issues 的寫入權限(建立/更新 issue 留言所需)
issues: write
# 傳遞給 composite action 的輸入參數
with:
# 留言用 token:取自 secret COMMENT_TOKEN,供 action 在 PR 上發布審查留言
+6 -26
View File
@@ -1,34 +1,14 @@
# =============================================================================
# 用途:建置「AI 程式碼審查」Docker action 映像檔。
# 以 Alpine Linux 為基底,安裝 bash / git / Node.js / npm 等執行環境,
# 將 app/ 程式碼與相依套件打包進映像,並透過 entrypoint.sh 作為容器進入點,
# 供 CIGitea Actions)以 Docker action 形式執行 AI code review 流程。
# 更新日期:2026/06/26 11:34:46
# =============================================================================
FROM codex:latest
# 指定支援中的 Alpine Linux 固定版本;Alpine 體積小,可縮小最終映像大小並加快拉取速度。
# 釘選明確版本可避免 latest tag 隨時間變動,提升建置可重現性。
FROM alpine:3.24.1
RUN apt update \
&& apt install -y --no-install-recommends git
&& apt clean \
&& rm -rf /var/lib/apt/lists/*s
# 安裝必要的工具
# 安裝執行 code review 所需的工具:bash(執行 entrypoint 腳本)、git(前置遠端驗證/取得 diff)、
# nodejs 與 npm(執行 app 內的 Node.js 程式)。
# --no-cache:不保留 apk 套件索引快取,避免殘留在映像層中以減少映像大小。
RUN apk add --no-cache bash git nodejs npm
# 將專案的 app/ 目錄複製到映像內的 /app;包含 Node.js 程式碼與 package.json 等相依宣告。
COPY ./app /app
# 進入 /app 安裝 npm 相依套件,使 Node.js 程式可在容器內正常執行。
# 副作用:會在 /app/node_modules 產生套件檔案,並依 package-lock.json(若存在)解析版本。
RUN cd /app && npm install
# 將容器進入點腳本 entrypoint.sh 複製到映像根目錄 /entrypoint.sh
COPY entrypoint.sh /entrypoint.sh
# 賦予 entrypoint.sh 可執行權限,確保容器啟動時能直接執行該腳本。
COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# 設定容器進入點為 /entrypoint.shexec 形式,不經過 shell 解析);
# 容器啟動時即執行此腳本,作為 Docker action 的實際入口。
ENTRYPOINT ["/entrypoint.sh"]
+14 -25
View File
@@ -4,34 +4,23 @@ author: 'Jeffery'
inputs:
token:
description: ''
required: true
required: false
comment_token:
description: ''
required: false
model:
description: ''
description: '要使用的 AI 助理 CLI 模型識別字串'
required: true
runs:
using: 'composite'
steps:
- name: 安裝 Node.js 相依套件
shell: bash
run: |
cd "${GITHUB_ACTION_PATH:-${GITEA_ACTION_PATH:-.}}/app"
npm ci
- name: 執行 AI 程式碼審查
shell: bash
env:
GITEA_SERVER_URL: ${{ gitea.server_url }}
GITEA_REPOSITORY: ${{ gitea.repository }}
GITEA_TOKEN: ${{ inputs.token || gitea.token }}
GITEA_COMMENT_TOKEN: ${{ inputs.comment_token || inputs.token || gitea.token }}
PR_NUMBER: ${{ gitea.event.pull_request.number }}
PR_HEAD_SHA: ${{ gitea.event.pull_request.head.sha }}
PR_HEAD_BRANCH: ${{ gitea.event.pull_request.head.ref }}
PR_BASE_BRANCH: ${{ gitea.event.pull_request.base.ref }}
MODEL: ${{ inputs.model }}
run: |
echo "🚀 AI Code Review Action 啟動"
cd "${GITHUB_ACTION_PATH:-${GITEA_ACTION_PATH:-.}}/app"
node main.js
using: 'docker'
image: 'Dockerfile'
env:
GITEA_SERVER_URL: ${{ gitea.server_url }}
GITEA_REPOSITORY: ${{ gitea.repository }}
GITEA_TOKEN: ${{ inputs.token || gitea.token }}
GITEA_COMMENT_TOKEN: ${{ inputs.comment_token || inputs.token || gitea.token }}
PR_NUMBER: ${{ gitea.event.pull_request.number }}
PR_HEAD_SHA: ${{ gitea.event.pull_request.head.sha }}
PR_HEAD_BRANCH: ${{ gitea.event.pull_request.head.ref }}
PR_BASE_BRANCH: ${{ gitea.event.pull_request.base.ref }}
MODEL: ${{ inputs.model }}
-15
View File
@@ -1,15 +0,0 @@
{
"name": "ai-code-review",
"version": "1.0.0",
"description": "AI code review Gitea action",
"private": true,
"scripts": {
"test": "npm --prefix app test"
},
"repository": {
"type": "git",
"url": "https://gitea.jsc.idv.tw/docker-actions/ai-code-review.git"
},
"author": "Jeffery",
"license": "ISC"
}