Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
feat: enable pre-commit workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dantetemplar committed Feb 25, 2024
1 parent e8743c3 commit 8685e1c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 18 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ __pycache__/
.env
./.ruff_cache
.DS_Store
settings.yaml
settings.yaml
40 changes: 23 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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$

0 comments on commit 8685e1c

Please sign in to comment.