From 08d6fa2cb98e1811c903c78a93d752c0bf7fb167 Mon Sep 17 00:00:00 2001 From: John Wason Date: Sat, 16 Mar 2024 23:01:32 -0400 Subject: [PATCH 1/4] Add pre-commit-config.yaml --- .pre-commit-config.yaml | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .pre-commit-config.yaml 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 From c3a604f0f26bd008bc596abeb0df2d24f31baa8b Mon Sep 17 00:00:00 2001 From: John Wason Date: Sat, 16 Mar 2024 23:03:32 -0400 Subject: [PATCH 2/4] Add pre-commit github action --- .github/workflows/clang_format.yml | 30 ----------------------------- .github/workflows/cmake_format.yml | 31 ------------------------------ .github/workflows/pre_commit.yml | 22 +++++++++++++++++++++ 3 files changed, 22 insertions(+), 61 deletions(-) delete mode 100644 .github/workflows/clang_format.yml delete mode 100644 .github/workflows/cmake_format.yml create mode 100644 .github/workflows/pre_commit.yml 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..8d0915b9005 --- /dev/null +++ b/.github/workflows/pre_commit.yml @@ -0,0 +1,22 @@ +name: pre-commit + +on: + push: + branches: + - master + - 'dev**' + pull_request: + schedule: + - cron: '0 5 * * *' + +jobs: + pre-commit: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - name: apt + run: | + sudo apt update + sudo apt install -y dos2unix + - uses: pre-commit/action@v3.0.1 From 730521643e2f2b7cd57d5cc285805b1a14523134 Mon Sep 17 00:00:00 2001 From: John Wason Date: Sun, 17 Mar 2024 15:02:57 -0400 Subject: [PATCH 3/4] Skip no-commit-to-branch pre-commit hook on github actions --- .github/workflows/pre_commit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pre_commit.yml b/.github/workflows/pre_commit.yml index 8d0915b9005..7f13116cead 100644 --- a/.github/workflows/pre_commit.yml +++ b/.github/workflows/pre_commit.yml @@ -12,6 +12,8 @@ on: jobs: pre-commit: runs-on: ubuntu-22.04 + env: + SKIP: no-commit-to-branch steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 From a081b63f828b7321e7d38fae58d2137cc1c7c055 Mon Sep 17 00:00:00 2001 From: John Wason Date: Sun, 17 Mar 2024 15:03:34 -0400 Subject: [PATCH 4/4] Use Python 3.10 for pre-commit --- .github/workflows/pre_commit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pre_commit.yml b/.github/workflows/pre_commit.yml index 7f13116cead..7da2103ab70 100644 --- a/.github/workflows/pre_commit.yml +++ b/.github/workflows/pre_commit.yml @@ -17,6 +17,8 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 + with: + python-version: '3.10' - name: apt run: | sudo apt update