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
53 changes: 53 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Git Hooks Tests

on:
pull_request:
push:
branches: [ main ]

jobs:
shellcheck:
name: ShellCheck Lint
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run ShellCheck
run: |
find . -name "*.sh" -not -path "./vendor/*" -exec shellcheck {} +

unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
needs: shellcheck

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: composer

- name: Install dependencies
run: |
composer init -n
composer require --dev phpstan/phpstan

- name: Prepare test environment
run: |
chmod +x php/*.sh
chmod +x php/laravel/*.sh 2>/dev/null || true
chmod +x shell/*.sh 2>/dev/null || true
chmod +x docker/*.sh 2>/dev/null || true
chmod +x simple/*.sh 2>/dev/null || true
chmod +x tests/run_all.sh
chmod +x tests/lib/*.bash
find tests -name "*.sh" -exec chmod +x {} +

- name: Run all tests
run: ./tests/run_all.sh
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Dependencies
vendor/
composer.lock

# IDE
.idea/
.vscode/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db

# PHPStan baseline (project-specific, not for this repo)
.phpstan-error-count.json

# Test artifacts
tests/**/tmp/
*.tmp

# Logs
*.log
91 changes: 91 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# CLAUDE.md

## Project Overview

A collection of reusable git hook scripts for automating code quality checks. Main focus: PHP/Laravel (PHPStan, Pint), shell script validation (ShellCheck), Docker linting, and commit message enhancement.

## Directory Structure

```
docker/ # Docker-related hooks
├── check_hadolint.sh # Dockerfile linter

git/ # Git workflow hooks
├── check_branch_name.sh # Branch naming convention validator
└── preparations/ # Commit message enhancers
├── add_task_id_in_commit.sh
└── prepare-commit-description.sh

php/ # PHP/Laravel hooks
├── check_phpstan.sh # PHPStan with progressive error reduction
├── find_test.sh # Unit test coverage validator
├── start_test_in_docker.sh # Run PHPUnit tests in Docker
└── laravel/
└── check_pint.sh # Laravel Pint code style fixer

shell/ # Shell script validation
└── check_shellcheck.sh # ShellCheck via Docker

scripts/ # Local utility scripts
├── check_shellcheck.sh # ShellCheck (local execution)
└── pre-commit-check.sh # Pre-commit orchestrator

tests/ # Test framework
├── run_all.sh # Run all test suites
├── lib/test_helper.bash # Test utilities and assertions
└── php/phpstan/ # PHPStan hook tests
```

## Script Conventions

### Input Format
All scripts receive files to check as a list of arguments:
```bash
./php/check_phpstan.sh default file1.php file2.php
```

### Script Header
Every script must start with a description block after the shebang:

```bash
#!/bin/bash
# ------------------------------------------------------------------------------
# Brief description of what the script does.
# Input format and expected arguments.
# Exit conditions (success/failure criteria).
# ------------------------------------------------------------------------------
```

**Requirements:**
- Language: English
- Format: comments inside `# ---...---` delimiters
- Content: 3-5 lines describing:
- What the script does (main action)
- Input format (files/arguments)
- Success/failure conditions (exit codes)

## Dependencies

- Bash 4.0+, Git, jq
- PHP 8.1+, Composer (for PHPStan/Pint)
- Docker (optional, for containerized checks)
- ShellCheck (for shell validation)

## Testing

Run all tests:
```bash
./tests/run_all.sh
```

Run specific test suite:
```bash
./tests/php/phpstan/run.sh
```

## CI/CD

GitHub Actions (`.github/workflows/tests.yml`):
- ShellCheck linting on all scripts
- Unit tests execution
- Triggered on PR and push to main
119 changes: 100 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,117 @@
# Dev Scripts Git Hooks
# Git Hooks Collection

**Коллекция полезных скриптов для разработчиков**
Автоматизация рутинных задач, git-хуки, bash-утилиты и другие мини-инструменты, которые ускоряют и упрощают ежедневную работу программиста.
A collection of reusable git hook scripts for automating code quality checks and developer workflows.

## Простые проверки
## Features

**./shell/preparations/add_task_id_in_commit.sh**
- **PHP/Laravel**: PHPStan analysis with progressive error reduction, Pint code style fixing, test coverage validation
- **Docker**: Dockerfile linting with Hadolint
- **Shell**: Script validation with ShellCheck
- **Git**: Branch naming conventions, automatic task ID injection in commits

