Skip to content

Commit da75a46

Browse files
committed
More advanced validation for each provider and beautify the summary for the main repo.
PR validation and inform the user for invalid endpoints,discovery,url failures.
1 parent eaa3cfd commit da75a46

4 files changed

Lines changed: 185 additions & 116 deletions

File tree

.github/scripts/validate-pr-provider.js

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const { XMLParser } = require('fast-xml-parser');
77
const USER_AGENT = 'oEmbed Validator Bot/1.0 (https://github.com/iamcal/oembed)';
88
const xmlParser = new XMLParser();
99

10-
// --- Validation Logic ---
11-
1210
async function fetchUrl(url, isJson = false) {
1311
const headers = { 'User-Agent': USER_AGENT };
1412
if (isJson) headers['Accept'] = 'application/json';
@@ -111,39 +109,55 @@ async function main() {
111109
for (const file of filesToTest) {
112110
if (fs.existsSync(file)) {
113111
fileCount++;
112+
console.error(`Processing ${file}...`);
114113
const result = await validateProviderFile(file);
115114
allResults.passes.push(...result.passes.map(msg => `**${path.basename(file)}**: ${msg}`));
116115
allResults.fails.push(...result.fails.map(msg => `**${path.basename(file)}**: ${msg}`));
117116
}
118117
}
119118

120-
let markdown = `## Pull Request Provider Validation\n\n`;
121-
markdown += `Tested **${fileCount}** provider file(s) in this pull request.\n\n`;
119+
const passedCount = allResults.passes.length;
120+
const failedCount = allResults.fails.length;
121+
const totalCount = passedCount + failedCount;
122+
let summary;
122123

123-
if (allResults.fails.length > 0) {
124-
markdown += `### ❌ ${allResults.fails.length} Check(s) Failed\n\n`;
125-
allResults.fails.forEach(fail => {
126-
markdown += `- ${fail}\n`;
127-
});
128-
markdown += '\n---\n\n';
129-
}
124+
if (failedCount > 0) {
125+
const failureRows = allResults.fails.map(fail => {
126+
const safeFail = fail.replace(/\|/g, '\\|');
127+
return `| ${safeFail} |`;
128+
}).join('\n');
130129

131-
if (allResults.passes.length > 0) {
132-
markdown += `### ✅ ${allResults.passes.length} Check(s) Passed\n\n`;
133-
allResults.passes.forEach(pass => {
134-
markdown += `- ${pass}\n`;
135-
});
136-
}
130+
summary = `## Pull Request Provider Validation
131+
132+
- ✅ **Passed:** ${passedCount}
133+
- ❌ **Failed:** ${failedCount}
134+
- Total Checks: ${totalCount}
135+
136+
---
137+
138+
### 🚨 Failed Checks
137139
138-
if (allResults.fails.length > 0) {
139-
markdown += `\n**Please address the failed checks before this pull request can be merged.**`;
140+
| Details |
141+
|---------|
142+
${failureRows}
143+
144+
\n**Please address the failed checks before this pull request can be merged.**\`;
140145
} else {
141-
markdown += `\n**All checks passed! Thank you for your contribution.**`;
142-
}
146+
summary = \`## Pull Request Provider Validation
147+
148+
- ✅ **Passed:** ${passedCount}
149+
- ❌ **Failed:** 0
150+
- Total Checks: ${totalCount}
143151
144-
console.log(markdown);
152+
---
153+
154+
### 🎉 All checks passed! Thank you for your contribution.
155+
`;
156+
}
157+
158+
console.log(summary);
145159

146-
if (allResults.fails.length > 0) {
160+
if (failedCount > 0) {
147161
process.exit(1);
148162
}
149163
}

.github/workflows/pr-validation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: oEmbed Validate Provider PR
33
on:
44
pull_request:
55
# branches:
6-
# - master
6+
# - '**'
77
paths:
88
- 'providers/**.yml'
99

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
name: Validate oEmbed providers on the live registry.
1+
name: oEmbed Bot
22

33
on:
4-
# push:
5-
# branches:
6-
# - master
7-
pull_request:
8-
branches:
9-
- master
10-
paths:
11-
- 'providers/**.yml'
124
schedule:
135
- cron: '0 0 */3 * *'
146
workflow_dispatch:
@@ -21,43 +13,60 @@ on:
2113
jobs:
2214
validate:
2315
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
pull-requests: write
2419

2520
steps:
26-
- name: Check out repository
27-
uses: actions/checkout@v4
28-
with:
29-
# Fetch depth 0 is required to accurately compare changes in PRs
30-
fetch-depth: 0
31-
32-
- name: Set up Node.js
33-
uses: actions/setup-node@v4
34-
with:
35-
node-version: '18'
36-
cache: 'npm'
37-
38-
- name: Install dependencies
39-
run: npm install
40-
41-
- name: Get changed files for PRs
42-
id: changed-files
43-
if: github.event_name == 'pull_request'
44-
run: |
45-
FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^providers/.*\.yml$' | sed 's/providers\///' | xargs)
46-
echo "files_to_test=${FILES}" >> $GITHUB_ENV
47-
echo "Changed files: $FILES"
48-
49-
- name: Determine script providers to test
50-
id: script-args
51-
run: |
52-
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
53-
echo "ARGUMENTS=${{ env.files_to_test }}" >> $GITHUB_ENV
54-
elif [[ "${{ github.event.inputs.provider }}" != "" ]]; then
55-
echo "ARGUMENTS=${{ github.event.inputs.provider }}" >> $GITHUB_ENV
56-
else
57-
echo "ARGUMENTS=" >> $GITHUB_ENV
58-
fi
59-
60-
- name: Run validation script
61-
run: |
62-
echo "Running validation with arguments: ${{ env.ARGUMENTS }}"
63-
node scripts/validate-providers.js ${{ env.ARGUMENTS }} >> $GITHUB_STEP_SUMMARY
21+
- name: 🌐 Check out repository
22+
uses: actions/checkout@v4
23+
24+
- name: 🌐 Set up Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: '18'
28+
cache: 'npm'
29+
30+
- name: 💽 Install dependencies
31+
run: npm install
32+
33+
- name: 🌐 Determine script providers to test
34+
id: script-args
35+
run: |
36+
if [[ "${{ github.event.inputs.provider }}" != "" ]]; then
37+
echo "ARGUMENTS=${{ github.event.inputs.provider }}" >> $GITHUB_ENV
38+
else
39+
echo "ARGUMENTS=" >> $GITHUB_ENV
40+
fi
41+
42+
- name: 🤖 Run validation and auto clean inactive providers from the live registry.
43+
id: validation-script
44+
run: |
45+
echo "Running validation with arguments: ${{ env.ARGUMENTS }}"
46+
node scripts/validate-providers.js ${{ env.ARGUMENTS }} >> $GITHUB_STEP_SUMMARY
47+
continue-on-error: true
48+
49+
- name: 🔌 Create Pull Request if changes were made to any providers.
50+
uses: peter-evans/create-pull-request@v7.0.8
51+
if: github.event_name == 'schedule'
52+
with:
53+
token: ${{ secrets.GITHUB_TOKEN }}
54+
commit-message: "chore: Automatically disable unreachable providers"
55+
branch: "automated-provider-cleanup"
56+
delete-branch: true
57+
title: "🤖 Automated Provider Cleanup"
58+
body: |
59+
The oEmbed validation bot has detected that one or more providers have become unreachable (due to DNS, timeout, expired domain, 403 errors) and has automatically moved them to the `providers-disabled` directory.
60+
61+
This PR contains the results of this cleanup. Please review the changes and merge if they are acceptable.
62+
63+
**Assignees:** @ItsWarmaster, @iamcal
64+
assignees: |
65+
ItsWarmaster
66+
iamcal
67+
reviewers: |
68+
ItsWarmaster
69+
iamcal
70+
labels: |
71+
Maintenance
72+
Automated

0 commit comments

Comments
 (0)