Skip to content

Commit 11a13e2

Browse files
authored
Merge pull request #16 from sansecio/phar
create phar release when tag is made
2 parents 8274e87 + 6a7381d commit 11a13e2

File tree

7 files changed

+134
-49
lines changed

7 files changed

+134
-49
lines changed

.github/workflows/release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Setup PHP
14+
uses: shivammathur/setup-php@v2
15+
with:
16+
php-version: '8.1'
17+
18+
- name: Checkout Repository
19+
uses: actions/checkout@v3
20+
21+
- name: Install Dependencies
22+
run: composer install
23+
24+
- name: Install Box
25+
run: composer global require humbug/box
26+
27+
- name: Create PHAR
28+
run: box compile
29+
30+
- name: Create Release
31+
uses: ncipollo/release-action@v1
32+
with:
33+
artifacts: composer-integrity.phar
34+
artifactContentType: application/x-php

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.idea
22
/vendor
33
/test/vendor
4-
/test/composer.lock
4+
/test/composer.lock
5+
/composer-integrity.phar

box.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"main": "composer-integrity.php"
3+
}

composer-integrity.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use DI\Container;
4+
use Sansec\Integrity\IntegrityCommand;
5+
use Sansec\Integrity\PackageResolver\LockReaderStrategy;
6+
use Symfony\Component\Console\Application;
7+
8+
require_once 'vendor/autoload.php';
9+
10+
$container = new Container();
11+
12+
$application = $container->get(Application::class);
13+
$application->add($container->make(IntegrityCommand::class, [
14+
'packageResolverStrategy' => $container->make(
15+
LockReaderStrategy::class,
16+
['rootDirectory' => \getcwd()]
17+
)
18+
]));
19+
$application->setDefaultCommand('integrity');
20+
$application->run();

src/CommandProvider.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Composer\Composer;
66
use DI\Container;
7+
use Sansec\Integrity\PackageResolver\ComposerStrategy;
78

89
class CommandProvider implements \Composer\Plugin\Capability\CommandProvider
910
{
@@ -19,7 +20,16 @@ public function __construct(array $config)
1920
public function getCommands()
2021
{
2122
return [
22-
$this->container->make(IntegrityCommand::class, ['composer' => $this->composer])
23+
$this->container->make(
24+
ComposerIntegrityCommand::class,
25+
[
26+
'composer' => $this->composer,
27+
'packageResolverStrategy' => $this->container->make(
28+
ComposerStrategy::class,
29+
['composer' => $this->composer]
30+
)
31+
]
32+
)
2333
];
2434
}
2535
}

src/ComposerIntegrityCommand.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Sansec\Integrity;
4+
5+
use Composer\Composer;
6+
use DI\Container;
7+
8+
class ComposerIntegrityCommand extends IntegrityCommand
9+
{
10+
private ?PatchDetector $patchDetector = null;
11+
12+
public function __construct(
13+
private readonly Container $container,
14+
private readonly PackageResolverStrategy $packageResolverStrategy,
15+
private readonly Composer $composer,
16+
string $name = null
17+
) {
18+
parent::__construct($container, $packageResolverStrategy, $name);
19+
}
20+
21+
private function getPatchDetector(): PatchDetector
22+
{
23+
if ($this->patchDetector === null) {
24+
$this->patchDetector = $this->container->make(
25+
PatchDetector::class,
26+
[
27+
'composer' => $this->composer,
28+
// We must use a getter because the application object is not known to us during construction
29+
'application' => $this->getApplication()
30+
]
31+
);
32+
}
33+
return $this->patchDetector;
34+
}
35+
36+
protected function getRendererOptions(bool $json): array
37+
{
38+
$options = parent::getRendererOptions($json);
39+
40+
if (!$this->getPatchDetector()->hasPatchPlugin()) {
41+
return $options;
42+
}
43+
44+
$options['additionalColumns'] = ['Patched'];
45+
$options['verdictEnricher'] = new class($options['json'], $this->getPatchDetector()->getPatchedPackages()) implements VerdictEnricher
46+
{
47+
public function __construct(private readonly bool $json, private readonly array $patchedPackages)
48+
{
49+
}
50+
51+
public function enrich(PackageVerdict $packageVerdict): array
52+
{
53+
$patchApplied = in_array($packageVerdict->name, $this->patchedPackages);
54+
return ['patch_applied' => $this->json ? $patchApplied : ($patchApplied ? 'Yes' : 'No')];
55+
}
56+
};
57+
58+
return $options;
59+
}
60+
}