Автоматически добавляет ID задачи из названия ветки в начало коммита.
Пример: ветка `feat/dev-123_filter` → коммит `dev-123 | добавил фильтр по типу`.
## Quick Start

**./shell/simple/check_branch_name.sh**
1. Clone the repository
2. Copy desired scripts to your project's `.git/hooks/` directory
3. Make scripts executable: `chmod +x .git/hooks/*`

Пример shell-скрипта, который проверяет, что текущая ветка Git соответствует заданной структуре "^(feature|bugfix|hotfix|release)\/[a-zA-Z0-9]+_[a-zA-Z0-9_-]+$".
## Available Scripts

## Docker compose
### PHP

**./shell/docker/check_docker.sh**
| Script | Description |
|--------|-------------|
| `php/check_phpstan.sh` | Runs PHPStan with progressive error reduction. Tracks error count per file and allows commits only when errors decrease. |
| `php/laravel/check_pint.sh` | Runs Laravel Pint, auto-fixes code style issues, and stages corrected files. |
| `php/find_test.sh` | Validates that modified PHP classes have corresponding unit tests. |
| `php/start_test_in_docker.sh` | Runs PHPUnit tests inside Docker for modified files. |

Проверка работы docker compose сборки (отключение, запуск, работа контейнеров).
### Git Workflow

## Laravel
| Script | Description |
|--------|-------------|
| `git/check_branch_name.sh` | Validates branch names match pattern: `{type}/{task-id}_{description}` |
| `git/preparations/add_task_id_in_commit.sh` | Prepends task ID from branch name to commit message. |
| `git/preparations/prepare-commit-description.sh` | Appends list of changed files to commit message. |

**./php/laravel/check_phpstan.sh**
### Docker

Проверка добавленных или изменённых файлов, через статический анализатор PHPStan.
| Script | Description |
|--------|-------------|
| `docker/check_hadolint.sh` | Lints Dockerfiles using Hadolint. |

**./php/laravel/check_pint.sh**
### Shell

Проверка и автоисправление code style добавленных или изменённых файлов, через модуль Pint.
| Script | Description |
|--------|-------------|
| `shell/check_shellcheck.sh` | Validates shell scripts using ShellCheck (via Docker). |
| `scripts/check_shellcheck.sh` | Validates shell scripts using ShellCheck (local). |

**./php/laravel/find_tests.sh**
## Usage Examples

Проверяет созданы ли тесты для классов, которые были добавлены в git индекс.
### PHPStan with Progressive Error Reduction

```bash
# Default mode: requires error count to decrease by at least 1
./php/check_phpstan.sh default src/Service.php src/Helper.php

# Strict mode: requires zero errors
./php/check_phpstan.sh strict src/Service.php
```

### Branch Name Validation

```bash
# In pre-commit hook
./git/check_branch_name.sh
# Valid: feature/dev-123_user_auth, bugfix/issue-456_fix_login
# Invalid: main, my-branch, feature/no_task_id
```

### Task ID in Commits

```bash
# In prepare-commit-msg hook
./git/preparations/add_task_id_in_commit.sh
# Branch: feature/dev-123_new_feature
# Commit: "add validation" → "dev-123 | add validation"
```

## Integration

### Pre-commit Hook Example

```bash
#!/bin/bash
# .git/hooks/pre-commit

FILES=$(git diff --cached --name-only --diff-filter=ACM)
PHP_FILES=$(echo "$FILES" | grep '\.php$')
SH_FILES=$(echo "$FILES" | grep '\.sh$')

[[ -n "$PHP_FILES" ]] && ./php/check_phpstan.sh default $PHP_FILES
[[ -n "$SH_FILES" ]] && ./scripts/check_shellcheck.sh $SH_FILES
```

## Testing

```bash
# Run all tests
./tests/run_all.sh

# Run specific test suite
./tests/php/phpstan/run.sh
```

## Requirements

- Bash 4.0+
- Git
- jq
- PHP 8.1+ with Composer (for PHP hooks)
- Docker (optional)
- ShellCheck (for shell validation)

## License

MIT
34 changes: 0 additions & 34 deletions docker/check_docker.sh

This file was deleted.

Loading