Skip to content

Commit 316285b

Browse files
authored
Merge pull request #371 from Roave/feature/#342-support-github-output-format
#342 implemented GitHub Actions output format
2 parents 8c859ae + aad5f2f commit 316285b

25 files changed

+536
-50
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
run: "composer install --no-interaction --no-progress --no-suggest"
8484

8585
- name: "Roave Backward Compatibility Check"
86-
run: "bin/roave-backward-compatibility-check"
86+
run: "bin/roave-backward-compatibility-check --format=github-actions"
8787

8888
check-composer-dependencies:
8989
name: "Composer Require Checker"

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ To generate additional documentation for changelogs:
101101
vendor/bin/roave-backward-compatibility-check --format=markdown > results.md
102102
```
103103

104+
### GitHub Actions
105+
106+
When running in GitHub Actions, it is endorsed to use the `--format=github-actions` output format:
107+
108+
```bash
109+
vendor/bin/roave-backward-compatibility-check --format=github-actions
110+
```
111+
104112
### Documentation
105113

106114
If you need further guidance:

src/Change.php

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@ final class Change
1515
private const REMOVED = 'removed';
1616
private const SKIPPED = 'skipped';
1717

18-
/** @psalm-var self::* */
19-
private string $modificationType;
20-
21-
private string $description;
22-
23-
private bool $isBcBreak;
24-
2518
/** @psalm-param self::* $modificationType */
26-
private function __construct(string $modificationType, string $description, bool $isBcBreak)
27-
{
28-
$this->modificationType = $modificationType;
29-
$this->description = $description;
30-
$this->isBcBreak = $isBcBreak;
19+
private function __construct(
20+
private string $modificationType,
21+
public string $description,
22+
private bool $isBcBreak,
23+
public ?string $file = null,
24+
public ?int $line = null,
25+
public ?int $column = null
26+
) {
3127
}
3228

3329
/** @psalm-pure */
@@ -75,6 +71,48 @@ public function isSkipped(): bool
7571
return $this->modificationType === self::SKIPPED;
7672
}
7773

74+
/** @internal */
75+
public function withFilePositionsIfNotAlreadySet(
76+
?string $file,
77+
int $line,
78+
?int $column
79+
): self {
80+
$instance = clone $this;
81+
82+
$instance->file ??= $file;
83+
$instance->line ??= $line;
84+
$instance->column ??= $column;
85+
86+
return $instance;
87+
}
88+
89+
public function onFile(?string $file): self
90+
{
91+
$instance = clone $this;
92+
93+
$instance->file = $file;
94+
95+
return $instance;
96+
}
97+
98+
public function onLine(int $line): self
99+
{
100+
$instance = clone $this;
101+
102+
$instance->line = $line;
103+
104+
return $instance;
105+
}
106+
107+
public function onColumn(?int $column): self
108+
{
109+
$instance = clone $this;
110+
111+
$instance->column = $column;
112+
113+
return $instance;
114+
}
115+
78116
public function __toString(): string
79117
{
80118
return Str\format(

src/Command/AssertBackwardsCompatible.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Roave\BackwardCompatibility\Changes;
1313
use Roave\BackwardCompatibility\CompareApi;
1414
use Roave\BackwardCompatibility\Factory\ComposerInstallationReflectorFactory;
15+
use Roave\BackwardCompatibility\Formatter\GithubActionsFormatter;
1516
use Roave\BackwardCompatibility\Formatter\MarkdownPipedToSymfonyConsoleFormatter;
1617
use Roave\BackwardCompatibility\Formatter\SymfonyConsoleTextFormatter;
1718
use Roave\BackwardCompatibility\Git\CheckedOutRepository;
@@ -94,7 +95,8 @@ protected function configure(): void
9495
'format',
9596
null,
9697
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
97-
'Currently only supports "markdown"'
98+
'Currently supports "console", "markdown" or "github-actions"',
99+
['console']
98100
)
99101
->addOption(
100102
'install-development-dependencies',
@@ -174,12 +176,20 @@ public function execute(InputInterface $input, OutputInterface $output): int
174176
)
175177
);
176178

177-
(new SymfonyConsoleTextFormatter($stdErr))->write($changes);
178-
179-
$outputFormats = Type\vec(Type\string())->coerce($input->getOption('format') ?: []);
180-
181-
if (Iter\contains($outputFormats, 'markdown')) {
182-
(new MarkdownPipedToSymfonyConsoleFormatter($output))->write($changes);
179+
$formatters = [
180+
'console' => new SymfonyConsoleTextFormatter($stdErr),
181+
'markdown' => new MarkdownPipedToSymfonyConsoleFormatter($output),
182+
'github-actions' => new GithubActionsFormatter($output, $toPath),
183+
];
184+
185+
foreach (
186+
Type\vec(Type\union(
187+
Type\literal_scalar('console'),
188+
Type\literal_scalar('markdown'),
189+
Type\literal_scalar('github-actions'),
190+
))->coerce((array) $input->getOption('format')) as $format
191+
) {
192+
$formatters[$format]->write($changes);
183193
}
184194
} finally {
185195
$this->git->remove($fromPath);

src/DetectChanges/BCBreak/ClassBased/MultipleChecksOnAClass.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Roave\BackwardCompatibility\Change;
88
use Roave\BackwardCompatibility\Changes;
9+
use Roave\BackwardCompatibility\Formatter\SymbolStartColumn;
910
use Roave\BetterReflection\Reflection\ReflectionClass;
1011

1112
final class MultipleChecksOnAClass implements ClassBased
@@ -26,8 +27,16 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass):
2627
/** @return iterable<int, Change> */
2728
private function multipleChecks(ReflectionClass $fromClass, ReflectionClass $toClass): iterable
2829
{
30+
$toFile = $toClass->getFileName();
31+
$toLine = $toClass->getStartLine();
32+
$toColumn = SymbolStartColumn::get($toClass);
33+
2934
foreach ($this->checks as $check) {
30-
yield from $check($fromClass, $toClass);
35+
foreach ($check($fromClass, $toClass) as $change) {
36+
// Note: this approach allows us to quickly add file/line/column to each change, but in future,
37+
// we will need to push this concern into each checker instead.
38+
yield $change->withFilePositionsIfNotAlreadySet($toFile, $toLine, $toColumn);
39+
}
3140
}
3241
}
3342
}

src/DetectChanges/BCBreak/ClassConstantBased/MultipleChecksOnAClassConstant.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Roave\BackwardCompatibility\Change;
88
use Roave\BackwardCompatibility\Changes;
9+
use Roave\BackwardCompatibility\Formatter\SymbolStartColumn;
910
use Roave\BetterReflection\Reflection\ReflectionClassConstant;
1011

1112
final class MultipleChecksOnAClassConstant implements ClassConstantBased
@@ -20,14 +21,23 @@ public function __construct(ClassConstantBased ...$checks)
2021

2122
public function __invoke(ReflectionClassConstant $fromConstant, ReflectionClassConstant $toConstant): Changes
2223
{
23-
return Changes::fromIterator($this->multipleChecks($fromConstant, $fromConstant));
24+
return Changes::fromIterator($this->multipleChecks($fromConstant, $toConstant));
2425
}
2526

2627
/** @return iterable<int, Change> */
2728
private function multipleChecks(ReflectionClassConstant $fromConstant, ReflectionClassConstant $toConstant): iterable
2829
{
30+
$toLine = $toConstant->getStartLine();
31+
$toColumn = SymbolStartColumn::get($toConstant);
32+
$toFile = $toConstant->getDeclaringClass()
33+
->getFileName();
34+
2935
foreach ($this->checks as $check) {
30-
yield from $check($fromConstant, $toConstant);
36+
foreach ($check($fromConstant, $toConstant) as $change) {
37+
// Note: this approach allows us to quickly add file/line/column to each change, but in future,
38+
// we will need to push this concern into each checker instead.
39+
yield $change->withFilePositionsIfNotAlreadySet($toFile, $toLine, $toColumn);
40+
}
3141
}
3242
}
3343
}

src/DetectChanges/BCBreak/FunctionBased/MultipleChecksOnAFunction.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Roave\BackwardCompatibility\Change;
88
use Roave\BackwardCompatibility\Changes;
9+
use Roave\BackwardCompatibility\Formatter\SymbolStartColumn;
910
use Roave\BetterReflection\Reflection\ReflectionFunction;
1011
use Roave\BetterReflection\Reflection\ReflectionMethod;
1112

@@ -38,8 +39,16 @@ private function multipleChecks(
3839
ReflectionMethod|ReflectionFunction $fromFunction,
3940
ReflectionMethod|ReflectionFunction $toFunction
4041
): iterable {
42+
$toFile = $toFunction->getFileName();
43+
$toLine = $toFunction->getStartLine();
44+
$toColumn = SymbolStartColumn::get($toFunction);
45+
4146
foreach ($this->checks as $check) {
42-
yield from $check($fromFunction, $toFunction);
47+
foreach ($check($fromFunction, $toFunction) as $change) {
48+
// Note: this approach allows us to quickly add file/line/column to each change, but in future,
49+
// we will need to push this concern into each checker instead.
50+
yield $change->withFilePositionsIfNotAlreadySet($toFile, $toLine, $toColumn);
51+
}
4352
}
4453
}
4554
}

src/DetectChanges/BCBreak/InterfaceBased/MultipleChecksOnAnInterface.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Roave\BackwardCompatibility\Change;
88
use Roave\BackwardCompatibility\Changes;
9+
use Roave\BackwardCompatibility\Formatter\SymbolStartColumn;
910
use Roave\BetterReflection\Reflection\ReflectionClass;
1011

1112
final class MultipleChecksOnAnInterface implements InterfaceBased
@@ -26,8 +27,16 @@ public function __invoke(ReflectionClass $fromInterface, ReflectionClass $toInte
2627
/** @return iterable<int, Change> */
2728
private function multipleChecks(ReflectionClass $fromInterface, ReflectionClass $toInterface): iterable
2829
{
30+
$toFile = $toInterface->getFileName();
31+
$toLine = $toInterface->getStartLine();
32+
$toColumn = SymbolStartColumn::get($toInterface);
33+
2934
foreach ($this->checks as $check) {
30-
yield from $check($fromInterface, $toInterface);
35+
foreach ($check($fromInterface, $toInterface) as $change) {
36+
// Note: this approach allows us to quickly add file/line/column to each change, but in future,
37+
// we will need to push this concern into each checker instead.
38+
yield $change->withFilePositionsIfNotAlreadySet($toFile, $toLine, $toColumn);
39+
}
3140
}
3241
}
3342
}

src/DetectChanges/BCBreak/MethodBased/MultipleChecksOnAMethod.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Roave\BackwardCompatibility\Change;
88
use Roave\BackwardCompatibility\Changes;
9+
use Roave\BackwardCompatibility\Formatter\SymbolStartColumn;
910
use Roave\BetterReflection\Reflection\ReflectionMethod;
1011

1112
final class MultipleChecksOnAMethod implements MethodBased
@@ -26,8 +27,16 @@ public function __invoke(ReflectionMethod $fromMethod, ReflectionMethod $toMetho
2627
/** @return iterable<int, Change> */
2728
private function multipleChecks(ReflectionMethod $fromMethod, ReflectionMethod $toMethod): iterable
2829
{
30+
$toFile = $toMethod->getFileName();
31+
$toLine = $toMethod->getStartLine();
32+
$toColumn = SymbolStartColumn::get($toMethod);
33+
2934
foreach ($this->checks as $check) {
30-
yield from $check($fromMethod, $toMethod);
35+
foreach ($check($fromMethod, $toMethod) as $change) {
36+
// Note: this approach allows us to quickly add file/line/column to each change, but in future,
37+
// we will need to push this concern into each checker instead.
38+
yield $change->withFilePositionsIfNotAlreadySet($toFile, $toLine, $toColumn);
39+
}
3140
}
3241
}
3342
}

src/DetectChanges/BCBreak/PropertyBased/MultipleChecksOnAProperty.php

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

77
use Roave\BackwardCompatibility\Change;
88
use Roave\BackwardCompatibility\Changes;
9+
use Roave\BackwardCompatibility\Formatter\SymbolStartColumn;
910
use Roave\BetterReflection\Reflection\ReflectionProperty;
1011

1112
final class MultipleChecksOnAProperty implements PropertyBased
@@ -26,8 +27,17 @@ public function __invoke(ReflectionProperty $fromProperty, ReflectionProperty $t
2627
/** @return iterable<int, Change> */
2728
private function multipleChecks(ReflectionProperty $fromProperty, ReflectionProperty $toProperty): iterable
2829
{
30+
$toLine = $toProperty->getStartLine();
31+
$toColumn = SymbolStartColumn::get($toProperty);
32+
$toFile = $toProperty->getImplementingClass()
33+
->getFileName();
34+
2935
foreach ($this->checks as $check) {
30-
yield from $check($fromProperty, $toProperty);
36+
foreach ($check($fromProperty, $toProperty) as $change) {
37+
// Note: this approach allows us to quickly add file/line/column to each change, but in future,
38+
// we will need to push this concern into each checker instead.
39+
yield $change->withFilePositionsIfNotAlreadySet($toFile, $toLine, $toColumn);
40+
}
3141
}
3242
}
3343
}

0 commit comments

Comments
 (0)