Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add github action to check driver URL validity #3

Merged
merged 10 commits into from
Jul 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/check-driver-urls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Check Driver Urls

on:
pull_request:
push:
branches:
- main

jobs:
check-urls:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/Iron # 20.x.x
- run: npm install yaml
- name: parse drivers registry
uses: actions/github-script@v7
id: drivers_registry_urls
with:
script: | # js
const { parse } = require('yaml');
const fs = require('fs');
const registry = parse(fs.readFileSync('registry.yaml', 'utf8'));

const drivers = registry.drivers;
const majorVersion = '${{ steps.major_version.outputs.major_version }}';

const urls = [];

for (const driver of drivers) {
const driverName = driver.name;
const driverDeps = driver.deps;

for (const versionName of Object.keys(driver.versions)) {
urls.push({
description: `${driverName}-${versionName}`,
url: driver.versions[versionName],
});
}

if (driverDeps) {
driverDeps.forEach(dep => {
urls.push({
description: `${driverName}-dep`,
url: dep,
});
});
}
}

console.log(urls);

return urls;

- name: check urls
uses: actions/github-script@v7
with:
script: | # js
const urls = JSON.parse(`${{ steps.drivers_registry_urls.outputs.result }}`);
const failedUrls = [];

await Promise.all(urls.map(({ description, url }) => {
return fetch(url)
.then((response) => {
if (!response.ok) {
console.log(`❌ Failed to fetch ${description}`);
failedUrls.push({ description, url });
} else {
console.log(`✅ Successfully fetched ${description}`);
}
}).catch((error) => {
console.log(`❌ Failed to fetch ${description}: ${error}`);
failedUrls.push({ description, url });
});
}));

if (failedUrls.length > 0) {
console.log('\n\n❌ Failed urls:', failedUrls);
process.exit(1);
}

console.log(`\n\n✅ Successfully fetched all urls`);
process.exit(0);