Skip to content

Commit

Permalink
build: introduce pre-commit checks
Browse files Browse the repository at this point in the history
  • Loading branch information
fvranicTT committed Feb 24, 2025
1 parent 8dde27a commit f854a34
Show file tree
Hide file tree
Showing 210 changed files with 18,839 additions and 17,411 deletions.
45 changes: 45 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
BasedOnStyle: Google
ColumnLimit: 120
IndentWidth: 4

# This will make access modifiers (public/protected/private) sit on the same indentation as `class` keyword
AccessModifierOffset: -4

# Arguments, parameters and construction initializer are broken as following:
# - Try to fit everything into single line (controlled by ColumnLimit).
# - If it doesn't fit, break immediately after open bracket (in case of arguments and parameters)
# or after colon in case of constructor initializers.
# - Try to fit everything else into the second line.
# - If it doesn't fit in second line, then each argument, parameter or initializer will sit in its own line.
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: true
AlignConsecutiveBitFields: true
AlignConsecutiveDeclarations: true
AlignTrailingComments: true
AlignEscapedNewlines: Left
AlignOperands: true
BinPackArguments: false
BinPackParameters: false

# When constructor initializers exist in the constructor definition, leave the colon as last thing on the original
# line instead of putting it on the next line.
BreakConstructorInitializers: AfterColon

# Pointer and reference alignment
DerivePointerAlignment: true
PointerAlignment: Left
ReferenceAlignment: Left

# Disallow single statements after if/else/for/while/do without curly braces.
InsertBraces: true
BreakBeforeBraces: Attach

# Separate definition blocks, including classes, structs, enums, and functions.
SeparateDefinitionBlocks: Always
SpaceBeforeCpp11BracedList: true
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
AllowShortLoopsOnASingleLine: true
AllowShortBlocksOnASingleLine: true
RemoveSemicolon: true
SortUsingDeclarations: LexicographicNumeric
28 changes: 28 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Run Pre-commit Hooks
name: Run Pre-commit Hooks

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

jobs:
pre-commit:
name: Run Pre-commit Hooks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history so 'origin/main' is available

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Run Pre-commit and Fix Issues
uses: pre-commit/action@v3.0.1
with:
extra_args: "--from-ref origin/main --to-ref HEAD"
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.7
hooks:
- id: clang-format
args: ["-style=file"]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint
exclude: ^(?!\.github/).* # Only include files in .github/
- repo: https://github.com/espressif/check-copyright/
rev: v1.0.3
hooks:
- id: check-copyright
args: ['--config', 'infra/check_copyright_config.yaml', "--ignore", ""]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
11 changes: 11 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

extends: default

rules:
# yaml documents should start optionally with ---
document-start: disable
line-length:
max: 120
# the "on:" is detected as truthy value and spawns a false warning
truthy: disable
5 changes: 5 additions & 0 deletions infra/check_copyright_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ DEFAULT:
//
// SPDX-License-Identifier: {license}
new_notice_python: | # notice for new python files
# SPDX-FileCopyrightText: © {years} Tenstorrent AI ULC
#
# SPDX-License-Identifier: {license}
# comment lines matching:
# SPDX-FileCopyrightText: year[-year] Espressif Systems
# or
Expand Down
Loading

0 comments on commit f854a34

Please sign in to comment.