Skip to content

Commit 3efecef

Browse files
committed
Merge branch '2.x' for 2.3.0 release
2 parents 4d6a5b9 + be857b5 commit 3efecef

File tree

74 files changed

+2324
-695
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2324
-695
lines changed

.github/workflows/code-analysis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ jobs:
3333
restore-keys: ${{ runner.os }}-composer-
3434

3535
- name: Install dependencies
36-
run: |
37-
composer install --prefer-dist --no-progress
38-
chmod -R +x tools/*
36+
run: composer install --prefer-dist --no-progress
3937

4038
- name: Execute PhpStan
4139
run: php githooks tool phpstan

.github/workflows/main-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
php-version: ${{ matrix.php-versions }}
2929
extensions: ${{ env.extensions }} #optional
30-
tools: phpcs, phpcbf, phpmd, phpstan
30+
tools: phpcs, phpcbf, phpmd, phpstan:1.4
3131
ini-values: "post_max_size=256M" #optional
3232
coverage: none
3333

.github/workflows/release.yml

Lines changed: 76 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,25 @@ jobs:
4949
echo $version
5050
php githooks app:build --build-version=${version}
5151
52-
- uses: actions/upload-artifact@master
52+
- name: 'Tar files to keep permissions'
53+
run: |
54+
tar -cvf githooks-71.tar builds/php7.1/githooks
55+
tar -cvf githooks-73.tar builds/githooks
56+
ls -lah builds/githooks builds/php7.1/githooks
57+
58+
- name: Upload php 7.1 build
59+
uses: actions/upload-artifact@master
5360
if: ${{ '7.1' == matrix.php-versions }}
5461
with:
5562
name: githooks-71
56-
path: builds/php7.1/githooks
63+
path: githooks-71.tar
5764

58-
- uses: actions/upload-artifact@master
65+
- name: Upload php 7.3 build
66+
uses: actions/upload-artifact@master
5967
if: ${{ '7.3' == matrix.php-versions }}
6068
with:
6169
name: githooks-73
62-
path: builds/githooks
70+
path: githooks-73.tar
6371

6472
test_rc:
6573
name: Test the Build in php ${{ matrix.php-versions }}
@@ -100,19 +108,22 @@ jobs:
100108
chmod -R +x tools/*
101109
102110
- name: Delete Old Builds
103-
run: rm builds/githooks builds/php7.1/githooks
111+
run: rm builds/githooks builds/php7.1/githooks && echo ${{ secrets.PAT_TOKEN_TO_COMMIT }}
104112

105-
- uses: actions/download-artifact@master
106-
if: ${{ '7.2' == matrix.php-versions }}
113+
- uses: actions/download-artifact@v3
107114
with:
108115
name: githooks-71
109-
path: 'builds/php7.1'
110116

111117
- uses: actions/download-artifact@master
112-
if: ${{ '8.1' == matrix.php-versions }}
113118
with:
114119
name: githooks-73
115-
path: builds
120+
121+
- name: Extract and check builds
122+
run: |
123+
tar -xf githooks-71.tar
124+
tar -xf githooks-73.tar
125+
ls -lah builds
126+
git status
116127
117128
- name: Testing the Aplication
118129
run: |
@@ -121,59 +132,58 @@ jobs:
121132
vendor/bin/phpunit --group release
122133
shell: bash
123134

124-
# commit_rc:
125-
# name: Commit the Build
126-
# needs: test_rc
127-
# runs-on: ubuntu-latest
128-
# steps:
129-
# - name: Checkout
130-
# uses: actions/checkout@v2
131-
# token: ''
132-
133-
# - name: Delete Old Builds
134-
# run: rm builds/githooks builds/php7.1/githooks
135-
136-
# - uses: actions/download-artifact@master
137-
# with:
138-
# name: githooks-71
139-
# path: 'builds/php7.1'
140-
141-
# - uses: actions/download-artifact@master
142-
# with:
143-
# name: githooks-73
144-
# path: builds
145-
146-
# - name: Make Changes
147-
# uses: DamianReeves/write-file-action
148-
# with:
149-
# path: README.md
150-
# contents: |
151-
# echo "Hello World!"
152-
# write-mode: append
153-
154-
# - name: Make Changes
155-
# run: ls && echo 'Nueva fila' >> README.md
156-
157-
# - name: Check Changes
158-
# run: git status
159-
160-
# - name: Get Time
161-
# id: time
162-
# uses: nanzm/get-time-action@v1.1
163-
# with:
164-
# # timeZone: 8
165-
# format: 'DD-MM-YYYY HH-mm-ss'
166-
167-
# - name: Commit the new RC
168-
# uses: EndBug/add-and-commit@v7
169-
# env:
170-
# TIME: "${{ steps.time.outputs.time }}"
171-
# with:
172-
# # add: 'builds/*'
173-
# add: '*'
174-
# default_author: github_actions # github_actor -> UserName <UserName@users.noreply.github.com> || user_info -> Your Display Name <your-actual@email.com>
175-
# message: 'RC ${{ env.version }} - ${{ env.TIME }}'
176-
# push: false
177-
178-
# - name: Git Log
179-
# run: git log
135+
commit_rc:
136+
name: Commit the Build
137+
needs: test_rc
138+
runs-on: ubuntu-latest
139+
permissions:
140+
contents: write
141+
steps:
142+
- name: Checkout
143+
uses: actions/checkout@v3
144+
145+
- name: Delete Old Builds
146+
run: rm builds/githooks builds/php7.1/githooks && echo ${{ secrets.PAT_TOKEN_TO_COMMIT }}
147+
148+
- uses: actions/download-artifact@v3
149+
with:
150+
name: githooks-71
151+
152+
- uses: actions/download-artifact@master
153+
with:
154+
name: githooks-73
155+
156+
- name: Extract and check builds
157+
run: |
158+
tar -xf githooks-71.tar
159+
tar -xf githooks-73.tar
160+
ls -lah builds
161+
git status
162+
163+
- name: Get Time
164+
id: time
165+
uses: nanzm/get-time-action@v1.1
166+
with:
167+
timeZone: 1
168+
format: 'DD-MM-YYYY HH:mm:ss'
169+
170+
- name: Extract version
171+
id: version_id
172+
run: |
173+
branch=${GITHUB_REF##*/}
174+
echo ${branch}
175+
prefix='rc-'
176+
version=${branch#"$prefix"}
177+
echo $version
178+
echo "::set-output name=version::${version}"
179+
180+
- name: Check Version
181+
run: echo ${{ steps.version_id.outputs.version }} && echo ${{ steps.time.outputs.time }}
182+
183+
- uses: GuillaumeFalourd/git-commit-push@v1.3
184+
with:
185+
files: builds/githooks builds/php7.1/githooks
186+
commit_message: 'Release Candidate: ${{ steps.version_id.outputs.version }} - Build: ${{ steps.time.outputs.time }}'
187+
188+
- name: Git Log
189+
run: git log

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ testsDir/src
2929
testsDir/app
3030
testsDir/vendor
3131
testsDir/*.yml
32-
githooks.yml
32+
/githooks.yml
3333

3434
tools/tmp/
3535

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ Then run `composer update wtyd/githooks`.
5151

5252
5. [Set the configuration file](#Set-the-configuration-file).
5353

54-
5554
# Usage
5655
When you commit, all the configured code check tools are automatically launched. If your code pass all checks, GitHooks allows you to commit. If not, you have to fix the code and try again:
5756
<p>
@@ -85,14 +84,18 @@ But you can set your [own script](https://github.com/Wtyd/githooks/wiki/Console%
8584
The `githooks.yml` file is splitted on three parts:
8685

8786
## Options
88-
Actually the only option is `execution`. This flag marks how GitHooks will run:
87+
### Execution
88+
The `execution` flag marks how GitHooks will run:
8989
* `full` (the default option): executes always all tools setted against all path setted for each tool.
9090
For example, you setted phpcs for run in `src` and `app` directories. The commit only contains modified files from `database` directory. Phpcs will check `src` and `app` directories even if no files in these directories have been modified.
9191
* `fast`: this option runs the tools only against files modified by commit.
9292
* This option only affects the following tools: phpcs, phpmd, phpstan, and parallel-lint. The rest of the tools will run as the full option.
93-
* **WARNING!!!** You must set the excludes of the tools either in githooks.yml or in the configuration file of eath tool since this
93+
* **WARNING!!!** You must set the excludes of the tools either in `githooks.yml` or in the configuration file of eath tool since this
9494
option overwrites the key `paths` of the tools so that they are executed only against the modified files.
9595

96+
### Processes
97+
Run multiple tools in multiple processes at same time (`tool all` command). The default number of processes is 1.
98+
9699
## Tools
97100
It is an array with the name of the tools that GitHooks will run. The name of the tools is their executable. If you want all the tools to be executed, the `Tools` key will be as follows:
98101
```yml

app-

Whitespace-only changes.

app/Commands/ExecuteToolCommand.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@
33
namespace Wtyd\GitHooks\App\Commands;
44

55
use Wtyd\GitHooks\App\Commands\ToolCommand as BaseCommand;
6+
use Wtyd\GitHooks\ConfigurationFile\CliArguments;
67
use Wtyd\GitHooks\ConfigurationFile\Exception\ConfigurationFileInterface;
78
use Wtyd\GitHooks\ConfigurationFile\Exception\ConfigurationFileNotFoundException;
89
use Wtyd\GitHooks\ConfigurationFile\Exception\ToolIsNotSupportedException;
9-
use Wtyd\GitHooks\ConfigurationFile\Exception\WrongExecutionValueException;
10+
use Wtyd\GitHooks\ConfigurationFile\Exception\WrongOptionsValueException;
1011
use Wtyd\GitHooks\Tools\Errors;
1112

1213
class ExecuteToolCommand extends BaseCommand
1314
{
14-
protected $signature = 'tool {tool : Tool will be run} {execution? : Override the execution mode of githooks.yml. Values: "fast" and "full"}';
15-
protected $description = 'Run the tool passed as argument. It must be a supported tool by GitHooks. ';
15+
protected $signature = 'tool
16+
{tool : Tool will be run}
17+
{execution? : Override the execution mode of githooks.yml. Values: "fast" and "full"}
18+
{--ignoreErrorsOnExit= : Avoids exit error even if the tool finds some trobule. When tool is \'all\' applies for all tools}
19+
{--otherArguments= : Other tool options not supported by GitHooks}
20+
{--executablePath= : Path to executable}
21+
{--paths= : Paths or files against the tool will be executed}
22+
{--processes= : Number of parallel processes in which the tools will be executed}';
23+
24+
protected $description = 'Run the tool passed as argument. It must be a supported tool by GitHooks. the available options depend on the tool passed as parameter';
1625

1726
public function handle()
1827
{
@@ -21,15 +30,26 @@ public function handle()
2130
$execution = strval($this->argument('execution'));
2231

2332
try {
24-
$tools = $this->toolsPreparer->__invoke($tool, $execution);
33+
$configurationFile = $this->readConfigurationFileAction
34+
->__invoke(new CliArguments(
35+
$tool,
36+
$execution,
37+
$this->option('ignoreErrorsOnExit'),
38+
strval($this->option('otherArguments')),
39+
strval($this->option('executablePath')),
40+
strval($this->option('paths')),
41+
intval($this->option('processes'))
42+
));
43+
44+
$tools = $this->toolsPreparer->__invoke($configurationFile);
2545

26-
$withLiveOutput = $tool === 'all' ? false : true;
46+
$processesExecution = $this->processExecutionFactory->create($tool);
2747

28-
$errors = $this->toolExecutor->__invoke($tools, $withLiveOutput);
48+
$errors = $processesExecution->execute($tools, $configurationFile->getProcesses());
2949
} catch (ToolIsNotSupportedException $exception) {
3050
$this->error($exception->getMessage());
3151
$errors->setError($tool, $exception->getMessage());
32-
} catch (WrongExecutionValueException $exception) {
52+
} catch (WrongOptionsValueException $exception) {
3353
$this->error($exception->getMessage());
3454
$errors->setError($tool, $exception->getMessage());
3555
} catch (ConfigurationFileNotFoundException $exception) {
@@ -47,6 +67,7 @@ public function handle()
4767
$this->warn($warning);
4868
}
4969
}
70+
5071
foreach ($this->toolsPreparer->getConfigurationFileWarnings() as $warning) {
5172
$this->warn($warning);
5273
}

app/Commands/ToolCommand.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,31 @@
33
namespace Wtyd\GitHooks\App\Commands;
44

55
use Wtyd\GitHooks\Tools\Errors;
6-
use Wtyd\GitHooks\Tools\ToolExecutor;
76
use Wtyd\GitHooks\Tools\ToolsPreparer;
87
use LaravelZero\Framework\Commands\Command;
8+
use Wtyd\GitHooks\ConfigurationFile\ReadConfigurationFileAction;
9+
use Wtyd\GitHooks\Tools\Execution\ProcessExecutionFactory;
10+
use Wtyd\GitHooks\Tools\Execution\ProcessExecutionFactoryAbstract;
911

1012
abstract class ToolCommand extends Command
1113
{
12-
/**
13-
* @var ToolsPreparer
14-
*/
14+
/** @var ReadConfigurationFileAction */
15+
protected $readConfigurationFileAction;
16+
17+
/** @var ToolsPreparer */
1518
protected $toolsPreparer;
1619

17-
/**
18-
* @var ToolExecutor
19-
*/
20-
protected $toolExecutor;
20+
/** @var ProcessExecutionFactoryAbstract */
21+
protected $processExecutionFactory;
2122

22-
public function __construct(ToolsPreparer $toolsPreparer, ToolExecutor $toolExecutor)
23-
{
23+
public function __construct(
24+
ReadConfigurationFileAction $readConfigurationFileAction,
25+
ToolsPreparer $toolsPreparer,
26+
ProcessExecutionFactoryAbstract $processExecutionFactory
27+
) {
28+
$this->readConfigurationFileAction = $readConfigurationFileAction;
2429
$this->toolsPreparer = $toolsPreparer;
25-
$this->toolExecutor = $toolExecutor;
30+
$this->processExecutionFactory = $processExecutionFactory;
2631
parent::__construct();
2732
}
2833

app/Providers/AppServiceProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Tests\Utils\FileReaderFake;
88
use Wtyd\GitHooks\ConfigurationFile\FileReader;
99
use Wtyd\GitHooks\Container\RegisterBindings;
10+
use Wtyd\GitHooks\Tools\Execution\ProcessExecutionFactoryAbstract;
11+
use Wtyd\GitHooks\Tools\Execution\ProcessExecutionFactoryFake;
1012
use Wtyd\GitHooks\Tools\Tool\SecurityChecker;
1113

1214
class AppServiceProvider extends ServiceProvider
@@ -49,6 +51,7 @@ protected function testsRegister(): void
4951
if (defined('APP_ENV') && APP_ENV === 'testing') {
5052
$this->app->singleton(FileReader::class, FileReaderFake::class);
5153
$this->app->singleton(SecurityChecker::class, SecurityCheckerFake::class);
54+
$this->app->singleton(ProcessExecutionFactoryAbstract::class, ProcessExecutionFactoryFake::class);
5255
}
5356
}
5457
}

builds/githooks

-1.52 MB
Binary file not shown.

0 commit comments

Comments
 (0)