fix(ci): use opencode-go plan model for AI review #5

Merged
Noel merged 14 commits from fix/ai_pr_review into main 2026-10-18 16:24:58 +00:00
+114 -18
View File
@@ -109,24 +109,69 @@ jobs:
- name: Audit dependencies for known vulnerabilities
working-directory: ${{ env.APP_DIR }}
run: pnpm audit --prod --audit-level moderate
continue-on-error: true # advisory: does not block the PR by default
# blocks the PR on vulnerabilities - re-add `continue-on-error: true`
# here only if a CVE fix is genuinely blocked upstream, never to
# make a red pipeline green
# ------------------------------------------------------- dockerfile lint --
dockerfile-lint:
name: Dockerfile lint (droast)
runs-on: ubuntu-latest
container:
image: immanuwell/droast:1.7.0
# skips until the repo contains a Dockerfile
if: ${{ hashFiles('**/Dockerfile', '**/Dockerfile.*', '**/Containerfile') != '' }}
# droast's own container image ships no node (actions/checkout would
# fail with exit 127 - same as the gitleaks image), so run the droast
# binary in the multi-arch node image instead
container: node:22-bookworm
steps:
- uses: actions/checkout@v4
- name: Install droast
run: |
case "$(uname -m)" in
x86_64) DROAST_ASSET=droast-linux-x86_64; DROAST_SHA=cadb963a040ba2e68641af764f794e5d4fb3371bb9b92255fa5027060b08ea6e ;;
aarch64) DROAST_ASSET=droast-linux-arm64; DROAST_SHA=0800e80d11f668615fc87750f58809b56bedca83ec6d8a539daa56f42da64bc3 ;;
*) echo "unsupported arch: $(uname -m)" && exit 1 ;;
esac
curl -fsSL -o /usr/local/bin/droast \
"https://github.com/immanuwell/dockerfile-roast/releases/download/1.7.0/${DROAST_ASSET}"
# verify against the pinned hash checked into this workflow
# (fetching the checksum from the same release as the binary
# would be trust-on-first-use and prove nothing)
echo "${DROAST_SHA} /usr/local/bin/droast" | sha256sum -c -
chmod +x /usr/local/bin/droast
droast --version
- name: Discover Dockerfiles
id: discover
# shell check instead of hashFiles: the act runner's hashFiles
# evaluation returned empty and silently skipped the job even when
# Dockerfiles existed
run: |
# Discovery: -print -quit instead of `| head -n 1` - head can
# SIGPIPE find (exit 141) when multiple Dockerfiles match
found="$(find . \
-path ./.git -prune -o -path ./node_modules -prune -o \
-type f \( -iname 'Dockerfile*' -o -iname '*dockerfile' -o -iname 'Containerfile*' \) \
-print -quit)"
if [ -n "$found" ]; then
echo "found=true" >> "$GITHUB_OUTPUT"
echo "Dockerfile found: $found"
else
echo "found=false" >> "$GITHUB_OUTPUT"
echo "No Dockerfile in repo - nothing to lint"
fi
- name: Lint Dockerfile(s)
if: ${{ steps.discover.outputs.found == 'true' }}
run: |
# --no-roast = technical output for CI; --min-severity warning so
# info-level findings don't block the PR
droast --no-roast --min-severity warning .
# lint exactly the tree the discovery step sees: prune node_modules
# and .git so vendored Dockerfiles in dependencies cannot produce
# findings on third-party code
find . \
-path ./.git -prune -o -path ./node_modules -prune -o \
-type f \( -iname 'Dockerfile*' -o -iname '*dockerfile' -o -iname 'Containerfile*' \) \
-print0 | xargs -0 -r droast --no-roast --min-severity warning
# ------------------------------------------------------- snyk security ----
# DISABLED: Snyk free plan only includes ~100 test credits/month, which the
@@ -183,10 +228,12 @@ jobs:
fetch-depth: 0
- name: Install opencode CLI
run: curl -fsSL https://opencode.ai/install | bash
env:
# pin the version for reproducible CI, e.g. v1.0.0
OPENCODE_VERSION: latest
run: curl -fsSL https://opencode.ai/v2/install | bash -s -- -v 2.0.32
# v2 installer is required: the classic /install URL ships only
# OpenCode 1.x (resolved to v1.19.3 on arm64), which cannot resolve
# model variants like "#max" and failed with ProviderModelNotFoundError.
# Version pinned (-v 2.0.32) so a breaking v2 release cannot fail
# the job mid-PR; bump deliberately, not automatically.
- name: Get PR diff
run: |
@@ -209,10 +256,39 @@ jobs:
# (variants: high, max). NOTE the provider prefix must be
# "opencode-go", NOT "opencode" (Zen is a different, pay-per-call
# provider and fails with 'Insufficient account funds').
# Output is redirected (not piped through tee): if opencode fails,
# the job must fail here so the error log is never posted as a
# "review" comment.
#
# Auth is env-only: the CLI picks up OPENCODE_API_KEY from the
# environment (verified headless). Deliberately NO opencode.json:
# a config file in the checkout would hold the API key in
# plaintext, readable by the agent - a malicious PR diff could
# prompt-inject the agent into quoting the key in the review
# comment (publicly visible). Env vars are invisible to file reads.
# Permissions live in a global config OUTSIDE the checkout (no
# secrets in it, so nothing can leak). OpenCode v2 schema: the
# field is "permissions" (plural) - an ordered array of
# {action, resource, effect}; "bash" was renamed "shell" in v2.
# The singular v1 "permission" object is ignored by the v2 CLI
# (verified empirically: shell commands executed despite deny).
# Denying shell/edit/webfetch/websearch/external_directory means
# no headless permission prompts can hang or kill the run, and
# the reviewer physically cannot modify the repo or browse
# attacker-controlled URLs.
mkdir -p "$HOME/.config/opencode"
printf '{
"$schema": "https://opencode.ai/config.json",
"permissions": [
{ "action": "edit", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "external_directory", "resource": "*", "effect": "deny" }
]
}' > "$HOME/.config/opencode/opencode.json"
# --print-logs: surface auth/provider errors in the CI log instead
# of failing with an opaque exit code
EXIT_CODE=0
opencode run \
--print-logs \
--model opencode-go/deepseek-v4-pro#max \
"You are a principal engineer performing a rigorous code review on a
pull request. You have tool access: read repo files for context when
@@ -280,12 +356,26 @@ jobs:
End your response with a final verdict line, exactly one of:
VERDICT: APPROVE (no BLOCKER findings)
VERDICT: REQUEST_CHANGES (at least one BLOCKER)" \
> /tmp/review.md 2>&1
EXIT_CODE=$?
> /tmp/review.md 2>&1 || EXIT_CODE=$?
# always show the output - never swallow the error text
cat /tmp/review.md
if [ $EXIT_CODE -ne 0 ]; then
echo "::error::opencode review failed (exit ${EXIT_CODE}) - NOT posting this output as a review comment"
exit $EXIT_CODE
# The posting gate is the OUTPUT CONTRACT, not the exit code:
# a completed review always ends with a VERDICT line - error
# dumps never do. opencode can exit 1 on benign tool denials
# even after a full review, so a present verdict means post;
# anything else means the review did not complete.
# Anchored to the tail: the prompt itself contains VERDICT
# lines, so scanning the whole file could pass on echoed
# prompt text or injected quotes - only the last lines count.
if tail -n 5 /tmp/review.md | grep -qE '^VERDICT: (APPROVE|REQUEST_CHANGES)'; then
[ "$EXIT_CODE" -ne 0 ] && echo "::warning::opencode exited ${EXIT_CODE} but produced a valid verdict - posting review"
echo "Review completed with verdict."
else
# fail closed: no verdict = no review. exit 1 unconditionally -
# falling back to EXIT_CODE would exit 0 when opencode succeeded
# but produced no review, and the job would go green.
echo "::error::opencode produced no valid review (exit ${EXIT_CODE:-1}) - NOT posting this output as a review comment"
exit 1
fi
- name: Post review as PR comment
@@ -296,6 +386,12 @@ jobs:
REPO: ${{ github.repository }}
# Gitea sets GITHUB_API_URL, e.g. https://gitea.example.com/api/v1
run: |
# re-verify the output contract here: never post anything that is
# not a completed review, regardless of how the previous step ended
if ! tail -n 5 /tmp/review.md | grep -qE '^VERDICT: (APPROVE|REQUEST_CHANGES)'; then
echo "::error::no verdict in review output - nothing to post"
exit 1
fi
# jq is not in the node image - use node for JSON encoding
BODY=$(node -e 'process.stdout.write(JSON.stringify(require("fs").readFileSync("/tmp/review.md","utf8")))')
HTTP_CODE=$(curl -s -o /tmp/comment-response.json -w "%{http_code}" \