-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(tooling): SPDX --fix, hook ordering, and strict shellcheck fixes #670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dc2142d
3f61059
557d8ac
7f02c42
a455473
ff76418
1107926
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,25 +2,99 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Checks that all given files contain the required SPDX license headers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Usage: check-spdx-headers.sh file1 file2 ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # SPDX header check (and optional auto-insert), similar in spirit to DOCA's check_doca_license.py --fix. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # check-spdx-headers.sh FILE... # fail if header missing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # check-spdx-headers.sh --fix FILE... # insert NVIDIA Apache-2.0 SPDX block after shebang (if any) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPYRIGHT="SPDX-FileCopyrightText: Copyright (c)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LICENSE="SPDX-License-Identifier: Apache-2.0" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPYRIGHT_SUBSTR="SPDX-FileCopyrightText: Copyright (c)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LICENSE_SUBSTR="SPDX-License-Identifier: Apache-2.0" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usage() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Usage: $0 [--fix] FILE..." >&2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FIX=false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "${1:-}" == "--fix" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FIX=true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shift | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[ $# -gt 0 ]] || usage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| has_spdx() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local file=$1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local head | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| head=$(head -n 16 -- "$file" 2>/dev/null) || return 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| grep -Fq "$COPYRIGHT_SUBSTR" <<<"$head" || return 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| grep -Fq "$LICENSE_SUBSTR" <<<"$head" || return 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| comment_style_for() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local base | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| base=$(basename "$1") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "$base" in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Dockerfile | *.dockerfile | *.Dockerfile) echo "#" ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *.ts | *.tsx | *.js | *.mjs | *.cjs) echo "//" ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *) echo "#" ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| spdx_block() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local style=$1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local year | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| year=$(date +%Y) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "$style" == "//" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| printf '// SPDX-FileCopyrightText: Copyright (c) %s NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n' "$year" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| printf '// SPDX-License-Identifier: Apache-2.0\n' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| printf '# SPDX-FileCopyrightText: Copyright (c) %s NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n' "$year" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| printf '# SPDX-License-Identifier: Apache-2.0\n' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| insert_spdx() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local file=$1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local style | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| style=$(comment_style_for "$file") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local tmp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tmp="$(mktemp "${TMPDIR:-/tmp}/nemoclaw-spdx.XXXXXX")" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IFS= read -r first || true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "$first" == '#!'* ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| printf '%s\n' "$first" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| spdx_block "$style" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| printf '\n' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| spdx_block "$style" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| printf '\n' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ -n "${first:-}" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| printf '%s\n' "$first" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } <"$file" >"$tmp" && mv "$tmp" "$file" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+65
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
src="$tmpdir/pre-commit"
printf '#!/usr/bin/env bash\necho ok\n' >"$src"
chmod 755 "$src"
tmp="$(mktemp "${TMPDIR:-/tmp}/nemoclaw-spdx.XXXXXX")"
printf '#!/usr/bin/env bash\n# SPDX-License-Identifier: Apache-2.0\n\necho ok\n' >"$tmp"
mv "$tmp" "$src"
stat -c '%a %n' "$src" 2>/dev/null || stat -f '%Lp %N' "$src"Repository: NVIDIA/NemoClaw Length of output: 104 🏁 Script executed: #!/bin/bash
# First, find the script file
find . -name "check-spdx-headers.sh" -type fRepository: NVIDIA/NemoClaw Length of output: 90 🏁 Script executed: #!/bin/bash
# Test mktemp + mv behavior without stat (which isn't available)
# Create a test directory
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
# Create original file with executable permissions
src="$tmpdir/test-script"
printf '#!/usr/bin/env bash\necho ok\n' >"$src"
chmod 755 "$src"
echo "Original file permissions (using ls -l):"
ls -l "$src"
# Simulate what mktemp does
tmp="$(mktemp "${TMPDIR:-/tmp}/test.XXXXXX")"
printf '#!/usr/bin/env bash\n# Header\necho ok\n' >"$tmp"
echo "Temp file permissions after creation (using ls -l):"
ls -l "$tmp"
# Now do the mv
mv "$tmp" "$src"
echo "Original file permissions after mv (using ls -l):"
ls -l "$src"
# Clean up
rm -f "$src"Repository: NVIDIA/NemoClaw Length of output: 423 🏁 Script executed: cat ./scripts/check-spdx-headers.shRepository: NVIDIA/NemoClaw Length of output: 2527 🏁 Script executed: # Check if this script is used on executable files/hooks
grep -r "check-spdx-headers.sh" --include="*.md" --include="*.yaml" --include="*.yml" --include="*.json"Repository: NVIDIA/NemoClaw Length of output: 390 Preserve the original file permissions when rewriting scripts with mktemp and mv. The Suggested fix insert_spdx() {
local file=$1
local style
style=$(comment_style_for "$file")
local tmp
+ local mode
tmp="$(mktemp "${TMPDIR:-/tmp}/nemoclaw-spdx.XXXXXX")"
+ mode="$(stat -c '%a' "$file" 2>/dev/null || stat -f '%Lp' "$file")"
{
IFS= read -r first || true
if [[ "$first" == '#!'* ]]; then
printf '%s\n' "$first"
spdx_block "$style"
printf '\n'
cat
else
spdx_block "$style"
printf '\n'
if [[ -n "${first:-}" ]]; then
printf '%s\n' "$first"
fi
cat
fi
- } <"$file" >"$tmp" && mv "$tmp" "$file"
+ } <"$file" >"$tmp" && chmod "$mode" "$tmp" && mv "$tmp" "$file"
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| failed=0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for file in "$@"; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file_head="$(head -n 5 -- "$file")" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ! grep -Fq "$COPYRIGHT" <<< "$file_head"; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Missing SPDX-FileCopyrightText: $file" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| failed=1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[ -f "$file" ]] || continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if has_spdx "$file"; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ! grep -Fq "$LICENSE" <<< "$file_head"; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Missing SPDX-License-Identifier: $file" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "$FIX" == true ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Adding SPDX header: $file" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| insert_spdx "$file" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Missing SPDX-FileCopyrightText or SPDX-License-Identifier (first ~16 lines): $file" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| failed=1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit $failed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit "$failed" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Test inference.local routing through OpenShell provider (local vLLM) | ||
| echo '{"model":"nvidia/nemotron-3-nano-30b-a3b","messages":[{"role":"user","content":"say hello"}]}' > /tmp/req.json | ||
| echo '{"model":"nvidia/nemotron-3-nano-30b-a3b","messages":[{"role":"user","content":"say hello"}]}' >/tmp/req.json | ||
| curl -s https://inference.local/v1/chat/completions -H "Content-Type: application/json" -d @/tmp/req.json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Test inference.local routing through OpenShell provider | ||
| echo '{"model":"nvidia/nemotron-3-super-120b-a12b","messages":[{"role":"user","content":"say hello"}]}' > /tmp/req.json | ||
| echo '{"model":"nvidia/nemotron-3-super-120b-a12b","messages":[{"role":"user","content":"say hello"}]}' >/tmp/req.json | ||
| curl -s https://inference.local/v1/chat/completions -H "Content-Type: application/json" -d @/tmp/req.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: NVIDIA/NemoClaw
Length of output: 102
🏁 Script executed:
cat -n .pre-commit-config.yaml | head -100Repository: NVIDIA/NemoClaw
Length of output: 4520
🏁 Script executed:
Repository: NVIDIA/NemoClaw
Length of output: 719
Keep blueprint
__init__.pyfiles out of the lint-staged fixer..pre-commit-config.yamlexplicitly excludesnemoclaw-blueprint/**/__init__.pyfrom the SPDX headers fixer (line 50), but the lint-staged globnemoclaw-blueprint/**/*.py(lines 40–43) sends every staged blueprint__init__.pyfile tocheck-spdx-headers.sh --fix. At least one such file exists (nemoclaw-blueprint/orchestrator/__init__.py). This creates inconsistent behavior between the two hooks and should be excluded from lint-staged as well.🤖 Prompt for AI Agents