From 7cd375bbbfa4319042888cf13ebdee36450b8e51 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jan 2024 15:01:59 +0100 Subject: [PATCH] Clean hooks --- .github/workflows/phpcs.yml | 1 + .github/workflows/phpcsfixer.yml.disabled | 63 ----------------------- .github/workflows/pre-commit.yml | 10 ++++ .pre-commit-config.yaml | 19 ++++++- 4 files changed, 28 insertions(+), 65 deletions(-) delete mode 100644 .github/workflows/phpcsfixer.yml.disabled diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index 1bb1184586f..2b73f3bcba9 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -11,6 +11,7 @@ jobs: phpcs: runs-on: ubuntu-latest steps: + # Get git sources - uses: actions/checkout@v4 with: fetch-depth: 50 # important! diff --git a/.github/workflows/phpcsfixer.yml.disabled b/.github/workflows/phpcsfixer.yml.disabled deleted file mode 100644 index 959ba5ad801..00000000000 --- a/.github/workflows/phpcsfixer.yml.disabled +++ /dev/null @@ -1,63 +0,0 @@ -name: GitHub CI PHPCS and PHPCBF - -on: - pull_request: - types: [opened] -#on: -# push: -# paths: -# - '**.php' - -jobs: - #filesChanged: - # uses: ./.github/workflows/files_changed.yaml - # with: - # folder_path: .* - - linter_name: - name: Run & fix PHP Code Sniffer - runs-on: ubuntu-latest - #needs: filesChanged - steps: - - uses: actions/checkout@v3 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.event.pull_request.head.ref }} - # fetch-depth: 10 - - - name: echo Get list of all changed files - run: | - #echo ${{ needs.filesChanged.outputs.all_changed_files }} - #echo boolean_output=${{ needs.filesChanged.outputs.boolean_output }} - echo github.head_ref=${{github.head_ref}} - echo github.base_ref=${{github.base_ref}} - echo github.ref_name=${{github.ref_name}} - - - uses: eldy/phpcsfixer-action@master - with: - github_token: ${{ secrets.github_token }} - use_default_configuration_file: false - phpcs_standard: 'dev/setup/codesniffer/ruleset.xml' - phpcs_head_ref: ${{github.head_ref}} - phpcs_base_ref: ${{github.base_ref}} - phpcs_ref_name: ${{github.ref_name}} - phpcs_github_event_name: ${{github.event_name}} - phpcs_files: ${{ needs.filesChanged.outputs.all_changed_files }} - - #- uses: stefanzweifel/git-auto-commit-action@v4 # auto commit the fixes action for GitHub - # with: - # commit_message: Fix PHPCS errors by GitHub PHPCSfixer action - - - name: Commit changes - uses: EndBug/add-and-commit@v9.1.3 - with: - default_author: github_actions - committer_name: GitHub Actions - committer_email: actions@github.com - #author_name: PHP CS fixer - #author_email: eldy@destailleur.fr - #committer_name: PHP CS fixer - #committer_email: eldy@destailleur.fr - message: 'PHP CS fixer github action' - add: '*.php' - diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 9ade67aee82..41269a8d3a0 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -14,20 +14,25 @@ jobs: - name: Install required tools run: sudo apt-get update && sudo apt-get install cppcheck if: false + # Checkout git sources to analyze - uses: actions/checkout@v4 + # ??? - name: Create requirements.txt if no requirements.txt or pyproject.toml run: |- [ -r requirements.txt ] || [ -r pyproject.toml ] || touch requirements.txt + # Install python and pre-commit tool - uses: actions/setup-python@v4 with: cache: pip python-version: '3.11' - run: python -m pip install pre-commit regex + # Restore previous cache of precommit - uses: actions/cache/restore@v3 with: path: ~/.cache/pre-commit/ key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + # Run alls the precommit tools (defined into pre-commit-config.yaml). We can force exclusion of some of them here. - name: Run pre-commit hooks env: # SKIP is used by pre-commit to not execute certain hooks @@ -36,10 +41,12 @@ jobs: set -o pipefail pre-commit gc pre-commit run --show-diff-on-failure --color=always --all-files | tee ${RAW_LOG} + # If error, we convert log in the checkstyle format - name: Convert Raw Log to CheckStyle format if: ${{ failure() }} run: | python ${LOG_TO_CS} ${RAW_LOG} ${CS_XML} + # Annotate the git sources with the log messages - name: Annotate Source Code with Messages uses: staabm/annotate-pull-request-from-checkstyle-action@v1 if: ${{ failure() }} @@ -47,12 +54,15 @@ jobs: files: ${{ env.CS_XML }} notices-as-warnings: true # optional prepend-filename: true # optional + + # Save the precommit cache - uses: actions/cache/save@v3 if: ${{ always() }} with: path: ~/.cache/pre-commit/ key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + # Upload result log files of precommit into the Artifact shared store - name: Provide log as artifact uses: actions/upload-artifact@v3 if: ${{ always() }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8a3e5e4dbf1..3429b6b93d7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,7 @@ --- exclude: (?x)^( htdocs/includes/ckeditor/.* ) repos: + # Several miscellaneous checks and fix (on yaml files, end of files fix) - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: @@ -24,13 +25,16 @@ repos: |build/debian/dolibarr.config )$ - id: fix-byte-order-marker - id: check-case-conflict - - id: check-toml + + # Beautify shell scripts - repo: https://github.com/lovesegfault/beautysh.git rev: v6.2.1 hooks: - id: beautysh exclude: (?x)^(dev/setup/git/hooks/pre-commit)$ args: [--tab] + + # Run local script - repo: local hooks: - id: local-precommit-script @@ -38,6 +42,8 @@ repos: language: system entry: bash -c '[ ! -x local.sh ] || ./local.sh' pass_filenames: false + + # Check PHP syntax - repo: https://github.com/bolovsky/pre-commit-php rev: 1.5.1 hooks: @@ -46,6 +52,8 @@ repos: args: [-p] - id: php-cs - id: php-lint + + # Prettier (format code, only for non common files) - repo: https://github.com/pre-commit/mirrors-prettier rev: v3.0.3 hooks: @@ -66,6 +74,8 @@ repos: - scss - css - yaml + + # Check format of yam files - repo: https://github.com/adrienverge/yamllint.git rev: v1.32.0 hooks: @@ -74,6 +84,8 @@ repos: - --no-warnings - -d - '{extends: relaxed, rules: {line-length: {max: 120}}}' + + # Execute codespell to fix typo errors (setup of codespell into dev/tools/codespell/) - repo: https://github.com/codespell-project/codespell rev: v2.2.5 hooks: @@ -85,6 +97,8 @@ repos: additional_dependencies: [tomli] - alias: codespell-lang-en_US # Only for translations with specialised exceptions + # -D contains predefined conversion dictionaries + # -L is to ignore some words id: codespell files: ^htdocs/langs/en_US/.*$ args: @@ -95,8 +109,9 @@ repos: - -L - informations,medias,uptodate,reenable,crypted,developpers - -L - - "creat,unitl,alltime,datas,referers,process'" + - "creat,unitl,alltime,datas,referers" + # Check some shell scripts - repo: https://github.com/shellcheck-py/shellcheck-py rev: v0.9.0.5 hooks: