Update broken-links.yml #25
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: Check Latest Release URLs | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| check-readme: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 18 | |
| - name: Install dependencies | |
| run: npm install @octokit/rest | |
| - name: Check README for outdated release URLs | |
| run: | | |
| node --input-type=module <<'EOF' | |
| import { readFileSync } from 'fs'; | |
| import { Octokit } from '@octokit/rest'; | |
| const octokit = new Octokit(); // Unauthenticated for public API calls | |
| const checkLatestRelease = async () => { | |
| const readme = readFileSync('README.md', 'utf-8'); | |
| const regex = /- ### \[(.*?)\]\((https:\/\/github\.com\/.*?)\) <br>.*?\[!\[Latest Release Date\]\(.*?\)\]\((.*?)\)/g; | |
| let match; | |
| let allCorrect = true; | |
| console.log('🔍 Starting checks for outdated release URLs in README...'); | |
| while ((match = regex.exec(readme)) !== null) { | |
| const pluginName = match[1]; | |
| const repoUrl = match[2]; | |
| const currentReleaseUrl = match[3]; | |
| const repoPath = repoUrl.replace('https://github.com/', ''); | |
| console.log(`\n🛠 Checking plugin: ${pluginName}`); | |
| console.log(` ➤ Repository URL: ${repoUrl}`); | |
| console.log(` ➤ Current Release URL: ${currentReleaseUrl}`); | |
| console.log(` ➤ Repo Path: ${repoPath}`); | |
| try { | |
| const { data: latestRelease } = await octokit.repos.getLatestRelease({ | |
| owner: repoPath.split('/')[0], | |
| repo: repoPath.split('/')[1], | |
| }); | |
| const latestReleaseUrl = `https://github.com/${repoPath}/releases/tag/${latestRelease.tag_name}`; | |
| console.log(` ➤ Latest Release URL: ${latestReleaseUrl}`); | |
| if (currentReleaseUrl.trim() === latestReleaseUrl.trim()) { | |
| console.log(`✅ ${pluginName} is up-to-date.`); | |
| } else { | |
| console.log(`❌ ${pluginName} is outdated.`); | |
| console.log(` ➤ Update the URL to: ${latestReleaseUrl}`); | |
| console.log(`::warning file=README.md::${pluginName} is outdated. Update the URL to ${latestReleaseUrl}`); | |
| allCorrect = false; | |
| } | |
| } catch (error) { | |
| console.error(`⚠️ Failed to fetch latest release for ${pluginName}. Error: ${error.message}`); | |
| console.log(`::error file=README.md::Failed to fetch latest release for ${pluginName}: ${error.message}`); | |
| allCorrect = false; | |
| } | |
| } | |
| if (allCorrect) { | |
| console.log('✅ All plugins are up-to-date.'); | |
| console.log('::notice file=README.md::All plugins are verified and up-to-date.'); | |
| } else { | |
| console.log('❌ Some plugins are outdated.'); | |
| process.exit(1); | |
| } | |
| }; | |
| checkLatestRelease(); | |
| EOF |