diff --git a/.github/workflows/clang_format.yml b/.github/workflows/clang_format.yml deleted file mode 100644 index 089a88125fc..00000000000 --- a/.github/workflows/clang_format.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Clang-Format - -on: - push: - branches: - - master - - 'dev**' - pull_request: - paths: - - 'tesseract**' - - '.github/workflows/clang_format.yml' - - '**clang-format' - schedule: - - cron: '0 5 * * *' - -jobs: - clang_format: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v1 - - - name: Run clang format - run: | - sudo apt update - sudo apt install -y git clang-format-8 - if [ $? -ge 1 ]; then return 1; fi - ./.run-clang-format - if [ $? -ge 1 ]; then return 1; fi - output=$(git diff) - if [ -n "$output" ]; then exit 1; else exit 0; fi diff --git a/.github/workflows/cmake_format.yml b/.github/workflows/cmake_format.yml deleted file mode 100644 index 501fbcbdf12..00000000000 --- a/.github/workflows/cmake_format.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: CMake-Format - -on: - push: - branches: - - master - - 'dev**' - pull_request: - paths: - - 'tesseract**' - - '.github/workflows/clang_format.yml' - - '**clang-format' - schedule: - - cron: '0 5 * * *' - -jobs: - cmake_format: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - - name: Run CMake Lang Format Check - run: | - sudo pip3 install cmakelang - RED='\033[0;31m' - NC='\033[0m' # No Color - ./.run-cmake-format - output=$(git diff) - if [ -n "$output" ]; then printf "${RED}CMake format error: run script './.run-cmake-formate'${NC}\n"; fi - if [ -n "$output" ]; then printf "${RED}${output}${NC}\n"; fi - if [ -n "$output" ]; then exit 1; else exit 0; fi diff --git a/.github/workflows/pre_commit.yml b/.github/workflows/pre_commit.yml new file mode 100644 index 00000000000..7da2103ab70 --- /dev/null +++ b/.github/workflows/pre_commit.yml @@ -0,0 +1,26 @@ +name: pre-commit + +on: + push: + branches: + - master + - 'dev**' + pull_request: + schedule: + - cron: '0 5 * * *' + +jobs: + pre-commit: + runs-on: ubuntu-22.04 + env: + SKIP: no-commit-to-branch + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + with: + python-version: '3.10' + - name: apt + run: | + sudo apt update + sudo apt install -y dos2unix + - uses: pre-commit/action@v3.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000000..b3cff37c3ea --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,61 @@ +exclude: ^.*\.dae$ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: "v4.5.0" + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + exclude: .clang-format + args: ['--unsafe'] + - id: check-ast + - id: check-docstring-first + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + - id: trailing-whitespace + - id: fix-byte-order-marker + - id: check-executables-have-shebangs + - id: check-shebang-scripts-are-executable + - id: check-json + - id: check-toml + - id: check-xml + - id: detect-private-key + - id: no-commit-to-branch + args: ['--branch', 'master'] + - id: forbid-submodules +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v14.0.6 + hooks: + - id: clang-format + types_or: [c++, c, java, c#] +- repo: https://github.com/hhatto/autopep8 + rev: v2.0.4 + hooks: + - id: autopep8 + args: ["--ignore=E402", "-i", "--max-line-length=120"] +- repo: https://github.com/Kr4is/cmake-format-precommit + rev: b912a5a5bce3c479f4cb52763979cc5a8319eb44 + hooks: + - id: cmake-format +- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.12.0 + hooks: + - id: pretty-format-yaml + args: [--autofix, --indent, '2', '--preserve-quotes'] + exclude: ^\.clang.*$ +# - repo: https://github.com/efrecon/pre-commit-hook-lxml +# rev: v0.1.1 +# hooks: +# - id: format-xml +# exclude: ^.*\.svg$ +- repo: local + hooks: + - id: dos2unix + name: dos2unix + entry: dos2unix + args: ["-n", "-o"] + files: '\.(c|cpp|h|hpp|java|cs|i|m|cmake|txt|css|js|ts|html|md|txt|py|yaml|yml|csproj|rst|py\.in|csproj\.in)$' + language: system