Update check-plugin-links.yml #2
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: Validate Plugin Download Links | |
| on: | |
| push: | |
| branches: | |
| - main # Runs on every push to the main branch | |
| workflow_dispatch: # Allows manual triggering of the workflow | |
| 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." | |
| if [ -f badges.json ]; then | |
| echo "badges.json successfully fetched from gh-pages." | |
| else | |
| 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 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`; | |
| 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) { | |
| 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(); | |
| EOF |