Skip to content

Commit

Permalink
feat: add pre commit config (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
nichmor authored Jul 12, 2024
1 parent b830baf commit 73b260d
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: pre-commit

on:
push:
branches: [ "main" ]
pull_request:

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up pixi
uses: prefix-dev/[email protected]
with:
environments: lint
- name: pre-commit
run: pixi run pre-commit-run --color=always --show-diff-on-failure
env:
# As the rust GitHub action is better at the rust jobs it can be skipped in this job.
SKIP: clippy,fmt
74 changes: 74 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
exclude: (^.pixi/|.snap)
repos:
- repo: local
hooks:
- id: pixi-install
name: pixi-install
entry: pixi install -e lint
language: system
always_run: true
require_serial: true
pass_filenames: false
# pre-commit-hooks
- id: check-yaml
name: check-yaml
entry: pixi run -e lint check-yaml
language: system
types: [yaml]
- id: end-of-file
name: end-of-file
entry: pixi run -e lint end-of-file-fixer
language: system
types: [text]
stages: [commit, push, manual]
- id: trailing-whitespace
name: trailing-whitespace
entry: pixi run -e lint trailing-whitespace-fixer
language: system
types: [text]
stages: [commit, push, manual]
# Use ruff for python examples
- id: ruff
name: ruff
entry: pixi run -e lint ruff check --fix --exit-non-zero-on-fix --force-exclude
language: system
types_or: [python, pyi]
require_serial: true
- id: ruff-format
name: ruff-format
entry: pixi run -e lint ruff format --force-exclude
language: system
types_or: [python, pyi]
require_serial: true
# typos
- id: typos
name: typos
entry: pixi run -e lint typos --write-changes --force-exclude
language: system
types: [text]
# Copied from Mozilla https://github.com/mozilla/grcov/blob/master/.pre-commit-config.yaml
- repo: https://github.com/DevinR528/cargo-sort
rev: v1.0.9
hooks:
- id: cargo-sort
- repo: local
hooks:
- id: fmt
name: fmt
language: system
types: [file, rust]
entry: cargo fmt
pass_filenames: false
- id: clippy
name: clippy
language: system
types: [file, rust]
entry: cargo clippy --all-targets -- -D warnings -Dclippy::dbg_macro # Use -D warnings option to ensure the job fails when encountering warnings
pass_filenames: false
- id: test
name: test
language: system
stages: [push]
types: [file, rust]
entry: cargo test
pass_filenames: false
13 changes: 13 additions & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ make = "~=4.3"
pkg-config = "~=0.29.2"
rust = "~=1.75.0"
cmake = "~=3.26.4"

[feature.lint.dependencies]
pre-commit = ">=3.7.1,<4"
pre-commit-hooks = ">=4.6.0,<5"
ruff = ">=0.4.8,<0.5"
typos = ">=1.23.1,<2"

[feature.lint.tasks]
pre-commit-install = "pre-commit install"
pre-commit-run = "pre-commit run"

[environments]
lint = { features = ["lint"], no-default-feature = true, solve-group = "default" }

0 comments on commit 73b260d

Please sign in to comment.