diff --git a/.github/workflows/update-registry.yml b/.github/workflows/update-registry.yml new file mode 100644 index 0000000..bf54df6 --- /dev/null +++ b/.github/workflows/update-registry.yml @@ -0,0 +1,43 @@ +name: Update Plugin Registry + +on: + schedule: + - cron: '0 0 * * *' # Run daily at midnight + workflow_dispatch: # Allow manual trigger + +jobs: + build: + runs-on: ubuntu-latest + + permissions: + contents: write # Needed to push changes + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + + - name: Generate Registry + run: php scripts/generate_registry.php + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check for Changes + id: check_changes + run: | + if [[ -n $(git status -s public/plugins.json) ]]; then + echo "has_changes=true" >> $GITHUB_OUTPUT + fi + + - name: Commit and Push + if: steps.check_changes.outputs.has_changes == 'true' + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add public/plugins.json + git commit -m "chore(registry): update plugins.json [skip ci]" + git push diff --git a/scripts/generate_registry.php b/scripts/generate_registry.php new file mode 100644 index 0000000..85fa7cb --- /dev/null +++ b/scripts/generate_registry.php @@ -0,0 +1,103 @@ + [ + 'method' => 'GET', + 'header' => [ + 'User-Agent: Mivo-Registry-Bot', + $token ? "Authorization: token $token" : '' + ] + ] + ]; + $context = stream_context_create($opts); + return file_get_contents($url, false, $context); +} + +echo "Starting Registry Generation...\n"; + +// 1. Fetch Repositories +$reposUrl = "https://api.github.com/orgs/$orgName/repos?per_page=100"; +$reposJson = fetchUrl($reposUrl, $githubToken); + +if (!$reposJson) { + die("Error: Failed to fetch repositories.\n"); +} + +$repos = json_decode($reposJson, true); +$plugins = []; + +foreach ($repos as $repo) { + // Only process repositories starting with 'plugin-' + if (strpos($repo['name'], 'plugin-') !== 0) { + continue; + } + + echo "Processing: " . $repo['name'] . "\n"; + + // 2. Fetch plugin.php + $rawUrl = "https://raw.githubusercontent.com/$orgName/{$repo['name']}/{$repo['default_branch']}/plugin.php"; + $pluginContent = fetchUrl($rawUrl, $githubToken); + + if (!$pluginContent) { + echo " - Warning: plugin.php not found. Skipping.\n"; + continue; + } + + // 3. Parse Metadata + // Regex looking for: * Key: Value + preg_match_all('/^\s*\*\s*([a-zA-Z0-9 ]+):\s*(.+)$/m', $pluginContent, $matches, PREG_SET_ORDER); + + $metadata = []; + foreach ($matches as $match) { + $key = strtolower(trim($match[1])); + $value = trim($match[2]); + $metadata[$key] = $value; + } + + // fallback if name is missing + if (empty($metadata['plugin name'])) { + echo " - Warning: 'Plugin Name' header missing. Skipping.\n"; + continue; + } + + // Construct Plugin Object + $plugin = [ + 'id' => $repo['name'], + 'name' => $metadata['plugin name'], + 'description' => $metadata['description'] ?? $repo['description'] ?? '', + 'author' => $metadata['author'] ?? $repo['owner']['login'], + 'version' => $metadata['version'] ?? '0.0.1', + 'category' => $metadata['category'] ?? 'Uncategorized', + 'tags' => array_map('trim', explode(',', $metadata['tags'] ?? '')), + 'repo' => $repo['html_url'], + 'download' => $repo['html_url'] . '/archive/refs/heads/' . $repo['default_branch'] . '.zip', // Default to main/master zip + 'readme' => $repo['html_url'] . '#readme', // Link to GitHub readme for now + 'updated_at' => $repo['updated_at'] + ]; + + // Clean up empty tags + $plugin['tags'] = array_filter($plugin['tags']); + + $plugins[] = $plugin; + echo " + Added: " . $plugin['name'] . "\n"; +} + +// 4. Save to JSON +$json = json_encode($plugins, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); +file_put_contents($outputFile, $json); + +echo "Done! Generated " . count($plugins) . " plugins.\n";