Update plugin-version-checker.yml #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Check Plugin Versions | ||
| on: | ||
| push: | ||
| branches: | ||
| - main # Trigger when commits are pushed to the main branch | ||
| workflow_dispatch: # Allows manual trigger if needed | ||
| jobs: | ||
| check-plugins: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| # Step 1: Checkout the repository | ||
| - name: Checkout Code | ||
| uses: actions/checkout@v3 | ||
| # Step 2: Set up Node.js | ||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: '18' | ||
| # Step 3: Install Dependencies | ||
| - name: Install Dependencies | ||
| run: npm install axios | ||
| # Step 4: Check Plugin Versions | ||
| - name: Check Plugins | ||
| id: check-plugins | ||
| run: | | ||
| node <<EOF | ||
| const fs = require('fs'); | ||
| const axios = require('axios'); | ||
| const readmePath = 'README.md'; | ||
| const pluginsSectionStart = '<!-- START PLUGINS LIST -->'; | ||
| const pluginsSectionEnd = '<!-- END PLUGINS LIST -->'; | ||
| // Read the README file | ||
| const readmeContent = fs.readFileSync(readmePath, 'utf8'); | ||
| // Extract the plugins section | ||
| const pluginSection = readmeContent.split(pluginsSectionStart)[1]?.split(pluginsSectionEnd)[0]; | ||
| if (!pluginSection) { | ||
| console.error('Plugins section not found in the README file.'); | ||
| process.exit(1); | ||
| } | ||
| // Extract GitHub URLs from the plugin section | ||
| const pluginRegex = /https:\/\/github\.com\/([\w-]+)\/([\w-]+)/g; | ||
| const matches = [...pluginSection.matchAll(pluginRegex)]; | ||
| const plugins = matches | ||
| .map(match => ({ owner: match[1], repo: match[2] })) | ||
| .filter(plugin => plugin.owner && plugin.repo); // Ensure valid entries | ||
| // Debugging: Log extracted plugins | ||
| if (plugins.length === 0) { | ||
| console.error('No valid plugins found in the README file.'); | ||
| process.exit(1); | ||
| } | ||
| console.log('Extracted Plugins:', plugins); | ||
| // Function to check latest releases | ||
| async function checkPlugins(plugins) { | ||
| const results = []; | ||
| for (const { owner, repo } of plugins) { | ||
| try { | ||
| const response = await axios.get(`https://api.github.com/repos/${owner}/${repo}/releases/latest`, { | ||
| headers: { 'Accept': 'application/vnd.github.v3+json' } | ||
| }); | ||
| const latestVersion = response.data.tag_name || 'No tag'; | ||
| const releaseDate = response.data.published_at || 'Unknown'; | ||
| results.push({ repo: `${owner}/${repo}`, latestVersion, releaseDate, status: 'Up-to-date' }); | ||
| } catch (error) { | ||
| results.push({ repo: `${owner}/${repo}`, status: 'Error or No Releases Found', error: error.message }); | ||
| } | ||
| } | ||
| return results; | ||
| } | ||
| // Run the check and display results | ||
| (async () => { | ||
| const results = await checkPlugins(plugins); | ||
| console.log('Plugin Version Check Results:'); | ||
| console.table(results); | ||
| // Identify outdated or problematic plugins | ||
| const problematicPlugins = results.filter(result => result.status !== 'Up-to-date'); | ||
| if (problematicPlugins.length > 0) { | ||
| console.error('Outdated or Unverified Plugins:', problematicPlugins); | ||
| process.exit(1); | ||
| } else { | ||
| console.log('All plugins are up-to-date.'); | ||
| } | ||
| })().catch(err => { | ||
| console.error('Unexpected Error:', err); | ||
| process.exit(1); | ||
| }); | ||
| EOF | ||