Skip to content

Added configurable automatic fixing and docker support #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 80 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
978e6b0
Updated workflow for Laravel 11
Apr 9, 2024
db7ac1d
Updated workflow for Laravel 11
Apr 9, 2024
5462e18
Added separate jobs for Laravel 10 and Laravel 11
Apr 9, 2024
4bd5500
Added separate jobs for Laravel 9
Apr 9, 2024
68dff6e
Added package lock to ignore, removed from project
Apr 9, 2024
0c887ce
Revert changes for package lock
Apr 9, 2024
a73ac10
Added support for more parameters including docker support
Apr 10, 2024
a088a2b
Fixed pint issues
Apr 10, 2024
1f51318
Fixed pipeline failure detection
Apr 15, 2024
39fc6c0
Fixed pint issues
Apr 15, 2024
2987439
Updated readme
Apr 15, 2024
7845c5d
Updated readme and tests
Apr 15, 2024
823ba4e
Updated readme
Apr 15, 2024
4348e40
Fixed after rebase
Apr 15, 2024
7876319
Refactoring for strong typing enforce, added phpstan and rector run i…
Apr 16, 2024
125e7f6
Added rector rules
Apr 16, 2024
8d4f057
Merge pull request #1 from indy2kro/v2-upgrade
indy2kro Apr 16, 2024
80962dd
Updated phpstan standard, added rector and php insights support
Apr 17, 2024
586c33b
Added option for validate_paths
Apr 19, 2024
f9c9440
Added option for analyzer_chunk_size
Apr 19, 2024
857fc11
Create dependabot.yml
indy2kro Apr 22, 2024
1f86040
Merge pull request #2 from indy2kro/workflow-improvements
indy2kro Apr 22, 2024
f1508f9
Create snyk-security.yml
indy2kro Apr 22, 2024
05df3df
Removed snyk config
indy2kro Apr 22, 2024
d671696
Create codacy.yml
indy2kro Apr 22, 2024
f34ae9e
Removed codacy config
indy2kro Apr 22, 2024
ec2ccf2
Fixed param usage
Apr 23, 2024
c121fdf
Updated chunk size to be configurable per command if needed
Aug 27, 2024
fa953bb
Fixed rector tests
Aug 28, 2024
f9255d2
pint fixes
Aug 28, 2024
b29d7c9
pint fixes
Aug 28, 2024
da3736a
pint fixes
Aug 28, 2024
5529338
Updated composer reqs for pest plugin laravel
Aug 28, 2024
4ffd86c
Removed Laravel 9 support
Aug 28, 2024
b31b6d3
Updated npm package lock
Aug 28, 2024
5afdaa6
fix: upgrade prettier from 2.8.7 to 2.8.8
snyk-bot Aug 29, 2024
2c5ef77
Merge pull request #6 from indy2kro/snyk-upgrade-d8cf1bd2f8f4f3aa7180…
indy2kro Aug 29, 2024
74bedf7
Update package-lock.json
indy2kro Sep 15, 2024
af5ca4d
Updated npm deps
indy2kro Sep 15, 2024
54bf0c5
Updated npm deps
indy2kro Sep 15, 2024
0568e8b
Füge Unterstützung für Laravel Sail hinzu
Sep 19, 2024
45b0831
Merge pull request #1 from algorhythm/feature/sail-support
algorhythm Sep 19, 2024
0a5a79b
Extend README.md with a "Laravel Sail" section
Sep 19, 2024
d52e5e9
Optimize README.md
Sep 19, 2024
e12040f
fix: upgrade eslint-plugin-import from 2.30.0 to 2.31.0
snyk-bot Oct 25, 2024
9517dd2
Merge pull request #14 from indy2kro/snyk-upgrade-c8e7d7c76fa31db078b…
indy2kro Oct 25, 2024
987499b
Merge pull request #13 from algorhythm/master
indy2kro Oct 31, 2024
c260866
fix: upgrade eslint-plugin-vue from 9.28.0 to 9.30.0
snyk-bot Nov 21, 2024
fa2b54b
Merge pull request #17 from indy2kro/snyk-upgrade-729e6e31cbbca870f9a…
indy2kro Nov 29, 2024
4063b75
fix: upgrade eslint-plugin-vue from 9.30.0 to 9.31.0
snyk-bot Dec 13, 2024
1dd195d
Merge pull request #18 from indy2kro/snyk-upgrade-4ed081fefb819a68fbc…
indy2kro Dec 13, 2024
ba5ac76
fix: upgrade eslint-plugin-vue from 9.31.0 to 9.32.0
snyk-bot Dec 24, 2024
d666d8b
Merge pull request #20 from indy2kro/snyk-upgrade-693c1e206e36f020688…
indy2kro Dec 28, 2024
9945a05
fix: upgrade blade-formatter from 1.41.1 to 1.42.0
snyk-bot Jan 14, 2025
1774db7
Merge pull request #21 from indy2kro/snyk-upgrade-1ccdbb72389c96dc746…
indy2kro Jan 14, 2025
c787f6f
fix: package.json & package-lock.json to reduce vulnerabilities
snyk-bot Jan 15, 2025
f642713
updated package.json
indy2kro Jan 15, 2025
a0b752f
Update .eslintrcFixture.js
indy2kro Jan 15, 2025
d5cb558
Update .eslintrcFixture.js
indy2kro Jan 15, 2025
e254ed8
Updated files
indy2kro Jan 15, 2025
e38e69f
Skip test for now
indy2kro Jan 15, 2025
ad3f35f
Merge pull request #22 from indy2kro/snyk-fix-7649892480bd83c14c28ebf…
indy2kro Jan 15, 2025
9ee3727
Update main.yml
indy2kro Jan 15, 2025
27e50c3
Update main.yml
indy2kro Jan 15, 2025
bf6af96
Updated deps to be more loose with upgrades
indy2kro Jan 15, 2025
0e89ef9
Added cron execution for tests
indy2kro Jan 15, 2025
316fedd
Update main.yml
indy2kro Jan 15, 2025
26b721d
Fix ESLint tests
igorsgm Jan 23, 2025
9454fa6
Upgrade scrutinizer checks
igorsgm Jan 23, 2025
666d5d3
scrutinizer using 8.2 instead
igorsgm Jan 23, 2025
46cb12a
scrutinizer using node v20.18.2
igorsgm Jan 23, 2025
0e981dd
node v22
igorsgm Jan 23, 2025
f520a67
node v18
igorsgm Jan 23, 2025
dd11c7c
node v18
igorsgm Jan 23, 2025
4be4e2a
node v20 again
igorsgm Jan 23, 2025
28b3457
test
igorsgm Jan 23, 2025
222dcba
Check 2
igorsgm Jan 23, 2025
b827bfd
Check 3
igorsgm Jan 23, 2025
29a2dfd
Check 4
igorsgm Jan 23, 2025
5882893
Using image
igorsgm Jan 23, 2025
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
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
[{*.yml,*.js}]
indent_size = 2
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
-
package-ecosystem: composer
directory: "/"
schedule:
interval: weekly
versioning-strategy: auto
groups:
dev-dependencies:
dependency-type: "development"
135 changes: 32 additions & 103 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,102 +12,13 @@ on:
- master
- main
- develop
schedule:
- cron: "0 6 * * *"

