Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/actions/ci-static-checks/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ runs:
run: |
npx prek run --all-files --stage pre-commit \
--skip source-shape-test-budget \
--skip test-file-size-budget \
--skip test-skills-yaml

- name: Run source-shape budget
shell: bash
run: npm run source-shape:check

- name: Run test file size budget
shell: bash
run: npm run test-size:check

- name: Verify platform matrix is in sync
shell: bash
run: python3 scripts/generate-platform-docs.py --check
3 changes: 0 additions & 3 deletions .github/workflows/base-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ on:
# takes effect immediately after merge instead of waiting for another tag.
- ".github/workflows/base-image.yaml"
- ".github/workflows/managed-images.yaml"

- "test/e2e/live/managed-image-activation-e2e.test.ts"
- "test/e2e/live/managed-image-activation-e2e-helpers.ts"
- ".github/actions/ci-reviewed-npm-audit/**"
- ".github/actions/build-base-image-platform/**"
- ".github/actions/publish-base-image-manifest/**"
Expand Down
109 changes: 105 additions & 4 deletions .github/workflows/codebase-growth-guardrails.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
name: CI / Codebase Growth Guardrails

# pull_request_target runs in the base repo context, so this policy cannot be
# bypassed by editing workflow files or tools in the PR. The trusted assertion
# reads PR metadata and blobs as data. It does not execute PR code.
# bypassed by editing workflow files or scripts in the PR. Keep this workflow
# data-only: do not check out or execute PR code. It only reads GitHub's
# file-level diff metadata.
on:
pull_request_target:
types: [opened, reopened, synchronize, ready_for_review]
Expand All @@ -20,6 +21,92 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Block newly added JavaScript files
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail

rows="$(gh api --paginate "/repos/${REPO}/pulls/${PR_NUMBER}/files" \
--jq '.[] | select((.filename | test("\\.(js|cjs|mjs)$")) and (.status == "added" or (.status == "renamed" and ((.previous_filename // "") | test("\\.(js|cjs|mjs)$") | not)))) | [.status, .filename, (.previous_filename // "")] | @tsv')"

if [ -z "$rows" ]; then
echo "PASS: no newly added .js, .cjs, or .mjs files."
exit 0
fi

cat <<'EOF'
FAIL: this PR adds JavaScript source files.

NemoClaw is standardizing on TypeScript for new Node.js code. Please
use .ts for new source, test, and script files instead of .js, .cjs,
or .mjs. Existing JavaScript files may still be modified or deleted.

Blocked files:
EOF
while IFS=$'\t' read -r file_status file_path previous_path; do
if [ -n "$previous_path" ]; then
echo " - ${file_path} (${file_status} from ${previous_path})"
else
echo " - ${file_path} (${file_status})"
fi
done <<< "$rows"
exit 1

- name: Require src/lib/onboard.ts to be net-neutral or smaller
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
TARGET_FILE: src/lib/onboard.ts
EXTRACTION_DIR: src/lib/onboard/
run: |
set -euo pipefail

# Intentionally hard-code TARGET_FILE in the jq expression. gh's jq
# filter does not accept shell variables directly, and missing
# previous_filename values must not match every file.
rows="$(gh api --paginate "/repos/${REPO}/pulls/${PR_NUMBER}/files" \
--jq '.[] | select(.filename == "src/lib/onboard.ts" or .previous_filename == "src/lib/onboard.ts") | [.additions, .deletions, .filename] | @tsv')"

if [ -z "$rows" ]; then
echo "${TARGET_FILE} was not changed. New modules under ${EXTRACTION_DIR} are allowed."
exit 0
fi

additions=0
deletions=0
while IFS=$'\t' read -r file_additions file_deletions _file_path; do
if [ -z "${file_additions:-}" ]; then
continue
fi
additions=$((additions + file_additions))
deletions=$((deletions + file_deletions))
done <<< "$rows"

net=$((additions - deletions))
echo "${TARGET_FILE}: +${additions}/-${deletions} (net ${net})"
echo "Growth under ${EXTRACTION_DIR} is allowed; this budget applies only to ${TARGET_FILE}."

if [ "$additions" -le "$deletions" ]; then
echo "PASS: ${TARGET_FILE} is net-neutral or smaller."
exit 0
fi

cat <<EOF
FAIL: ${TARGET_FILE} grew by ${net} line(s).

${TARGET_FILE} is already about 12k lines. Please move new logic into
focused modules under ${EXTRACTION_DIR}, or reduce ${TARGET_FILE} by at
least as many lines as this PR adds there.

This check allows src/lib/onboard/** to grow. It only blocks net growth
in the top-level onboard entrypoint.
EOF
exit 1

- name: Check out the trusted base revision
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -29,12 +116,26 @@ jobs:
- name: Install trusted dependencies
run: npm ci --ignore-scripts --no-audit --no-fund

- name: Enforce the codebase growth contract
- name: Require changed test files to stay within size budget
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
node --experimental-strip-types tools/growth-guardrails/test-size-budget.mts

- name: Require changed test files not to add if statements
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: node --experimental-strip-types tools/growth-guardrails/check-pr.mts
run: |
set -euo pipefail
node --experimental-strip-types tools/growth-guardrails/test-conditionals.mts
Loading
Loading