PR Check / Security scan (Snyk) (pull_request) Skipped
PR Check / ESLint (pull_request) Canceled after 27s
PR Check / Typecheck (pull_request) Canceled after 0s
PR Check / Secret scan (gitleaks) (pull_request) Canceled after 0s
PR Check / Dependency audit (pull_request) Canceled after 0s
PR Check / Dockerfile lint (droast) (pull_request) Canceled after 0s
PR Check / AI code review (opencode) (pull_request) Canceled after 0s
420 lines
20 KiB
YAML
420 lines
20 KiB
YAML
name: PR Check
|
|
|
|
on:
|
|
pull_request:
|
|
types: [opened, synchronize, reopened]
|
|
# manual trigger: the only way the paused snyk job below can run
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: pr-check-${{ github.event.pull_request.number }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
# The Gitea repo root IS the Nuxt app (CV_Website/CV_Site_Nuxt), so all
|
|
# app commands run from the workspace root. If you ever move the app into
|
|
# a subdirectory, change this to the subdirectory path.
|
|
APP_DIR: .
|
|
|
|
jobs:
|
|
# ---------------------------------------------------------------- lint ----
|
|
lint:
|
|
name: ESLint
|
|
runs-on: ubuntu-latest
|
|
container: node:22-bookworm
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: pnpm/action-setup@v4
|
|
with:
|
|
# match the pnpm major version used locally (v11.x) - older pnpm
|
|
# rejects our config-only pnpm-workspace.yaml ("packages field
|
|
# missing or empty")
|
|
version: 11
|
|
|
|
- name: Install dependencies
|
|
working-directory: ${{ env.APP_DIR }}
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Run ESLint
|
|
working-directory: ${{ env.APP_DIR }}
|
|
run: pnpm lint
|
|
|
|
# ------------------------------------------------------------ typecheck ---
|
|
typecheck:
|
|
name: Typecheck
|
|
runs-on: ubuntu-latest
|
|
container: node:22-bookworm
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: pnpm/action-setup@v4
|
|
with:
|
|
# match the pnpm major version used locally (v11.x) - older pnpm
|
|
# rejects our config-only pnpm-workspace.yaml ("packages field
|
|
# missing or empty")
|
|
version: 11
|
|
|
|
- name: Install dependencies
|
|
working-directory: ${{ env.APP_DIR }}
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Typecheck (vue-tsc)
|
|
working-directory: ${{ env.APP_DIR }}
|
|
run: pnpm typecheck
|
|
|
|
# -------------------------------------------------------------- secrets ---
|
|
secrets:
|
|
name: Secret scan (gitleaks)
|
|
runs-on: ubuntu-latest
|
|
# plain node image: the gitleaks container image has no node, which
|
|
# breaks node-based actions like actions/checkout
|
|
container: node:22-bookworm
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # gitleaks scans the full history
|
|
|
|
- name: Install gitleaks
|
|
run: |
|
|
echo "Runner arch: $(uname -m)"
|
|
case "$(uname -m)" in
|
|
x86_64) GITLEAKS_ARCH=x64 ;;
|
|
aarch64) GITLEAKS_ARCH=arm64 ;;
|
|
*) echo "unsupported arch: $(uname -m)" && exit 1 ;;
|
|
esac
|
|
curl -fsSL -o /tmp/gitleaks.tar.gz \
|
|
"https://github.com/gitleaks/gitleaks/releases/download/v8.28.0/gitleaks_8.28.0_linux_${GITLEAKS_ARCH}.tar.gz"
|
|
tar -xzf /tmp/gitleaks.tar.gz -C /usr/local/bin gitleaks
|
|
gitleaks version
|
|
|
|
- name: Scan for leaked secrets
|
|
run: gitleaks detect --source . --redact --verbose
|
|
# Already-committed secrets that you've accepted? Add a .gitleaksignore
|
|
# file listing their fingerprints instead of disabling the check.
|
|
|
|
# ----------------------------------------------------------- dependency ---
|
|
audit:
|
|
name: Dependency audit
|
|
runs-on: ubuntu-latest
|
|
container: node:22-bookworm
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: pnpm/action-setup@v4
|
|
with:
|
|
# match the pnpm major version used locally (v11.x) - older pnpm
|
|
# rejects our config-only pnpm-workspace.yaml ("packages field
|
|
# missing or empty")
|
|
version: 11
|
|
|
|
- name: Audit dependencies for known vulnerabilities
|
|
working-directory: ${{ env.APP_DIR }}
|
|
run: pnpm audit --prod --audit-level moderate
|
|
# 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
|
|
# 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
|
|
# 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 ----
|
|
# PAUSED: Snyk free plan only includes ~100 test credits/month, which the
|
|
# pipeline would burn through quickly (2 tests per PR push).
|
|
# Paused the actionlint-clean way: the job only runs on manual
|
|
# (workflow_dispatch) triggers, so pushes and PRs never burn credits.
|
|
# To re-enable fully, delete the if: line below. Consider also running
|
|
# this job only on PRs marked "ready for review" or on a weekly schedule
|
|
# instead of on every push.
|
|
snyk:
|
|
name: Security scan (Snyk)
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'workflow_dispatch'
|
|
# snyk/snyk:node is amd64-only ("no matching manifest for linux/arm64"),
|
|
# so install the CLI via npm in the multi-arch node image instead
|
|
container: node:22-bookworm
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Install Snyk CLI
|
|
run: npm install -g snyk@1 && snyk --version
|
|
|
|
- name: Snyk dependency scan
|
|
env:
|
|
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
|
working-directory: ${{ env.APP_DIR }}
|
|
run: |
|
|
# --all-projects: required because pnpm-workspace.yaml exists -
|
|
# without it Snyk errors with SNYK-CLI-0000
|
|
# --strict-out-of-sync: fails if the lockfile doesn't match package.json
|
|
snyk test \
|
|
--all-projects \
|
|
--severity-threshold=high \
|
|
--strict-out-of-sync=true
|
|
|
|
- name: Snyk Code scan (SAST)
|
|
env:
|
|
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
|
working-directory: ${{ env.APP_DIR }}
|
|
run: |
|
|
# static analysis of our own source code (XSS, injection, ...)
|
|
# Dockerfile/base image checks are covered by the droast job
|
|
snyk code test \
|
|
--severity-threshold=high
|
|
|
|
# -------------------------------------------------------- ai code review --
|
|
review:
|
|
name: AI code review (opencode)
|
|
runs-on: ubuntu-latest
|
|
container: node:22-bookworm
|
|
# Draft PRs don't get a (paid) review yet. The event_name check is
|
|
# load-bearing: manual (workflow_dispatch) triggers - which exist to
|
|
# run the paused snyk job - must NOT launch a paid review, which on
|
|
# a dispatch event has no PR to post to.
|
|
if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.draft }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Install opencode CLI
|
|
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: |
|
|
# lockfile changes bloat the diff (175KB here) and are pointless to
|
|
# review - pnpm audit already covers dependencies. Excluding the
|
|
# lockfile also keeps the diff small enough to hand to the model.
|
|
# The diff goes to a file IN the workspace so the agent can read it
|
|
# with its file tools (passing 190KB as a CLI argument fails with
|
|
# "Argument list too long", MAX_ARG_STRLEN is 128KiB).
|
|
git diff --merge-base "origin/${{ github.base_ref }}" \
|
|
-- . ':(exclude)pnpm-lock.yaml' > .pr-review-diff.patch
|
|
wc -c .pr-review-diff.patch
|
|
|
|
- name: Run opencode review
|
|
env:
|
|
OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
|
|
run: |
|
|
# opencode-go/deepseek-v4.1-flash#max: switched from
|
|
# deepseek-v4-pro#max on 2026-10-20 after two consecutive runs
|
|
# failed with "Upstream request failed: Endpoint is unavailable"
|
|
# (~10 min apart; the model is still listed active, the endpoint
|
|
# just does not serve). This is the default recorded in
|
|
# OKF_Nuxt/open-questions.md for exactly this case. NOTE the
|
|
# provider prefix must be "opencode-go", NOT "opencode" (Zen is a
|
|
# different, pay-per-call provider and fails with 'Insufficient
|
|
# account funds').
|
|
#
|
|
# 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.1-flash#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
|
|
the diff alone is ambiguous, but review ONLY code changed in this PR.
|
|
|
|
The full PR diff is in the file .pr-review-diff.patch in the repo
|
|
root. Read it first with your file tools.
|
|
|
|
## Project context
|
|
- Stack: Nuxt 4 (Vue 3, TypeScript) SSR web app in the repo root.
|
|
Backend/API services are being added in Golang.
|
|
- Deployment target: a personal production CV website.
|
|
- Already covered by other CI jobs, do NOT repeat their findings:
|
|
ESLint (style), vue-tsc (types), gitleaks (secrets in git history),
|
|
pnpm audit (dependency CVEs), droast (Dockerfile lint).
|
|
- Your job is everything those tools CANNOT see: logic, security,
|
|
architecture, correctness.
|
|
|
|
## Nuxt / Vue / TypeScript focus
|
|
- SSR pitfalls: window/document/localStorage access without
|
|
<ClientOnly> or process.client guards; hydration mismatch risks
|
|
(Date.now(), Math.random(), locale formatting in render path).
|
|
- useAsyncData/useFetch: missing or colliding keys, duplicate
|
|
requests between server and client, wrong caching/refresh setup.
|
|
- Reactivity bugs: destructuring reactive objects losing reactivity,
|
|
missing await on async setup, watch on getters vs refs.
|
|
- Security: v-html with unsanitized data, user input flowing into
|
|
meta/URLs, open redirects, missing validation in /server/api and
|
|
Nitro route handlers, auth checks on both page and API level.
|
|
- Config hygiene: server-only runtime config (no NUXT_PUBLIC_
|
|
prefix) leaking secrets into the client bundle.
|
|
|
|
## Golang focus (when Go code is in the diff)
|
|
- Errors: unchecked errors, errors discarded, wrapping with %w,
|
|
sentinel vs typed errors, panic in library code.
|
|
- Concurrency: goroutine leaks (missing context cancellation),
|
|
data races (shared state without mutex/channel), WaitGroup
|
|
misuse, defer in loops.
|
|
- Resources: unclosed response bodies/files/rows, missing
|
|
timeouts on http.Client, unbounded buffering.
|
|
- Correctness: slice aliasing surprises, copy vs reference
|
|
semantics, nil map writes, integer truncation.
|
|
|
|
## Cross-cutting
|
|
- API contract mismatches between Nuxt frontend and Go backends
|
|
(field names, nullability, status codes, date formats).
|
|
- Missing authorization checks on new endpoints or pages.
|
|
- Secrets/credentials ending up in logs or client-visible output.
|
|
- Performance on the critical render path (heavy components,
|
|
unoptimized images, blocking Nitro middleware).
|
|
|
|
## Output format (strict)
|
|
Review the diff in .pr-review-diff.patch. For every finding:
|
|
[BLOCKER] file:line - what and why + concrete fix suggestion
|
|
[WARN] file:line - what and why + concrete fix suggestion
|
|
[NIT] file:line - optional improvement
|
|
BLOCKER = must fix before merge (security, data loss, broken
|
|
behavior). WARN = should fix soon. NIT = optional.
|
|
If a finding cannot be localized to a file, prefix [BLOCKER-GENERAL].
|
|
No compliments, no summaries of what the diff does, no style nits.
|
|
Keep it under 400 words unless there are more than 10 findings.
|
|
If the diff contains no reviewable code (docs/config only), say so
|
|
in one line.
|
|
|
|
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=$?
|
|
# always show the output - never swallow the error text
|
|
cat /tmp/review.md
|
|
# 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
|
|
continue-on-error: true # token missing/expired must not fail the build
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.PR_GITEA_TOKEN }}
|
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
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}" \
|
|
-X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"body\": ${BODY}}" \
|
|
"${GITHUB_API_URL}/repos/${REPO}/issues/${PR_NUMBER}/comments")
|
|
echo "POST status: ${HTTP_CODE}"
|
|
cat /tmp/comment-response.json
|
|
case "$HTTP_CODE" in
|
|
200|201) echo "Review comment posted." ;;
|
|
*) echo "::error::Failed to post review comment (HTTP ${HTTP_CODE}) - check PR_GITEA_TOKEN scope and expiry" ;;
|
|
esac
|