Skip to content

Merge pull request #12 from i-mrDed/feat/enable-merge-gate #72

Merge pull request #12 from i-mrDed/feat/enable-merge-gate

Merge pull request #12 from i-mrDed/feat/enable-merge-gate #72

Workflow file for this run

# Secret scan + MongoModel data check
# ทำงานทุก push + PR — จับ secret ที่หลุดมาก่อน merge
# gitleaks สแกนทุกไฟล์ใน git history (แม้ลบทีหลังก็โดนจับ)
name: Secret Scan
on:
push:
pull_request:
workflow_dispatch:
permissions:
contents: read
pull-requests: write # gitleaks แสดงผลบน PR (เฉพาะที่จำเป็น)
jobs:
gitleaks:
name: Gitleaks secret scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # ต้อง history เต็ม — gitleaks สแกนทุก commit ที่ผ่านมา
# gitleaks-action@v2 requires a paid license for organization repos
# (missing GITLEAKS_LICENSE fails every run). The gitleaks CLI itself is
# free (MIT) — download the binary and scan directly instead.
- name: Install gitleaks CLI
run: |
curl -sL https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_linux_x64.tar.gz | tar xz
./gitleaks version
- name: Run Gitleaks
run: |
./gitleaks git . --redact --exit-code 1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
devpath-leak-check:
name: Dev-machine path leak scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Scan for dev-machine paths (username / local checkout / worktree)
run: |
# Catches leaks that gitleaks doesn't (dev paths, not secrets):
# - C:/Users/<name>/ or C:\Users\<name>\ (a real username)
# - .opencode/ .opencode\ .worktrees/ .worktrees\ (local checkout)
# git grep so it runs on the clean CI checkout (tracked files only).
# runneradmin = GitHub's own CI runner user (expected, allowed).
if git grep -nE 'C:[/\\]Users[/\\][A-Za-z0-9_]{2,}|\.opencode[/\\]|\.worktrees[/\\]' -- \
. ':!docs/screenshots/*' ':!.github/workflows/secret-scan.yml' \
':!docs/GO_PUBLIC_CHECKLIST.md' \
| grep -v 'runneradmin'; then
echo "::error::Dev-machine path leak — replace with <user>/~/placeholders (see docs/GO_PUBLIC_CHECKLIST.md)"
exit 1
fi
echo "dev-path scan OK"
mongomodel-data-check:
name: MongoModel data sanity
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate model JSON parses
# hashFiles is only evaluated at step level (after checkout) — job-level
# `if: hashFiles(...)` is rejected by GitHub's parser (workflow fails
# before any job starts). projects.json is tracked, so the file always
# exists in CI; this guard keeps the job a no-op if it ever disappears.
if: hashFiles('mongomodel-data/projects.json') != ''
run: |
node -e "const fs=require('fs');const j=JSON.parse(fs.readFileSync('mongomodel-data/projects.json','utf8'));if(!j.projects)throw new Error('no projects key');console.log('projects.json OK:',Object.keys(j.projects).length,'project(s)')"
- name: Scan mongomodel-data for obvious secrets
if: hashFiles('mongomodel-data/projects.json') != ''
run: |
if grep -rEil 'mongodb(\+srv)?://[^" ]*(:[^"@ ]+@)|BEGIN [A-Z ]*PRIVATE KEY|(ghp|gho|ghu)_[A-Za-z0-9]{36}|github_pat_|sk-(proj-|ant-)[A-Za-z0-9]{10,}|AKIA[0-9A-Z]{16}|xox[baprs]-[A-Za-z0-9-]{10,}|eyJ[A-Za-z0-9_-]{10,}\.' mongomodel-data/; then
echo "::error::Possible secret found in mongomodel-data — do not commit secrets in shared brain"
exit 1
fi
echo "mongomodel-data scan OK"