Skip to content

Create plugin-version-checker.yml #1

Create plugin-version-checker.yml

Create plugin-version-checker.yml #1

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 README file
const readmeContent = fs.readFileSync(readmePath, 'utf8');
// Extract plugin 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\/([^\s)]+)/g;
const matches = [...pluginSection.matchAll(pluginRegex)];
const plugins = matches.map(match => match[1]);
// Check latest releases
async function checkPlugins(plugins) {
const results = [];
for (const plugin of plugins) {
try {
const [owner, repo] = plugin.split('/');
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;
results.push({ repo, latestVersion, status: 'Up-to-date' });
} catch (error) {
results.push({ repo: plugin, status: 'Error or No Releases Found', error: error.message });
}
}
return results;
}
checkPlugins(plugins)
.then(results => {
console.log('Plugin Version Check Results:');
console.table(results);
// Check for outdated plugins
const outdated = results.filter(result => result.status !== 'Up-to-date');
if (outdated.length > 0) {
console.error('Outdated or Unverified Plugins:', outdated);
process.exit(1);
} else {
console.log('All plugins are up-to-date.');
}
})
.catch(err => {
console.error('Error during plugin check:', err);
process.exit(1);
});
EOF