Skip to content

Commit

Permalink
Merge pull request #26 from youwe-petervanderwal/feat/git-hook-via-ddev
Browse files Browse the repository at this point in the history
feat: execute Git hook within DDev
  • Loading branch information
youwe-petervanderwal committed Mar 22, 2024
2 parents df7693a + 4dd7444 commit d1ca0f9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.18
### Added
- Grumphp will run the git hook in DDev (if available)

## 2.17.1
### Added
- Added `ignore_patterns` support to allow project configurations to make use of this field through
Expand Down
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,37 @@ The testing suite can be run manually through the GrumPHP command.
```
vendor/bin/grumphp run
```
or for DDev projects
```
ddev exec vendor/bin/grumphp run
```

### Git commit hook

The testing suite is also automatically run at each git commit using a git
The testing suite is automatically run at each git commit using a git
commit hook.

This git commit hook will automatically detect DDev projects and will
run GrumPHP within the DDev container if needed. This behaviour can
be disabled:

- on individual basis via an environment variable:
```
YOUWE_BYPASS_DDEV=1 git commit
```
- on project basis via the `grumphp.yml` configuration file:
```
imports:
- resource: 'vendor/youwe/testing-suite/config/your-project-type/grumphp.yml'
grumphp:
git_hook_variables:
# Disable DDev detection by restoring to default `exec`
# See https://github.com/phpro/grumphp/blob/v2.x/doc/parameters.md for more options
EXEC_GRUMPHP_COMMAND: exec
```
After changing your `grumphp.yml`, run `vendor/bin/grumphp git:init` to update the git commit hook.

### CI/CD Integration examples

- [Bitbucket Pipelines](docs/examples/bitbucket-pipelines.md)
Expand Down
19 changes: 19 additions & 0 deletions bin/youwe-container-detected-exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -euo pipefail

if [ -z "${IS_DDEV_PROJECT-}" ] \
&& [ -z "${YOUWE_BYPASS_DDEV-}" ] \
&& [ -f .ddev/config.yaml ] \
&& which ddev >/dev/null
then
# - We're not already running within DDev (in that case $IS_DDEV_PROJECT equals true)
# - The YOUWE_BYPASS_DDEV flag isn't set by the user
# - We found the .ddev/config.yaml file, indicating this project runs in DDev
# - We found the DDev binary, indicating we're not on a build server
ddev exec "$@"
exit $?
fi

exec "$@"
exit $?
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"sensiolabs/security-checker": "*"
},
"bin": [
"bin/youwe-container-detected-exec",
"bin/youwe-testing-suite"
],
"extra": {
Expand Down
3 changes: 3 additions & 0 deletions config/default/grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ grumphp:
failed: ~
succeeded: ~

git_hook_variables:
EXEC_GRUMPHP_COMMAND: vendor/bin/youwe-container-detected-exec

parallel:
enabled: true

Expand Down

0 comments on commit d1ca0f9

Please sign in to comment.