Skip to content

Commit 63c8074

Browse files
committed
Nice diff output
1 parent 168805e commit 63c8074

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

.github/scripts/diffPrefixes.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php declare(strict_types = 1);
2+
3+
use SebastianBergmann\Diff\Differ;
4+
5+
require_once __DIR__ . '/../../vendor/autoload.php';
6+
7+
$diffFile = $argv[1] ?? null;
8+
$oldDir = $argv[2] ?? null;
9+
$newDir = $argv[3] ?? null;
10+
if ($diffFile === null || !is_file($diffFile)) {
11+
exit(1);
12+
}
13+
14+
if ($oldDir === null || !is_dir($oldDir)) {
15+
exit(1);
16+
}
17+
18+
if ($newDir === null || !is_dir($newDir)) {
19+
exit(1);
20+
}
21+
22+
$diffLines = explode("\n", file_get_contents($diffFile));
23+
$differ = new Differ(new \SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder(''));
24+
$isDifferent = false;
25+
foreach ($diffLines as $diffLine) {
26+
$operation = $diffLine[0];
27+
if ($operation === ' ') {
28+
continue;
29+
}
30+
31+
$path = substr($diffLine, 1);
32+
$oldFilePath = $oldDir . '/' . $path;
33+
if (!is_file($oldFilePath)) {
34+
continue;
35+
}
36+
37+
$newFilePath = $newDir . '/' . $path;
38+
if (!is_file($newFilePath)) {
39+
continue;
40+
}
41+
42+
$stringDiff = $differ->diff(file_get_contents($oldFilePath), file_get_contents($newFilePath));
43+
if ($stringDiff === '') {
44+
continue;
45+
}
46+
47+
$isDifferent = true;
48+
49+
echo "$path:\n";
50+
foreach (explode("\n", $stringDiff) as $line) {
51+
if (str_starts_with($line, '+')) {
52+
echo "\033[32m$line\033[0m\n";
53+
} elseif (str_starts_with($line, '-')) {
54+
echo "\033[31m$line\033[0m\n";
55+
} else {
56+
echo "$line\n";
57+
}
58+
}
59+
60+
echo "\n";
61+
}
62+
63+
if ($isDifferent) {
64+
exit(1);
65+
}

.github/workflows/phar.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,10 @@ jobs:
268268
run: "php .github/scripts/listPrefix.php ${{ github.workspace }}/phar-new > phar-new.txt"
269269

270270
- name: "Diff locations"
271-
run: "diff -u phar-old.txt phar-new.txt"
271+
run: "diff -u phar-old.txt phar-new.txt > diff.txt || true"
272+
273+
- name: "Diff files where prefix changed"
274+
run: "php .github/scripts/diffPrefixes.php ${{ github.workspace }}/diff.txt ${{ github.workspace }}/phar-old ${{ github.workspace }}/phar-new"
272275

273276
commit:
274277
name: "Commit PHAR"

0 commit comments

Comments
 (0)