first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env node
|
||||
import { promises as fs } from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const POPULARITY_ENDPOINT =
|
||||
process.env.NODE_POPULARITY_ENDPOINT ||
|
||||
'https://internal-production.app.n8n.cloud/webhook/nodes-popularity-scores';
|
||||
const FAIL_ON_ERROR = process.env.N8N_FAIL_ON_POPULARITY_FETCH_ERROR === 'true';
|
||||
const DATA_DIR = path.join(__dirname, '..', 'data');
|
||||
const OUTPUT_FILE = path.join(DATA_DIR, 'node-popularity.json');
|
||||
|
||||
async function ensureDataDir() {
|
||||
try {
|
||||
await fs.mkdir(DATA_DIR, { recursive: true });
|
||||
} catch (error) {
|
||||
// Directory might already exist, that's fine
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchPopularityData() {
|
||||
try {
|
||||
console.log('Fetching node popularity data from:', POPULARITY_ENDPOINT);
|
||||
const response = await fetch(POPULARITY_ENDPOINT, {
|
||||
signal: AbortSignal.timeout(5000),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log(`Successfully fetched popularity data for ${data.length} nodes`);
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.warn('Failed to fetch node popularity data:', error.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function getExistingData() {
|
||||
try {
|
||||
const content = await fs.readFile(OUTPUT_FILE, 'utf-8');
|
||||
return JSON.parse(content);
|
||||
} catch (error) {
|
||||
// File doesn't exist or is invalid
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function savePopularityData(data) {
|
||||
await ensureDataDir();
|
||||
await fs.writeFile(OUTPUT_FILE, JSON.stringify(data, null, 2));
|
||||
console.log(`Saved popularity data to ${OUTPUT_FILE} with ${data.length} nodes`);
|
||||
}
|
||||
|
||||
async function fallbackToExistingData() {
|
||||
const existingData = await getExistingData();
|
||||
|
||||
if (existingData) {
|
||||
console.log('Using existing cached data - no changes made');
|
||||
// Don't regenerate the file, keep the existing one
|
||||
} else {
|
||||
console.error('No data available - neither from API nor cache');
|
||||
console.error('Creating empty placeholder file to avoid build failure');
|
||||
await savePopularityData([]);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// Try to fetch fresh data
|
||||
const freshData = await fetchPopularityData();
|
||||
|
||||
if (freshData && Array.isArray(freshData) && freshData.length > 0) {
|
||||
// Save the fresh data
|
||||
await savePopularityData(freshData);
|
||||
} else {
|
||||
// Fetching failed
|
||||
if (FAIL_ON_ERROR) {
|
||||
console.error('N8N_FAIL_ON_POPULARITY_FETCH_ERROR is set - failing build');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Check if we have existing data
|
||||
console.log('API unavailable, checking for existing cached data');
|
||||
await fallbackToExistingData();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in fetch-node-popularity script:', error);
|
||||
|
||||
if (FAIL_ON_ERROR) {
|
||||
console.error('N8N_FAIL_ON_POPULARITY_FETCH_ERROR is set - failing build');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await fallbackToExistingData();
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user