jobs:
laravel9-tests:
runs-on: ubuntu-latest

strategy:
matrix:
operating-system: [ ubuntu-latest ]
php: [ '8.1', '8.2' ]
dependency-stability: [ 'prefer-stable' ]

laravel: [ '9.*' ]
include:
- laravel: 9.*
testbench: 8.*

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}}

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

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Cache node_modules directory
uses: actions/cache@v4
id: node_modules-cache
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}

- name: Install NPM packages
if: steps.node_modules-cache.outputs.cache-hit != 'true'
run: npm ci --include=dev

- name: Install PHP versions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v4
id: actions-cache
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Cache PHP dependencies (vendor)
uses: actions/cache@v4
id: vendor-cache
with:
path: vendor
key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }}

- name: Install Laravel Dependencies
if: steps.vendor-cache.outputs.cache-hit != 'true'
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-stability }} --prefer-dist --no-interaction --no-suggest

- name: Update Dependencies with latest stable
if: matrix.dependency-stability == 'prefer-stable'
run: composer update --prefer-stable

- name: Update Dependencies with lowest stable
if: matrix.dependency-stability == 'prefer-lowest'
run: composer update --prefer-stable --prefer-lowest

- name: Set up Git User
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"

# Code quality
- name: Execute tests (Unit and Feature tests) via PestPHP
shell: 'script -q -e -c "bash {0}"'
# Set environment
env:
SESSION_DRIVER: array
TTY: true

