|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +$root = dirname(__DIR__); |
| 6 | +$readme = file_get_contents($root . '/readme.txt'); |
| 7 | +$plugin = file_get_contents($root . '/cron-inspector-lite.php'); |
| 8 | + |
| 9 | +if (false === $readme || false === $plugin) { |
| 10 | + fwrite(STDERR, "Unable to read plugin metadata files.\n"); |
| 11 | + exit(1); |
| 12 | +} |
| 13 | + |
| 14 | +$failures = []; |
| 15 | + |
| 16 | +$required_readme_patterns = [ |
| 17 | + '/^=== Cron Inspector Lite ===$/m' => 'readme plugin title', |
| 18 | + '/^Contributors:\s*nariyanto$/m' => 'readme contributors', |
| 19 | + '/^Requires at least:\s*6\.0$/m' => 'minimum WordPress version', |
| 20 | + '/^Requires PHP:\s*7\.4$/m' => 'minimum PHP version', |
| 21 | + '/^Stable tag:\s*0\.1\.0$/m' => 'stable tag', |
| 22 | + '/^License:\s*GPLv2 or later$/m' => 'license', |
| 23 | + '/== Changelog ==/' => 'changelog section', |
| 24 | + '/= 0\.1\.0 =/' => '0.1.0 changelog entry', |
| 25 | +]; |
| 26 | + |
| 27 | +foreach ($required_readme_patterns as $pattern => $label) { |
| 28 | + if (1 !== preg_match($pattern, $readme)) { |
| 29 | + $failures[] = "Missing or invalid {$label}."; |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +$required_plugin_patterns = [ |
| 34 | + '/Plugin Name:\s*Cron Inspector Lite/' => 'plugin name', |
| 35 | + '/Version:\s*0\.1\.0/' => 'plugin version', |
| 36 | + '/Text Domain:\s*cron-inspector-lite/' => 'text domain', |
| 37 | + '/Domain Path:\s*\/languages/' => 'domain path', |
| 38 | + '/Requires at least:\s*6\.0/' => 'plugin minimum WordPress version', |
| 39 | + '/Requires PHP:\s*7\.4/' => 'plugin minimum PHP version', |
| 40 | + '/License:\s*GPL-2\.0-or-later/' => 'plugin license', |
| 41 | +]; |
| 42 | + |
| 43 | +foreach ($required_plugin_patterns as $pattern => $label) { |
| 44 | + if (1 !== preg_match($pattern, $plugin)) { |
| 45 | + $failures[] = "Missing or invalid {$label}."; |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +if (str_contains($readme, 'wp-cron-inspector-lite')) { |
| 50 | + $failures[] = 'readme.txt still contains old plugin slug/name text.'; |
| 51 | +} |
| 52 | + |
| 53 | +if ($failures) { |
| 54 | + foreach ($failures as $failure) { |
| 55 | + fwrite(STDERR, "FAIL: {$failure}\n"); |
| 56 | + } |
| 57 | + exit(1); |
| 58 | +} |
| 59 | + |
| 60 | +echo "Readme and plugin metadata validation passed.\n"; |
0 commit comments