Skip to content

Update check-plugin-links.yml #11

Update check-plugin-links.yml

Update check-plugin-links.yml #11

name: Validate Plugin Download Links
on:
push:
branches:
- main
workflow_dispatch:
jobs:
validate-links:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Fetch `badges.json` from gh-pages
run: |
git fetch origin gh-pages:gh-pages || echo "gh-pages branch does not exist."
git checkout gh-pages || echo "Failed to checkout gh-pages."
if [ ! -f badges.json ]; then
echo "No badges.json file found in gh-pages branch."
exit 1
fi
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
- name: Install Dependencies
run: npm install axios
- name: Validate Download Links
run: |
node <<EOF
const axios = require('axios');
const fs = require('fs');
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
const badges = JSON.parse(fs.readFileSync('./badges.json', 'utf-8'));
const plugins = badges.plugins;
async function validateLinks() {
let hasErrors = false;
for (const plugin of plugins) {
const repoUrl = plugin.url;
const releaseUrl = plugin.releaseUrl;
try {
const repoName = repoUrl.replace('https://github.com/', '');
const apiUrl = `https://api.github.com/repos/${repoName}/releases/latest`;
await sleep(2000); // Throttle requests with 2 seconds delay
const response = await axios.get(apiUrl, {
headers: {
'User-Agent': 'GitHub Actions',
Accept: 'application/vnd.github.v3+json',
},
});
const latestDownloadUrl = response.data.assets[0]?.browser_download_url || null;
if (!latestDownloadUrl) {
console.warn(\`⚠️ ${plugin.name}: No downloadable asset found in the latest release.\`);
console.log(\`::warning file=badges.json,line=1::${plugin.name} has no downloadable asset in its latest release.\`);
} else if (releaseUrl === latestDownloadUrl) {
console.log(\`✅ ${plugin.name}: Download link is up-to-date.\`);
} else {
console.error(\`❌ ${plugin.name}: Download link is outdated.\`);
console.error(\` Expected: ${latestDownloadUrl}\`);
console.error(\` Found: ${releaseUrl}\`);
console.log(\`::error file=badges.json,line=1::${plugin.name} has an outdated download link.\`);
hasErrors = true;
}
} catch (error) {
if (error.response?.status === 404) {
console.warn(\`⚠️ ${plugin.name}: No releases found (404).\`);
console.log(\`::warning file=badges.json,line=1::${plugin.name} has no releases.\`);
} else if (error.response?.status === 403) {
console.error(\`⚠️ ${plugin.name}: Rate limited or access denied (403).\`);
console.log(\`::error file=badges.json,line=1::${plugin.name} encountered an access issue.\`);
hasErrors = true;
} else {
console.error(\`⚠️ Error checking ${plugin.name}: ${error.message}\`);
console.log(\`::error file=badges.json,line=1::${plugin.name} encountered an error: ${error.message}\`);
hasErrors = true;
}
}
}
if (hasErrors) {
process.exit(1);
}
}
validateLinks().catch(err => {
console.error('Unhandled error:', err.message);
process.exit(1);
});
EOF