diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 0000000..edb638e --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,57 @@ +name: pre-commit + +on: [ push, pull_request ] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + #---------------------------------------------- + # Check-out repo and set-up python + #---------------------------------------------- + - name: Check out repository + uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + #---------------------------------------------- + # Install Poetry if not cached + #---------------------------------------------- + - name: Load cached Poetry installation + id: cached-poetry + uses: actions/cache@v4 + with: + path: ~/.local # the path depends on the OS + key: poetry-1.7.1 # increment to reset cache + - name: Install Poetry + if: steps.cached-poetry.outputs.cache-hit != 'true' + uses: snok/install-poetry@v1 + with: + version: '1.7.1' + virtualenvs-create: true + virtualenvs-in-project: true + #---------------------------------------------- + # Install project dependencies if not cached + #---------------------------------------------- + - name: Load cached Poetry dependencies + id: cached-poetry-dependencies + uses: actions/cache@v4 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + - name: Install Poetry dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction --no-root --with code-style + #---------------------------------------------- + # Run pre-commit with cache + #---------------------------------------------- + - name: Load pre-commit caches + uses: actions/cache@v4 + with: + path: ~/.cache/pre-commit + key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + - name: Run pre-commit + run: poetry run pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual + env: + RUFF_FORMAT: github diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d93d2fa..bbad5b4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,32 +4,26 @@ # pre-commit install # pre-commit run --all-files -default_install_hook_types: - - pre-push +default_stages: - pre-commit - -default_stages: [ commit, commit-msg, manual, merge-commit, post-checkout, post-commit, post-merge, post-rewrite, prepare-commit-msg, push ] + - pre-push + - commit-msg + - manual repos: # Fix some errors with Ruff - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.292 + rev: v0.2.2 hooks: - id: ruff - args: [ --fix, --exit-zero, --show-fixes ] + args: [ --fix, --exit-zero ] name: "ruff: fixing" + - id: ruff-format + name: "ruff: formatting" - # Format with Ruff + # Lint Python files with Ruff - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.292 - hooks: - - id: ruff - args: [ --fix, --exit-zero, --show-fixes ] - name: "ruff: format" - - # Lint with Ruff - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.292 + rev: v0.2.2 hooks: - id: ruff name: "ruff: linting" @@ -39,5 +33,17 @@ repos: rev: v4.5.0 hooks: - id: trailing-whitespace - - id: check-added-large-files + exclude: alembic/ - id: end-of-file-fixer + exclude: alembic/ + - id: check-added-large-files + + # Generate settings.schema.yaml + - repo: local + hooks: + - id: generate-settings-schema + name: generate settings.schema.yaml + language: system + entry: poetry run python ./scripts/generate_settings_schema.py + pass_filenames: false + files: ^src/config_schema.py$