run: vendor/bin/pest

- name: Execute Code Sniffer via Laravel Pint
run: vendor/bin/pint --test src config
permissions:
contents: read

jobs:
laravel10-tests:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -138,7 +49,7 @@ jobs:
id: node_modules-cache
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}

- name: Install NPM packages
if: steps.node_modules-cache.outputs.cache-hit != 'true'
Expand All @@ -159,16 +70,16 @@ jobs:
id: actions-cache
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-composer-laravel-10-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
${{ runner.os }}-composer-laravel-10-${{ matrix.php }}-

- name: Cache PHP dependencies (vendor)
uses: actions/cache@v4
id: vendor-cache
with:
path: vendor
key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-build-laravel-10-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}

- name: Install Laravel Dependencies
if: steps.vendor-cache.outputs.cache-hit != 'true'
Expand Down Expand Up @@ -202,13 +113,22 @@ jobs:
- name: Execute Code Sniffer via Laravel Pint
run: vendor/bin/pint --test src config

- name: Execute PHP Stan
run: vendor/bin/phpstan

- name: Execute Rector
run: vendor/bin/rector --dry-run

- name: Execute PHP Insights
run: vendor/bin/phpinsights --no-interaction

laravel11-tests:
runs-on: ubuntu-latest

strategy:
matrix:
operating-system: [ ubuntu-latest ]
php: [ '8.2', '8.3' ]
php: [ '8.2', '8.3', '8.4' ]
dependency-stability: [ 'prefer-stable' ]

laravel: [ '11.*' ]
Expand All @@ -232,7 +152,7 @@ jobs:
id: node_modules-cache
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}

- name: Install NPM packages
if: steps.node_modules-cache.outputs.cache-hit != 'true'
Expand All @@ -253,16 +173,16 @@ jobs:
id: actions-cache
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-composer-laravel-11-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
${{ runner.os }}-composer-laravel-11-${{ matrix.php }}-

- name: Cache PHP dependencies (vendor)
uses: actions/cache@v4
id: vendor-cache
with:
path: vendor
key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-build-laravel-11-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}

- name: Install Laravel Dependencies
if: steps.vendor-cache.outputs.cache-hit != 'true'
Expand Down Expand Up @@ -296,3 +216,12 @@ jobs:
- name: Execute Code Sniffer via Laravel Pint
run: vendor/bin/pint --test src config

- name: Execute PHP Stan
run: vendor/bin/phpstan

- name: Execute Rector
run: vendor/bin/rector --dry-run

- name: Execute PHP Insights
run: vendor/bin/phpinsights --no-interaction

5 changes: 3 additions & 2 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
build:
image: default-jammy
environment:
node: v20
php:
version: 8.1
node: "v16.20.0"
version: 8.3.3
nodes:
analysis:
project_setup:
Expand Down
102 changes: 100 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@

## ✨ Features

- **Pre-configured Hooks:** Laravel Git Hooks comes with pre-configured pre-commit hooks for popular tools, such as Laravel Pint, PHPCS, ESLint, Prettier, Larastan, Enlightn, and Blade Formatter, making it easy to enforce coding standards and style guidelines right away.
- **Pre-configured Hooks:** Laravel Git Hooks comes with pre-configured pre-commit hooks for popular tools, such as Laravel Pint, PHPCS, ESLint, Prettier, Larastan, Enlightn, Rector, PHP Insights and Blade Formatter, making it easy to enforce coding standards and style guidelines right away.
- **Manage Git Hooks:** Easily manage your Git hooks in your Laravel projects with a streamlined and organized approach.
- **Edit Commit Messages:** Gain control over your commit messages by customizing them to meet your project requirements and maintain a clean Git history.
- **Create Custom Hooks:** Add and integrate custom hooks tailored to your specific project needs, ensuring better code quality and adherence to guidelines.
- **Artisan Command for Hook Generation:** The package includes a convenient Artisan command that allows you to effortlessly generate new hooks of various types. Such as: `pre-commit`, `prepare-commit-msg`, `commit-msg`, `post-commit`, `pre-push`
- **Code Quality:** The package is thoroughly tested, with 100% of code coverage, ensuring its reliability and stability in a wide range of Laravel projects.
- **Code Quality:** The package is thoroughly tested, with >95% of code coverage, ensuring its reliability and stability in a wide range of Laravel projects.
- **Docker support:** Each hook can be configured to either run locally or inside a docker container.

