Skip to content

Commit

Permalink
Merge pull request #24 from Sweetchuck/i23-composer-plugin
Browse files Browse the repository at this point in the history
composer plugin
  • Loading branch information
Sweetchuck authored Apr 13, 2020
2 parents 7848685 + 19d65be commit e80e167
Show file tree
Hide file tree
Showing 52 changed files with 3,514 additions and 1,371 deletions.
34 changes: 17 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,19 @@ commands:
restore_cache:
name: 'Composer - cache restore'
keys:
- 'composer-{{ checksum "./composer.lock" }}-1'
- 'composer-{{ checksum "./composer.lock" }}-2'

-
run:
name: 'Composer - install'
command: >
[[ -d "$(composer config vendor-dir)" ]] || composer install --no-progress
composer install --no-progress --ansi
-
save_cache:
name: 'Composer - cache save'
key: 'composer-{{ checksum "./composer.lock" }}-1'
key: 'composer-{{ checksum "./composer.lock" }}-2'
paths:
- './bin/'
- './vendor/'
- '~/.composer/cache/'


Expand All @@ -69,25 +67,27 @@ commands:
-
run:
name: 'Run linters'
command: 'bin/robo lint'
command: 'bin/robo --ansi lint'

test:
description: 'Run tests'
steps:
-
run:
name: 'Git config user.name and user.email'
command: |
git config --global user.name 'Circle CI'
git config --global user.email '[email protected]'
-
run:
name: 'Run Behat tests'
command: 'bin/robo test'
-
store_test_results:
name: 'Codeception - unit'
command: 'bin/robo --ansi test unit'
- codecov/upload:
flags: 'unit'
file: './tests/_output/machine/coverage/unit/coverage.xml'
- run:
name: 'Codeception - acceptance'
command: 'bin/robo --ansi test acceptance'
- codecov/upload:
flags: 'acceptance'
file: './tests/_output/machine/coverage/acceptance/coverage.xml'
- store_test_results:
name: 'Store unit test results'
path: './reports/machine/junit'
path: './tests/_output/machine/junit'

jobs:
build:
Expand Down
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.feature]
indent_size = 2
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@

/bin/
/fixtures/project-template/*/vendor/

/reports/

/tests/_data/fixtures/project-template/*/vendor/
/tests/_output/
/tests/_support/_generated/
/tests/*.suite.yml

/vendor/

/.git-hooks-local
/codeception.yml
/phpcs.xml
/sweetchuck-git-hooks-*.tar
/sweetchuck-git-hooks-*.zip
84 changes: 41 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,87 +19,90 @@ teammates then this is the tool you are looking for.

1. Step into you existing package's directory (or create a new one with `git
init && composer init`)
2. Run `composer require 'sweetchuck/git-hooks'`
2. Run `composer require --dev 'sweetchuck/git-hooks'`
3. Then you have two option
1. Relay on the git hooks scripts which are shipped with this packag and
1. Relay on Git hooks scripts which are shipped with this package and
implement the logic in your `./.git-hooks` file.
2. Or create a `./git-hooks` directory and create Git hook files in it. (eg:
`./git-hooks/pre-commit`)
4. The deployment script will be automatically triggered by the
`post-install-cmd` Composer event.


## Example composer.json

```JSON
{
"require": {
"sweetchuck/git-hooks": "dev-master"
},
"scripts": {
"post-install-cmd": [
"\\Sweetchuck\\GitHooks\\Composer\\Scripts::postInstallCmd"
]
}
}
```


## Configuration

Example composer.json file:
```json
{
"extra": {
"sweetchuck/git-hooks": {
"core.hooksPath": "git-hooks",
"symlink": false
"core.hooksPath": "./git-hooks",
"symlink": true
}
}
}
```


### Configuration - symlink
### Configuration - core.hooksPath

Type: boolean
Type: string

Default value: false
Default value: `vendor/sweetchuck/git-hooks/git-hooks` (dynamically detected)

Copy or symlink Git hook files from the original location to the `./.git/hooks`.
If the Git version is >= v2.9 then this value will be used to set `git config
core.hooksPath <FOO>`. If Git is older than 2.9 then the content of this
directory will be symbolically linked or copied to `./.git/hooks` directory.


### Configuration - core.hooksPath
### Configuration - symlink

Type: string
Type: boolean

Default value: git-hooks
Default value: `false`

When this option is not empty then it allows to use the new feature of the Git
v2.9
This configuration option will be used only if Git version is older than v2.9.
Copy or symlink Git hook files from the original location (provided by the
`core.hooksPath` configuration) to the `./.git/hooks`.


## Example ./.git-hooks file

The file below runs a Robo command corresponding the name of the current Git
hook.
If you use the Git hooks script from this package
(`vendor/sweetchuck/git-hooks/git-hooks`) you will need custom script which
catches Git hooks add triggers something really useful.

Copy the content below into `./.git-hooks`
```bash
#!/usr/bin/env bash

# @todo Better detection for executables: php, composer.phar and robo.
robo="$(composer config 'bin-dir')/robo"
echo "BEGIN Git hook: ${sghHookName}"

function sghExit ()
{
echo "END Git hook: ${sghHookName}"

exit $1
}

# @todo Better detection for executables: php, composer.phar.
sghRobo="$(composer config 'bin-dir')/robo"

test -s "${sghBridge}.local" && . "${sghBridge}.local"

sghTask="githook:${sghHookName}"

# Exit without error if "robo" doesn't exists or it has no corresponding task.
test -x "$robo" || exit 0
"$robo" help "githook:$sghHookName" 1> /dev/null 2>&1 || exit 0
test -x "$sghRobo" || sghExit 0
"${sghRobo}" help "${sghTask}" 1> /dev/null 2>&1 || sghExit 0

if [ "$sghHasInput" = 'true' ]; then
"$robo" "githook:$sghHookName" $@ <<< $(</dev/stdin) || exit $?
"$sghRobo" "${sghTask}" $@ <<< $(</dev/stdin) || sghExit $?
else
"$robo" "githook:$sghHookName" $@ || exit $?
"$sghRobo" "${sghTask}" $@ || sghExit $?
fi

exit 0
sghExit 0
```


Expand All @@ -124,8 +127,3 @@ class RoboFile extends \Robo\Tasks
}
}
```


## Links

* https://robo.li/
Loading

0 comments on commit e80e167

Please sign in to comment.