Skip to content
Open
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
41 changes: 41 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: MIT

name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit on changed files
run: |
set -e
if [ "${{ github.event_name }}" = "pull_request" ]; then
base_sha="${{ github.event.pull_request.base.sha }}"
else
base_sha="${{ github.event.before }}"
fi
echo "Base SHA: ${base_sha}"
echo "Head SHA: ${{ github.sha }}"
changed=$(git diff --name-only "${base_sha}" "${{ github.sha }}" || true)
if [ -n "${changed}" ]; then
echo "Checking changed files:"
echo "${changed}"
pre-commit run --files ${changed} --show-diff-on-failure
else
echo "No changed files to check."
fi
45 changes: 45 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: MIT

# Pre-commit hooks for TileGym.
#
# Run locally with `bash format.sh` (which installs and runs these hooks), or
# directly with `pre-commit run --all-files`. CI runs these hooks on the files
# changed by each pull request (see .github/workflows/pre-commit.yml).
#
# Skill content under `skills/` is intentionally excluded: those files are
# signed artifacts (each skill ships a `skill.oms.sig`), so reformatting them
# would invalidate the signature. Skills are validated and signed by the
# NVSkills pipeline, not hand-formatted.

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
hooks:
- id: trailing-whitespace
exclude: '^skills/|\.patch$'
- id: end-of-file-fixer
exclude: '^skills/|\.patch$'
- id: check-yaml
exclude: '^skills/'
- id: check-added-large-files
exclude: '^skills/|\.patch$'
- id: check-json
exclude: '^skills/'
- id: pretty-format-json
args: ['--autofix', '--indent=2']
exclude: '^skills/'

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.9
hooks:
- id: ruff-check
name: ruff-lint
args: [--fix]
types_or: [python]
exclude: '^skills/|\.patch$'
- id: ruff-format
name: ruff-format
types_or: [python]
exclude: '^skills/|\.patch$'
25 changes: 22 additions & 3 deletions format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,32 @@
#
# SPDX-License-Identifier: MIT

# Quick formatting script for TileGym development
# Formats code and sorts imports using ruff
# Quick formatting script for TileGym development.
# Runs the pre-commit hooks, adds SPDX headers, and formats/sorts with ruff.

set -e

RUFF_VERSION="0.14.9"

echo "🔍 Checking pre-commit installation..."
if ! command -v pre-commit &> /dev/null; then
echo "📦 Installing pre-commit..."
pip install pre-commit
fi

echo ""
echo "Installing pre-commit hooks..."
pre-commit install-hooks

echo ""
echo "Running all pre-commit hooks..."
# Run pre-commit on all files; continue even if some hooks fail
# (several hooks are auto-fixers and will modify files).
set +e
pre-commit run --all-files
set -e

echo ""
echo "🔍 Checking ruff installation..."
if ! python3 -m ruff --version 2>/dev/null | grep -q "$RUFF_VERSION"; then
echo "📦 Installing ruff $RUFF_VERSION..."
Expand All @@ -29,4 +48,4 @@ echo "✨ Formatting code..."
python3 -m ruff format .

echo ""
echo "✅ Done! SPDX headers added, code is formatted, and imports are sorted."
echo "✅ Done! Pre-commit hooks ran, SPDX headers added, code formatted, imports sorted."
Loading