Update check-plugin-links.yml #15
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 from README | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| validate-readme-links: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Fetch README.md from the main branch | |
| run: | | |
| if [ ! -f README.md ]; then | |
| echo "README.md not found in the repository." | |
| 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: Run Validation Script | |
| run: | | |
| echo "Running validation script" | |
| node <<EOF | |
| const axios = require('axios'); | |
| const fs = require('fs'); | |
| const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); | |
| async function validateReadmeLinks() { | |
| let hasErrors = false; | |
| const readmeContent = fs.readFileSync('./README.md', 'utf-8'); | |
| const pluginRegex = /### \(.*?)\\(.*?)\.*?\!\Latest Release Date\\.*?\\\(.*?)\/gs; | |
| let match; | |
| while ((match = pluginRegex.exec(readmeContent)) !== null) { | |
| const pluginName = match[1]; | |
| const repoUrl = match[2]; | |
| const readmeReleaseUrl = match[3]; | |
| try { | |
| const repoName = repoUrl.replace('https://github.com/', ''); | |
| const apiUrl = \`https://api.github.com/repos/\${repoName}/releases/latest\`; | |
| await sleep(2000); // Throttle requests to avoid hitting the API rate limit | |
| const response = await axios.get(apiUrl, { | |
| headers: { | |
| 'User-Agent': 'GitHub Actions', | |
| Accept: 'application/vnd.github.v3+json' | |
| } | |
| }); | |
| const latestReleaseUrl = response.data.assets[0]?.browser_download_url; | |
| if (!latestReleaseUrl) { | |
| console.warn(\`⚠️ \${pluginName}: No downloadable asset found in the latest release.\`); | |
| console.log(\`::warning file=README.md,line=1::\${pluginName} has no downloadable asset in its latest release.\`); | |
| continue; | |
| } | |
| if (readmeReleaseUrl === latestReleaseUrl) { | |
| console.log(\`✅ \${pluginName}: Latest release URL in README matches the actual latest release.\`); | |
| } else { | |
| console.error(\`❌ \${pluginName}: Latest release URL in README is outdated.\`); | |
| console.error(\` Expected: \${latestReleaseUrl}\`); | |
| console.error(\` Found: \${readmeReleaseUrl}\`); | |
| console.log(\`::error file=README.md,line=1::\${pluginName} has an outdated latest release URL.\`); | |
| hasErrors = true; | |
| } | |
| } catch (error) { | |
| if (error.response?.status === 404) { | |
| console.warn(\`⚠️ \${pluginName}: No releases found (404).\`); | |
| console.log(\`::warning file=README.md,line=1::\${pluginName} has no releases.\`); | |
| } else if (error.response?.status === 403) { | |
| console.error(\`⚠️ \${pluginName}: Rate limited or access denied (403).\`); | |
| console.log(\`::error file=README.md,line=1::\${pluginName} encountered a rate limit or access issue.\`); | |
| hasErrors = true; | |
| } else { | |
| console.error(\`⚠️ Error checking \${pluginName}: \${error.message}\`); | |
| console.log(\`::error file=README.md,line=1::\${pluginName} encountered an error: \${error.message}\`); | |
| hasErrors = true; | |
| } | |
| } | |
| } | |
| if (hasErrors) { | |
| process.exit(1); | |
| } | |
| } | |
| validateReadmeLinks().catch(err => { | |
| console.error('Unhandled error:', err.message); | |
| process.exit(1); | |
| }); | |
| EOF |