src/IntegrityCommand.php

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
namespace Sansec\Integrity;
44

55
use Composer\Command\BaseCommand;
6-
use Composer\Composer;
76
use DI\Container;
8-
use Sansec\Integrity\PackageResolver\ComposerStrategy;
97
use Symfony\Component\Console\Command\Command;
108
use Symfony\Component\Console\Input\InputInterface;
119
use Symfony\Component\Console\Input\InputOption;
@@ -17,11 +15,10 @@ class IntegrityCommand extends BaseCommand
1715
private const OPTION_NAME_JSON = 'json';
1816

1917
private ?PackageSubmitter $packageSubmitter = null;
20-
private ?PatchDetector $patchDetector = null;
2118

2219
public function __construct(
2320
private readonly Container $container,
24-
private readonly Composer $composer,
21+
private readonly PackageResolverStrategy $packageResolverStrategy,
2522
string $name = null
2623
) {
2724
parent::__construct($name);
@@ -41,32 +38,12 @@ private function getPackageSubmitter(): PackageSubmitter
4138
if ($this->packageSubmitter === null) {
4239
$this->packageSubmitter = $this->container->make(
4340
PackageSubmitter::class,
44-
[
45-
'packageResolverStrategy' => $this->container->make(
46-
ComposerStrategy::class,
47-
['composer' => $this->composer]
48-
)
49-
]
41+
['packageResolverStrategy' => $this->packageResolverStrategy]
5042
);
5143
}
5244
return $this->packageSubmitter;
5345
}
5446

55-
private function getPatchDetector(): PatchDetector
56-
{
57-
// We must use a getter because the application object is not known to us during construction
58-
if ($this->patchDetector === null) {
59-
$this->patchDetector = $this->container->make(
60-
PatchDetector::class,
61-
[
62-
'composer' => $this->composer,
63-
'application' => $this->getApplication()
64-
]
65-
);
66-
}
67-
return $this->patchDetector;
68-
}
69-
7047
private function hasMismatchingVerdicts(array $verdicts): bool
7148
{
7249
return count(array_filter($verdicts, fn (PackageVerdict $verdict) => $verdict->verdict == 'mismatch')) > 0;
@@ -78,29 +55,9 @@ private function filterMatchVerdicts(array $verdicts): array
7855
return array_filter($verdicts, fn (PackageVerdict $verdict) => $verdict->verdict != 'match');
7956
}
8057

81-
private function getRendererOptions(bool $json): array
58+
protected function getRendererOptions(bool $json): array
8259
{
83-
$hasPatchPlugin = $this->getPatchDetector()->hasPatchPlugin();
84-
$patchedPackages = $this->getPatchDetector()->getPatchedPackages();
85-
86-
$options = ['json' => $json];
87-
if ($hasPatchPlugin) {
88-
$options['additionalColumns'] = ['Patched'];
89-
$options['verdictEnricher'] = new class($options['json'], $patchedPackages) implements VerdictEnricher
90-
{
91-
public function __construct(private readonly bool $json, private readonly array $patchedPackages)
92-
{
93-
}
94-
95-
public function enrich(PackageVerdict $packageVerdict): array
96-
{
97-
$patchApplied = in_array($packageVerdict->name, $this->patchedPackages);
98-
return ['patch_applied' => $this->json ? $patchApplied : ($patchApplied ? 'Yes' : 'No')];
99-
}
100-
};
101-
}
102-
103-
return $options;
60+
return ['json' => $json];
10461
}
10562

10663
protected function execute(InputInterface $input, OutputInterface $output)

0 commit comments

Comments
 (0)