## 1️⃣ Installation

Expand Down Expand Up @@ -61,9 +62,106 @@ To use the already created pre-commit hooks of this package, you can simply edit
\Igorsgm\GitHooks\Console\Commands\Hooks\EnlightnPreCommitHook::class, // Enlightn
\Igorsgm\GitHooks\Console\Commands\Hooks\ESLintPreCommitHook::class, // ESLint
\Igorsgm\GitHooks\Console\Commands\Hooks\PrettierPreCommitHook::class, // Prettier
\Igorsgm\GitHooks\Console\Commands\Hooks\PhpInsightsPreCommitHook::class, // PhpInsights
\Igorsgm\GitHooks\Console\Commands\Hooks\RectorPreCommitHook::class, // Rector
],
```

By default the pre-commit hooks will stop at first failure and will not continue with the remaining tools.

If the tool contains a fixer option it will prompt in the CLI to run the fix command.

This behavior can be adjusted using the following parameters from git-hooks.php config file:
```php
/*
|--------------------------------------------------------------------------
| Automatically fix errors
|--------------------------------------------------------------------------
|
| This configuration option allows you to configure the git hooks to
| automatically run the fixer without any CLI prompt.
|
*/
'automatically_fix_errors' => false,

/*
|--------------------------------------------------------------------------
| Automatically re-run analyzer after autofix
|--------------------------------------------------------------------------
|
| This configuration option allows you to configure the git hooks to
| automatically re-run the analyzer command after autofix.
| The git hooks will not fail in case the re-run is succesful.
|
*/
'rerun_analyzer_after_autofix' => false,

/*
|--------------------------------------------------------------------------
| Stop at first analyzer failure
|--------------------------------------------------------------------------
|
| This configuration option allows you to configure the git hooks to
| stop (or not) at the first analyzer failure encountered.
|
*/
'stop_at_first_analyzer_failure' => true,
```

There are also several debug options which can be adjusted using the following parameters from git-hooks.php config file:

```php
/*
|--------------------------------------------------------------------------
| Output errors
|--------------------------------------------------------------------------
|
| This configuration option allows you output any errors encountered
| during execution directly for easy debug.
|
*/
'output_errors' => false,

/*
|--------------------------------------------------------------------------
| Debug commands
|--------------------------------------------------------------------------
|
| This configuration option allows you to configure the git hooks to
| display the commands that are executed (usually for debug purpose).
|
*/
'debug_commands' => false,

/*
|--------------------------------------------------------------------------
| Debug output
|--------------------------------------------------------------------------
|
| This configuration option allows you display the output of each
| command during execution directly for easy debug.
|
*/
'debug_output' => false,
```
### Laravel Sail support

If you are using Laravel Sail and maybe not lokal PHP is installed, you can adjust the following parameters in the git-hooks.php config file:

```php
'use_sail' => env('GITHOOKS_USE_SAIL', false),
```
This will force the local git hooks to use the `sail` command to execute the hooks.

### Docker support

By default commands are executed locally, however this behavior can be adjusted for each hook using the parameters `run_in_docker` and `docker_container`:

```php
'run_in_docker' => env('LARAVEL_PINT_RUN_IN_DOCKER', true),
'docker_container' => env('LARAVEL_PINT_DOCKER_CONTAINER', 'app'),
```

### Creating Custom Git Hooks
1) If you need to create a custom Git hook for your project, Laravel Git Hooks makes it easy with the `git-hooks:make` Artisan command. To create a new custom hook, simply run the following command:
```bash
Expand Down
Loading
Loading