Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions .pre-commit-config.yaml

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ MOCK_DATA=true mvn javafx:run
.\setup.ps1

# macOS / Linux:
pip install pre-commit
pre-commit install
brew install lefthook
lefthook install
```

Ручная проверка всего сразу: `pre-commit run --all-files`.
Ручная проверка всего сразу: `lefthook run pre-commit`.
Если упал формат — поправить: `mvn spotless:apply`.

## RBAC
Expand Down
24 changes: 24 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Lefthook config for this Java/Maven project (replaces pre-commit).
#
# All jobs are CHECK-ONLY (no auto-fix):
# - lint via `mvn checkstyle:check`
# - format via `mvn spotless:check` (use `mvn spotless:apply` manually to fix)
# - unit tests via `mvn test` (integration tests tagged `integration` are
# already excluded from the default build via surefire `excludedGroups`
# in pom.xml, so no live backend is needed)
#
# Install/activate (per clone):
# brew install lefthook # or: winget install evilmartians.lefthook / scoop install lefthook
# lefthook install
#
# Run manually:
# lefthook run pre-commit
pre-commit:
parallel: false
jobs:
- name: "lint: mvn checkstyle:check"
run: mvn -B checkstyle:check
- name: "format: mvn spotless:check"
run: mvn -B spotless:check
- name: "test: mvn test (unit only, integration excluded)"
run: mvn -B test
30 changes: 15 additions & 15 deletions setup.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<#
.SYNOPSIS
Sets up git pre-commit hooks for this repo (pre-commit framework).
Sets up git hooks for this repo (lefthook).

.DESCRIPTION
Installs the `pre-commit` package if missing and runs `pre-commit install`
Installs `lefthook` if missing and runs `lefthook install`
so the lint/format/unit-test checks run automatically on every `git commit`.
Works on Windows PowerShell 5.1 and PowerShell 7+.
#>
Expand All @@ -18,27 +18,27 @@ if (-not (Test-Command 'git')) {
exit 1
}

$Python = if (Test-Command 'python') { 'python' } elseif (Test-Command 'python3') { 'python3' } else { $null }
if (-not $Python) {
Write-Error 'Python not found in PATH. Install Python 3 (python.org) with "Add to PATH" and retry.'
exit 1
}

# Must run inside the repo so hooks land in .git/hooks.
$null = git rev-parse --show-toplevel 2>$null
if ($LASTEXITCODE -ne 0) {
Write-Error 'Not inside a git repository. Run this script from the repo root.'
exit 1
}

& $Python -m pre_commit --version > $null 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host 'pre-commit not found, installing via pip...'
& $Python -m pip install --user pre-commit
if (-not (Test-Command 'lefthook')) {
if (Test-Command 'winget') {
Write-Host 'lefthook not found, installing via winget...'
winget install --exact --id evilmartians.lefthook
} elseif (Test-Command 'scoop') {
Write-Host 'lefthook not found, installing via scoop...'
scoop install lefthook
} else {
Write-Error 'lefthook not found in PATH. Install it (winget install evilmartians.lefthook, or scoop install lefthook) and retry.'
exit 1
}
}

# Use `python -m` so it works even if pip --user Scripts dir is not on PATH.
& $Python -m pre_commit install
lefthook install
Write-Host ''
Write-Host 'Done. Hooks will run on every commit.'
Write-Host 'To check everything right now: pre-commit run --all-files'
Write-Host 'To check everything right now: lefthook run pre-commit'
Loading