diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..ee1bee2 --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: Google +ColumnLimit: 100 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..db232bc --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,49 @@ +name: Lint + +on: + pull_request: + branches: [main] + types: [opened, synchronize, reopened] + +concurrency: + group: lint-${{ github.event.pull_request.number }} + cancel-in-progress: true + +env: + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true + +jobs: + lint: + name: "Lint" + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Check script permissions + run: | + errors=0 + for f in scripts/*.sh; do + [ -f "$f" ] || continue + if [ ! -x "$f" ]; then + echo "::error file=$f::Script is not executable" + errors=$((errors + 1)) + fi + done + if [ "$errors" -gt 0 ]; then + echo "::error::$errors script(s) missing executable permission" + exit 1 + fi + + - name: Build Docker image + run: docker build -f scripts/Dockerfile . --network host --tag cunls:local + + - name: Run pre-commit (changed files) + run: | + docker run --rm \ + -v "$(pwd):/cunls" \ + -w /cunls \ + cunls:local \ + bash -c "git config --global --add safe.directory /cunls && pre-commit run --from-ref origin/main --to-ref HEAD" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0d5ccd9 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v15.0.7 + hooks: + - id: clang-format + types_or: [c++, cuda] diff --git a/scripts/Dockerfile b/scripts/Dockerfile index acc4202..3f16d11 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -21,7 +21,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ RUN python3 -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" RUN pip install --upgrade pip && \ - pip install scikit-build-core nanobind build wheel + pip install scikit-build-core nanobind build wheel pre-commit # Sphinx docs dependencies COPY docs/sphinx/requirements.txt /tmp/cunls-docs-requirements.txt