Update check-latest-release.yml #8
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: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| check-readme: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '18' | |
| - name: Install dependencies | |
| run: npm install @octokit/rest | |
| - name: Check README for latest 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\/.*?).*?(.*?)(https:\/\/github\.com\/.*?\/releases\/.*)/g; | |
| let match; | |
| let allCorrect = true; | |
| console.log('Checking README for outdated release URLs...'); | |
| while ((match = regex.exec(readme)) !== null) { | |
| const pluginName = match[1]; | |
| const repoUrl = match[2]; | |
| const currentReleaseUrl = match[4]; | |
| const repoPath = repoUrl.replace('https://github.com/', ''); | |
| try { | |
| const { data: latestRelease } = await octokit.repos.getLatestRelease({ | |
| owner: repoPath.split('/')[0], | |
| repo: repoPath.split('/')[1], | |
| }); | |
| const latestReleaseUrl = latestRelease.html_url; | |
| if (currentReleaseUrl !== latestReleaseUrl) { | |
| console.log(`❌ ${pluginName} is outdated. Update the URL to ${latestReleaseUrl}`); | |
| allCorrect = false; | |
| } else { | |
| console.log(`✅ ${pluginName} is up-to-date.`); | |
| } | |
| } catch (error) { | |
| console.log(`⚠️ Failed to fetch latest release for ${pluginName}. Error: ${error.message}`); | |
| allCorrect = false; | |
| } | |
| } | |
| if (!allCorrect) { | |
| process.exit(1); | |
| } | |
| }; | |
| checkLatestRelease(); | |
| EOF |