diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb0ab36e..93803152 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -240,12 +240,14 @@ jobs: timeout-minutes: 30 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 - name: Install Rust run: rustup install - name: Branch check run: cargo xtask check-branch - name: PII scanner - run: bash SKILLS/nc-devx/scripts/check-pii.sh + run: bash SKILLS/nc-devx/scripts/check-pii.sh origin/main - name: Layers run: cargo xtask layers - name: Assets diff --git a/.github/workflows/nightly-release.yml b/.github/workflows/nightly-release.yml index 87f30765..7164b4ef 100644 --- a/.github/workflows/nightly-release.yml +++ b/.github/workflows/nightly-release.yml @@ -277,6 +277,23 @@ jobs: echo "sha=$sha" >> "$GITHUB_OUTPUT" echo "### NoteCraft $TAG (\`$(git rev-parse --short "$sha")\`)" >>"$GITHUB_STEP_SUMMARY" + i18n-audit: + name: i18n audit (warning only) + # No `needs`: this runs every night, even when there is no release, + # so missing locale entries surface within a day of landing. + # `continue-on-error` keeps it a warning: the job shows orange when + # the audit fails, but the run stays green and no release job + # depends on this one. + continue-on-error: true + runs-on: ubuntu-24.04 + timeout-minutes: 30 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Install Rust + run: rustup install + - name: i18n audit + run: cargo xtask i18n-audit + test: name: Build and test the tagged commit needs: prepare diff --git a/SKILLS/nc-devx/scripts/check-pii.sh b/SKILLS/nc-devx/scripts/check-pii.sh index f9496281..ee57421e 100644 --- a/SKILLS/nc-devx/scripts/check-pii.sh +++ b/SKILLS/nc-devx/scripts/check-pii.sh @@ -1,6 +1,21 @@ #!/bin/bash # NoteCraft PII Scanner - Checks for personally identifiable information -# Run: bash SKILLS/nc-devx/scripts/check-pii.sh [--fix] +# Run: bash SKILLS/nc-devx/scripts/check-pii.sh [--fix] [base-ref] +# +# What it scans, and where the content comes from: +# base-ref given (e.g. origin/main): the files changed against that ref, +# read from their COMMITTED content at HEAD (git show HEAD:). +# A commit that adds PII is caught even if the worktree file was +# restored to clean content afterwards. The file list itself comes +# from a two-commit diff (base..HEAD), not from the worktree: a +# one-arg `git diff ` compares base to the worktree, so a +# fully restored worktree would list nothing and the scan would +# never run. +# no argument: the staged files, read from the INDEX (git show :), +# not from the worktree. +# --fix: same scan as no argument, plus fix guidance after reporting. +# The scan never reads worktree files inside a git repo: worktree content +# is not what gets committed or pushed. # PII patterns to detect # Project-specific patterns (add your own as needed): @@ -11,19 +26,30 @@ PII_PATTERNS=( ) FIX_MODE=false +BASE_REF="" if [[ "$1" == "--fix" ]]; then FIX_MODE=true +elif [[ -n "$1" ]]; then + BASE_REF="$1" fi -# Determine what to scan +# Determine what to scan, and where its content comes from. +SCAN_MODE="worktree" # head | index | worktree if git rev-parse --git-dir > /dev/null 2>&1; then - # In a git repo: scan staged files if committing, all files if pushed - if [[ -n "$1" ]] && [[ "$1" != "--fix" ]]; then - # Called by cargo xtask pre-push: scan all changes - FILES=$(git diff origin/main --name-only 2>/dev/null || git diff --cached --name-only) + if [[ -n "$BASE_REF" ]]; then + # Called by the pre-push hook and by CI: scan the changes against + # the base ref. Fail closed if the ref is missing: scanning the + # wrong set (or nothing) would silently pass PII through. + if ! git rev-parse --verify --quiet "$BASE_REF" > /dev/null 2>&1; then + echo "check-pii: base ref '$BASE_REF' not found. Run 'git fetch origin' and try again." >&2 + exit 1 + fi + FILES=$(git diff "$BASE_REF" HEAD --name-only) + SCAN_MODE="head" else - # Called from pre-commit: scan staged files + # Called from pre-commit: scan staged files, from the index. FILES=$(git diff --cached --name-only) + SCAN_MODE="index" fi else # Not in git repo: scan current directory @@ -41,20 +67,46 @@ ISSUES_FILE=$(mktemp) # Scan each file while IFS= read -r file; do [[ -z "$file" ]] && continue - [[ ! -f "$file" ]] && continue + + # Fetch the content to scan. Inside a git repo this is the committed + # (HEAD) or staged (index) content, never the worktree file. + scan_target="$file" + tmp_file="" + if [[ "$SCAN_MODE" == "head" ]]; then + tmp_file=$(mktemp) + if ! git show "HEAD:$file" > "$tmp_file" 2>/dev/null; then + rm -f "$tmp_file" + continue # deleted at HEAD: nothing to push for this path + fi + scan_target="$tmp_file" + elif [[ "$SCAN_MODE" == "index" ]]; then + tmp_file=$(mktemp) + if ! git show ":$file" > "$tmp_file" 2>/dev/null; then + rm -f "$tmp_file" + continue # removed from the index + fi + scan_target="$tmp_file" + else + [[ ! -f "$file" ]] && continue + fi # Skip binary files - if file "$file" | grep -q "binary"; then + if file "$scan_target" | grep -q "binary"; then + [[ -n "$tmp_file" ]] && rm -f "$tmp_file" continue fi - # Check each pattern + # Check each pattern. The patterns are written as extended regex + # (unescaped {n,m} intervals), so grep needs -E: plain grep reads + # them as basic regex, where "{3}" is literal text and an SSN + # would never match. for pattern in "${PII_PATTERNS[@]}"; do - if grep -q "$pattern" "$file" 2>/dev/null; then + if grep -Eq "$pattern" "$scan_target" 2>/dev/null; then echo "$file: Found '$pattern'" >> "$ISSUES_FILE" FOUND_ISSUES=$((FOUND_ISSUES + 1)) fi done + [[ -n "$tmp_file" ]] && rm -f "$tmp_file" done <<< "$FILES" if [[ $FOUND_ISSUES -gt 0 ]]; then