Skip to content

Commit 950b2e7

Browse files
committed
WIP
1 parent 0899156 commit 950b2e7

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
working-directory:
5+
required: false
6+
type: string
7+
default: .
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
phar: ${{ steps.phar.outputs.phar }}
14+
steps:
15+
- uses: Icinga/github-actions/.github/actions/php-and-dependencies@php-workflow
16+
name: Setup PHP and dependencies
17+
with:
18+
php-version: 8.4
19+
working-directory: ${{ inputs.working-directory }}
20+
21+
- name: Build PHAR
22+
working-directory: ${{ inputs.working-directory }}
23+
id: phar
24+
run: |
25+
php -d phar.readonly=0 vendor/bin/phar-composer build
26+
echo "::set-output name=phar::$(pwd)/phpstan-adjust-scandirs.phar"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require __DIR__ . '/../vendor/autoload.php';
5+
6+
use Nette\Neon\Neon;
7+
8+
if ($argc < 3) {
9+
$program = basename($argv[0]);
10+
fwrite(STDERR, "Usage: $program <phpstan.neon> <scan_directories_separated_by_path_separator>\n");
11+
exit(1);
12+
}
13+
14+
$configFile = $argv[1];
15+
$scanDirsRaw = $argv[2];
16+
17+
$diff = [];
18+
19+
$scanDirs = explode(PATH_SEPARATOR, $scanDirsRaw);
20+
foreach ($scanDirs as $dir) {
21+
if (! is_dir($dir)) {
22+
fwrite(STDERR, "Error: Directory does not exist: $dir\n");
23+
} elseif (! is_readable($dir)) {
24+
fwrite(STDERR, "Error: Directory not readable: $dir\n");
25+
} else {
26+
$diff[] = "+ $dir";
27+
28+
continue;
29+
}
30+
31+
// Exit if not directory or not readable.
32+
exit(1);
33+
}
34+
35+
try {
36+
$config = Neon::decodeFile($configFile);
37+
} catch (Throwable $e) {
38+
fwrite(STDERR, "Error: Failed to decode NEON config: " . $e->getMessage() . "\n");
39+
exit(1);
40+
}
41+
42+
foreach ((array) $config['parameters']['scanDirectories'] ?? [] as $existing) {
43+
if (is_dir($existing) && is_readable($existing)) {
44+
$scanDirs[] = $existing;
45+
46+
$diff[] = "$existing (unchanged)";
47+
} else {
48+
$diff[] = "- $existing (not readable)";
49+
}
50+
}
51+
52+
$config['parameters']['scanDirectories'] = $scanDirs;
53+
54+
$encoded = Neon::encode($config, true);
55+
if (file_put_contents($configFile, $encoded) === false) {
56+
fwrite(STDERR, "Error: Cannot write NEON config file\n");
57+
exit(1);
58+
}
59+
60+
echo implode(PHP_EOL, $diff);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"nette/neon": "^3.4"
4+
}
5+
}

0 commit comments

Comments
 (0)