Skip to content

Commit e240ef4

Browse files
authored
Create plugin-version-checker.yml
1 parent 1b49088 commit e240ef4

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Check Plugin Versions
2+
3+
on:
4+
push:
5+
branches:
6+
- main # Trigger when commits are pushed to the main branch
7+
workflow_dispatch: # Allows manual trigger if needed
8+
9+
jobs:
10+
check-plugins:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
# Step 1: Checkout the repository
15+
- name: Checkout Code
16+
uses: actions/checkout@v3
17+
18+
# Step 2: Set up Node.js
19+
- name: Set up Node.js
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: '18'
23+
24+
# Step 3: Install Dependencies
25+
- name: Install Dependencies
26+
run: npm install axios
27+
28+
# Step 4: Check Plugin Versions
29+
- name: Check Plugins
30+
id: check-plugins
31+
run: |
32+
node <<EOF
33+
const fs = require('fs');
34+
const axios = require('axios');
35+
36+
const readmePath = 'README.md';
37+
const pluginsSectionStart = '<!-- START PLUGINS LIST -->';
38+
const pluginsSectionEnd = '<!-- END PLUGINS LIST -->';
39+
40+
// Read README file
41+
const readmeContent = fs.readFileSync(readmePath, 'utf8');
42+
43+
// Extract plugin section
44+
const pluginSection = readmeContent.split(pluginsSectionStart)[1]?.split(pluginsSectionEnd)[0];
45+
if (!pluginSection) {
46+
console.error('Plugins section not found in the README file.');
47+
process.exit(1);
48+
}
49+
50+
// Extract GitHub URLs from the plugin section
51+
const pluginRegex = /https:\/\/github\.com\/([^\s)]+)/g;
52+
const matches = [...pluginSection.matchAll(pluginRegex)];
53+
const plugins = matches.map(match => match[1]);
54+
55+
// Check latest releases
56+
async function checkPlugins(plugins) {
57+
const results = [];
58+
for (const plugin of plugins) {
59+
try {
60+
const [owner, repo] = plugin.split('/');
61+
const response = await axios.get(`https://api.github.com/repos/${owner}/${repo}/releases/latest`, {
62+
headers: { 'Accept': 'application/vnd.github.v3+json' }
63+
});
64+
const latestVersion = response.data.tag_name;
65+
66+
results.push({ repo, latestVersion, status: 'Up-to-date' });
67+
} catch (error) {
68+
results.push({ repo: plugin, status: 'Error or No Releases Found', error: error.message });
69+
}
70+
}
71+
return results;
72+
}
73+
74+
checkPlugins(plugins)
75+
.then(results => {
76+
console.log('Plugin Version Check Results:');
77+
console.table(results);
78+
79+
// Check for outdated plugins
80+
const outdated = results.filter(result => result.status !== 'Up-to-date');
81+
if (outdated.length > 0) {
82+
console.error('Outdated or Unverified Plugins:', outdated);
83+
process.exit(1);
84+
} else {
85+
console.log('All plugins are up-to-date.');
86+
}
87+
})
88+
.catch(err => {
89+
console.error('Error during plugin check:', err);
90+
process.exit(1);
91+
});
92+
EOF

0 commit comments

Comments
 (0)