ci: Validate docs urls for langchain nodes as well (no-changelog) (#8271)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2024-01-09 19:17:07 +01:00 committed by GitHub
parent 23abd8fb49
commit f208a6e087
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 15 deletions

View file

@ -1,9 +1,12 @@
{ {
"dependencies": { "dependencies": {
"cacheable-lookup": "6.1.0",
"conventional-changelog": "^4.0.0", "conventional-changelog": "^4.0.0",
"glob": "^10.3.0", "debug": "4.3.4",
"semver": "^7.5.4", "glob": "10.3.10",
"tempfile": "^5.0.0", "p-limit": "3.1.0",
"semver": "7.5.4",
"tempfile": "5.0.0",
"typescript": "*" "typescript": "*"
} }
} }

View file

@ -1,11 +1,19 @@
#!/usr/bin/env node #!/usr/bin/env node
const packages = ['nodes-base', '@n8n/nodes-langchain'];
const concurrency = 20;
let exitCode = 0;
const debug = require('debug')('n8n');
const path = require('path'); const path = require('path');
const https = require('https'); const https = require('https');
const glob = require('fast-glob'); const glob = require('glob');
const pLimit = require('p-limit'); const pLimit = require('p-limit');
const Lookup = require('cacheable-lookup').default;
const nodesBaseDir = path.resolve(__dirname, '../packages/nodes-base'); const agent = new https.Agent({ keepAlive: true, keepAliveMsecs: 5000 });
new Lookup().install(agent);
const limiter = pLimit(concurrency);
const validateUrl = async (kind, name, documentationUrl) => const validateUrl = async (kind, name, documentationUrl) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
@ -22,21 +30,26 @@ const validateUrl = async (kind, name, documentationUrl) =>
port: 443, port: 443,
path: url.pathname, path: url.pathname,
method: 'HEAD', method: 'HEAD',
agent,
},
(res) => {
debug('✓', kind, name);
resolve([name, res.statusCode]);
}, },
(res) => resolve([name, res.statusCode]),
) )
.on('error', (e) => reject(e)) .on('error', (e) => reject(e))
.end(); .end();
}); });
const checkLinks = async (kind) => { const checkLinks = async (baseDir, kind) => {
let types = require(path.join(nodesBaseDir, `dist/types/${kind}.json`)); let types = require(path.join(baseDir, `dist/types/${kind}.json`));
if (kind === 'nodes') if (kind === 'nodes')
types = types.filter(({ codex }) => !!codex?.resources?.primaryDocumentation); types = types.filter(({ codex }) => !!codex?.resources?.primaryDocumentation);
const limit = pLimit(30); debug(kind, types.length);
const statuses = await Promise.all( const statuses = await Promise.all(
types.map((type) => types.map((type) =>
limit(() => { limiter(() => {
const documentationUrl = const documentationUrl =
kind === 'credentials' kind === 'credentials'
? type.documentationUrl ? type.documentationUrl
@ -55,10 +68,13 @@ const checkLinks = async (kind) => {
if (missingDocs.length) console.log('Documentation URL missing for %s', kind, missingDocs); if (missingDocs.length) console.log('Documentation URL missing for %s', kind, missingDocs);
if (invalidUrls.length) console.log('Documentation URL invalid for %s', kind, invalidUrls); if (invalidUrls.length) console.log('Documentation URL invalid for %s', kind, invalidUrls);
if (missingDocs.length || invalidUrls.length) process.exit(1); if (missingDocs.length || invalidUrls.length) exitCode = 1;
}; };
(async () => { (async () => {
await checkLinks('credentials'); for (const packageName of packages) {
await checkLinks('nodes'); const baseDir = path.resolve(__dirname, '../../packages', packageName);
await Promise.all([checkLinks(baseDir, 'credentials'), checkLinks(baseDir, 'nodes')]);
if (exitCode !== 0) process.exit(exitCode);
}
})(); })();

View file

@ -27,10 +27,12 @@ jobs:
run: pnpm install --frozen-lockfile run: pnpm install --frozen-lockfile
- name: Build nodes-base - name: Build nodes-base
run: pnpm --filter @n8n/client-oauth2 --filter n8n-workflow --filter n8n-core --filter n8n-nodes-base build run: pnpm --filter @n8n/client-oauth2 --filter n8n-workflow --filter n8n-core --filter n8n-nodes-base --filter @n8n/n8n-nodes-langchain build
- run: npm install --prefix=.github/scripts --no-package-lock
- name: Test URLs - name: Test URLs
run: node scripts/validate-docs-links.js run: node .github/scripts/validate-docs-links.js
- name: Notify Slack on failure - name: Notify Slack on failure
uses: act10ns/slack@v2.0.0 uses: act10ns/slack@v2.0.0