Skip to content

Commit 7e65407

Browse files
authored
Update check-plugin-links.yml
Test 13
1 parent 74392ef commit 7e65407

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed
Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Validate Plugin Download Links
1+
name: Validate Plugin Download Links from README
22

33
on:
44
push:
@@ -7,19 +7,17 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
validate-links:
10+
validate-readme-links:
1111
runs-on: ubuntu-latest
1212

1313
steps:
1414
- name: Checkout code
1515
uses: actions/checkout@v3
1616

17-
- name: Fetch `badges.json` from gh-pages
17+
- name: Fetch README.md from the main branch
1818
run: |
19-
git fetch origin gh-pages:gh-pages || echo "gh-pages branch does not exist."
20-
git checkout gh-pages || echo "Failed to checkout gh-pages."
21-
if [ ! -f badges.json ]; then
22-
echo "No badges.json file found in gh-pages branch."
19+
if [ ! -f README.md ]; then
20+
echo "README.md not found in the repository."
2321
exit 1
2422
fi
2523
@@ -34,60 +32,64 @@ jobs:
3432
- name: Add and Run Validation Script
3533
run: |
3634
echo "Adding and running validation script"
37-
cat <<EOF > validate-links.js
35+
cat <<EOF > validate-readme-links.js
3836
const axios = require('axios');
3937
const fs = require('fs');
4038
4139
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
4240
43-
const badges = JSON.parse(fs.readFileSync('./badges.json', 'utf-8'));
44-
const plugins = badges.plugins;
45-
46-
async function validateLinks() {
41+
async function validateReadmeLinks() {
4742
let hasErrors = false;
4843
49-
for (const plugin of plugins) {
50-
const repoUrl = plugin.url;
51-
const releaseUrl = plugin.releaseUrl;
44+
const readmeContent = fs.readFileSync('./README.md', 'utf-8');
45+
const pluginRegex = /### \(.*?)\\(.*?)\.*?\\\!\Latest Release Date\\(.*?)\\\(.*?)\/gs;
46+
47+
let match;
48+
while ((match = pluginRegex.exec(readmeContent)) !== null) {
49+
const pluginName = match[1];
50+
const repoUrl = match[2];
51+
const readmeReleaseUrl = match[4];
5252
5353
try {
5454
const repoName = repoUrl.replace('https://github.com/', '');
5555
const apiUrl = \`https://api.github.com/repos/\${repoName}/releases/latest\`;
5656
57-
await sleep(2000); // Throttle requests with 2 seconds delay
58-
57+
await sleep(2000); // Throttle requests to avoid hitting the API rate limit
5958
const response = await axios.get(apiUrl, {
6059
headers: {
6160
'User-Agent': 'GitHub Actions',
62-
Accept: 'application/vnd.github.v3+json',
63-
},
61+
Accept: 'application/vnd.github.v3+json'
62+
}
6463
});
6564
66-
const latestDownloadUrl = response.data.assets[0]?.browser_download_url || null;
65+
const latestReleaseUrl = response.data.assets[0]?.browser_download_url;
66+
67+
if (!latestReleaseUrl) {
68+
console.warn(\`⚠️ \${pluginName}: No downloadable asset found in the latest release.\`);
69+
console.log(\`::warning file=README.md,line=1::\${pluginName} has no downloadable asset in its latest release.\`);
70+
continue;
71+
}
6772
68-
if (!latestDownloadUrl) {
69-
console.warn(\`⚠️ \${plugin.name}: No downloadable asset found in the latest release.\`);
70-
console.log(\`::warning file=badges.json,line=1::\${plugin.name} has no downloadable asset in its latest release.\`);
71-
} else if (releaseUrl === latestDownloadUrl) {
72-
console.log(\`✅ \${plugin.name}: Download link is up-to-date.\`);
73+
if (readmeReleaseUrl === latestReleaseUrl) {
74+
console.log(\`✅ \${pluginName}: Latest release URL in README matches the actual latest release.\`);
7375
} else {
74-
console.error(\`❌ \${plugin.name}: Download link is outdated.\`);
75-
console.error(\` Expected: \${latestDownloadUrl}\`);
76-
console.error(\` Found: \${releaseUrl}\`);
77-
console.log(\`::error file=badges.json,line=1::\${plugin.name} has an outdated download link.\`);
76+
console.error(\`❌ \${pluginName}: Latest release URL in README is outdated.\`);
77+
console.error(\` Expected: \${latestReleaseUrl}\`);
78+
console.error(\` Found: \${readmeReleaseUrl}\`);
79+
console.log(\`::error file=README.md,line=1::\${pluginName} has an outdated latest release URL.\`);
7880
hasErrors = true;
7981
}
8082
} catch (error) {
8183
if (error.response?.status === 404) {
82-
console.warn(\`⚠️ \${plugin.name}: No releases found (404).\`);
83-
console.log(\`::warning file=badges.json,line=1::\${plugin.name} has no releases.\`);
84+
console.warn(\`⚠️ \${pluginName}: No releases found (404).\`);
85+
console.log(\`::warning file=README.md,line=1::\${pluginName} has no releases.\`);
8486
} else if (error.response?.status === 403) {
85-
console.error(\`⚠️ \${plugin.name}: Rate limited or access denied (403).\`);
86-
console.log(\`::error file=badges.json,line=1::\${plugin.name} encountered an access issue.\`);
87+
console.error(\`⚠️ \${pluginName}: Rate limited or access denied (403).\`);
88+
console.log(\`::error file=README.md,line=1::\${pluginName} encountered a rate limit or access issue.\`);
8789
hasErrors = true;
8890
} else {
89-
console.error(\`⚠️ Error checking \${plugin.name}: \${error.message}\`);
90-
console.log(\`::error file=badges.json,line=1::\${plugin.name} encountered an error: \${error.message}\`);
91+
console.error(\`⚠️ Error checking \${pluginName}: \${error.message}\`);
92+
console.log(\`::error file=README.md,line=1::\${pluginName} encountered an error: \${error.message}\`);
9193
hasErrors = true;
9294
}
9395
}
@@ -98,10 +100,10 @@ jobs:
98100
}
99101
}
100102
101-
validateLinks().catch(err => {
103+
validateReadmeLinks().catch(err => {
102104
console.error('Unhandled error:', err.message);
103105
process.exit(1);
104106
});
105107
EOF
106108
107-
node validate-links.js
109+
node validate-readme-links.js

0 commit comments

Comments
 (0)