From 1c37af6f5bc65029e72b32e783aa3e6e6cf8e4c9 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Wed, 24 Dec 2025 00:16:31 +0100 Subject: [PATCH 1/2] add workflow to validate plugin.json files --- .github/scripts/validatePluginJson.php | 83 ++++++++++++++++++++++ .github/workflows/validate-plugin-json.yml | 25 +++++++ 2 files changed, 108 insertions(+) create mode 100644 .github/scripts/validatePluginJson.php create mode 100644 .github/workflows/validate-plugin-json.yml diff --git a/.github/scripts/validatePluginJson.php b/.github/scripts/validatePluginJson.php new file mode 100644 index 0000000..d2ef076 --- /dev/null +++ b/.github/scripts/validatePluginJson.php @@ -0,0 +1,83 @@ + Date: Wed, 24 Dec 2025 00:22:03 +0100 Subject: [PATCH 2/2] fix path --- .github/scripts/validatePluginJson.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/scripts/validatePluginJson.php b/.github/scripts/validatePluginJson.php index d2ef076..a73c5f8 100644 --- a/.github/scripts/validatePluginJson.php +++ b/.github/scripts/validatePluginJson.php @@ -32,30 +32,31 @@ function findPluginJsonFiles(string $dir): array * Validate a `plugin.json` file to ensure it does not contain a "meta" key. * * @param string $file Path to the JSON file. + * @param string $relativePath Relative path to the file for better output clarity. * @return string|null Error message if invalid, or null if valid. */ -function validateJsonFile(string $file): ?string +function validateJsonFile(string $file, string $relativePath): ?string { $content = file_get_contents($file); if ($content === false) { - return "Failed to read $file."; + return "Failed to read $relativePath."; } $json = json_decode($content, true); if (json_last_error() !== JSON_ERROR_NONE) { - return "Invalid JSON in $file: " . json_last_error_msg(); + return "Invalid JSON in $relativePath: " . json_last_error_msg(); } if (array_key_exists('meta', $json)) { - return "$file contains a 'meta' key. Please remove it."; + return "$relativePath contains a 'meta' key. Please remove it."; } return null; } -$root = __DIR__ . '/../../'; +$root = realpath(__DIR__ . '/../../'); $pluginJsonFiles = findPluginJsonFiles($root); echo 'Found ' . count($pluginJsonFiles) . " plugin.json file(s) to validate.\n"; @@ -63,8 +64,10 @@ function validateJsonFile(string $file): ?string $errors = []; foreach ($pluginJsonFiles as $file) { - echo "Validating $file...\n"; - $error = validateJsonFile($file); + $relativePath = str_replace($root . DIRECTORY_SEPARATOR, '', $file); + + echo "Validating $relativePath...\n"; + $error = validateJsonFile($file, $relativePath); if ($error !== null) { $errors[] = $error;