Skip to content

Commit 87de4a3

Browse files
authored
Merge pull request #74 from WyriHaximus/post-process-diffs
Post process diffs
2 parents 4c1f106 + 0dede20 commit 87de4a3

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

Dockerfile-build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ RUN composer install --ansi --no-progress --no-interaction --prefer-dist
99
## Compile runtime image
1010
FROM wyrihaximusnet/php:7.4-nts-alpine-slim-root AS runtime
1111
RUN mkdir /workdir
12-
COPY ./entrypoint.sh ./comment.php ./composer.* /workdir/
12+
COPY ./entrypoint.sh ./comment.php ./post-process.php ./composer.* /workdir/
1313
COPY --from=install-dependencies /workdir/vendor/ /workdir/vendor/
1414
ENTRYPOINT ["/workdir/entrypoint.sh"]

entrypoint.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ production=$(cat /workdir/production.md)
1212
/workdir/vendor/bin/composer-diff "${GITHUB_BASE_REF}:composer.lock" "${GITHUB_HEAD_REF}:composer.lock" --with-links --with-platform --no-prod -vvv > /workdir/development.md
1313
development=$(cat /workdir/development.md)
1414

15+
echo "Raw:"
16+
echo "=================================================="
17+
echo "Production:"
18+
echo "${production}"
19+
echo "--------------------------------------------------"
20+
echo "Development:"
21+
echo "${development}"
22+
23+
php /workdir/post-process.php production
24+
php /workdir/post-process.php development
25+
26+
echo "Post Processed:"
27+
echo "=================================================="
1528
echo "Production:"
1629
echo "${production}"
1730
echo "--------------------------------------------------"

post-process.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
require '/workdir/vendor/autoload.php';
4+
5+
$diff = file_get_contents('/workdir/' . $argv[1] . '.md');
6+
7+
preg_match_all('/ \| dev-\b(\w.*)\b ([0-9a-f]{7}) \| /', $diff, $matches);
8+
9+
if (count($matches[2]) === 0) {
10+
exit(0);
11+
}
12+
13+
$lines = explode(PHP_EOL, $diff);
14+
foreach ($matches[2] as $matchIndex => $sha) {
15+
foreach ($lines as $index => $contents) {
16+
if (strpos($contents, ' | 9999999-dev ' . $sha . ' | dev-' . $matches[1][$matchIndex] . ' ' . $sha . ' | ') !== false) {
17+
unset($lines[$index]);
18+
}
19+
}
20+
}
21+
22+
$processedContents = implode(PHP_EOL, $lines);
23+
if (strpos($processedContents, '[Compare]') === false) {
24+
$processedContents = '';
25+
}
26+
27+
file_put_contents('/workdir/' . $argv[1] . '.md', $processedContents);

0 commit comments

Comments
 (0)