From 6506c5ff5da63ca51fa237d3bcb02d0bf7b55eb5 Mon Sep 17 00:00:00 2001 From: Jason Stirnaman Date: Sat, 5 Jul 2025 19:32:45 -0500 Subject: [PATCH] chore(ci): Cleanup JS --- .github/workflows/audit-documentation.yml | 4 -- eslint.config.js | 13 ++++ helper-scripts/common/validate-tags.js | 69 ++++++++++++------- .../audit-cli-documentation.js | 18 +++-- 4 files changed, 68 insertions(+), 36 deletions(-) diff --git a/.github/workflows/audit-documentation.yml b/.github/workflows/audit-documentation.yml index dfbbac557..742f31c65 100644 --- a/.github/workflows/audit-documentation.yml +++ b/.github/workflows/audit-documentation.yml @@ -12,10 +12,6 @@ on: required: false type: boolean default: false - - schedule: - # Run weekly on Mondays at 9 AM UTC for all audits - - cron: '0 9 * * 1' jobs: cli-3-core: diff --git a/eslint.config.js b/eslint.config.js index 23104f7a1..18764ab0e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -95,6 +95,19 @@ export default [ }, }, + // Configuration for Node.js helper scripts + { + files: ['helper-scripts/**/*.js'], + languageOptions: { + globals: { + ...globals.node, + }, + }, + rules: { + // Node.js specific rules + }, + }, + // Configuration for specific file patterns { files: ['**/*.js'], diff --git a/helper-scripts/common/validate-tags.js b/helper-scripts/common/validate-tags.js index 3f21866a1..e304bc4fe 100644 --- a/helper-scripts/common/validate-tags.js +++ b/helper-scripts/common/validate-tags.js @@ -6,11 +6,6 @@ */ import { spawn } from 'child_process'; -import { dirname, join } from 'path'; -import { fileURLToPath } from 'url'; - -const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); /** * Execute a command and return the output @@ -37,7 +32,9 @@ function execCommand(command, args = [], cwd = process.cwd()) { if (code === 0) { resolve(stdout.trim()); } else { - reject(new Error(`Command failed: ${command} ${args.join(' ')}\n${stderr}`)); + reject( + new Error(`Command failed: ${command} ${args.join(' ')}\n${stderr}`) + ); } }); }); @@ -50,8 +47,12 @@ function execCommand(command, args = [], cwd = process.cwd()) { */ async function getGitTags(repoPath = process.cwd()) { try { - const output = await execCommand('git', ['tag', '--list', '--sort=-version:refname'], repoPath); - return output ? output.split('\n').filter(tag => tag.trim()) : []; + const output = await execCommand( + 'git', + ['tag', '--list', '--sort=-version:refname'], + repoPath + ); + return output ? output.split('\n').filter((tag) => tag.trim()) : []; } catch (error) { throw new Error(`Failed to get git tags: ${error.message}`); } @@ -76,12 +77,16 @@ async function isValidTag(version, repoPath = process.cwd()) { * Validate multiple version tags * @param {string[]} versions - Array of version strings to validate * @param {string} repoPath - Path to the git repository - * @returns {Promise<{valid: boolean, errors: string[], availableTags: string[]}>} + * @returns {Promise<{ + * valid: boolean, + * errors: string[], + * availableTags: string[] + * }>} Validation result */ async function validateTags(versions, repoPath = process.cwd()) { const errors = []; const availableTags = await getGitTags(repoPath); - + for (const version of versions) { if (version && version !== 'local' && !availableTags.includes(version)) { errors.push(`Version '${version}' is not a valid git tag`); @@ -91,7 +96,7 @@ async function validateTags(versions, repoPath = process.cwd()) { return { valid: errors.length === 0, errors, - availableTags: availableTags.slice(0, 10) // Return top 10 most recent tags + availableTags: availableTags.slice(0, 10), // Return top 10 most recent tags }; } @@ -101,26 +106,32 @@ async function validateTags(versions, repoPath = process.cwd()) { * @param {string} previousVersion - Previous version (optional) * @param {string} repoPath - Path to the git repository */ -async function validateVersionInputs(version, previousVersion = null, repoPath = process.cwd()) { +async function validateVersionInputs( + version, + previousVersion = null, + repoPath = process.cwd() +) { const versionsToCheck = [version]; if (previousVersion) { versionsToCheck.push(previousVersion); } const validation = await validateTags(versionsToCheck, repoPath); - + if (!validation.valid) { console.error('\nāŒ Version validation failed:'); - validation.errors.forEach(error => console.error(` - ${error}`)); - + validation.errors.forEach((error) => console.error(` - ${error}`)); + if (validation.availableTags.length > 0) { console.error('\nšŸ“‹ Available tags (most recent first):'); - validation.availableTags.forEach(tag => console.error(` - ${tag}`)); + validation.availableTags.forEach((tag) => console.error(` - ${tag}`)); } else { console.error('\nšŸ“‹ No git tags found in repository'); } - - console.error('\nšŸ’” Tip: Use "local" for development/testing with local containers'); + + console.error( + '\nšŸ’” Tip: Use "local" for development/testing with local containers' + ); process.exit(1); } @@ -134,10 +145,16 @@ async function validateVersionInputs(version, previousVersion = null, repoPath = */ async function getRepositoryRoot(startPath = process.cwd()) { try { - const output = await execCommand('git', ['rev-parse', '--show-toplevel'], startPath); + const output = await execCommand( + 'git', + ['rev-parse', '--show-toplevel'], + startPath + ); return output; } catch (error) { - throw new Error(`Not a git repository or git not available: ${error.message}`); + throw new Error( + `Not a git repository or git not available: ${error.message}` + ); } } @@ -146,24 +163,26 @@ export { isValidTag, validateTags, validateVersionInputs, - getRepositoryRoot + getRepositoryRoot, }; // CLI usage when run directly if (import.meta.url === `file://${process.argv[1]}`) { const args = process.argv.slice(2); - + if (args.length === 0) { console.log('Usage: node validate-tags.js [previous-version]'); console.log('Examples:'); console.log(' node validate-tags.js v3.0.0'); console.log(' node validate-tags.js v3.0.0 v2.9.0'); - console.log(' node validate-tags.js local # Special case for development'); + console.log( + ' node validate-tags.js local # Special case for development' + ); process.exit(1); } const [version, previousVersion] = args; - + try { const repoRoot = await getRepositoryRoot(); await validateVersionInputs(version, previousVersion, repoRoot); @@ -172,4 +191,4 @@ if (import.meta.url === `file://${process.argv[1]}`) { console.error(`Error: ${error.message}`); process.exit(1); } -} \ No newline at end of file +} diff --git a/helper-scripts/influxdb3-monolith/audit-cli-documentation.js b/helper-scripts/influxdb3-monolith/audit-cli-documentation.js index b9bea8991..74e1af565 100755 --- a/helper-scripts/influxdb3-monolith/audit-cli-documentation.js +++ b/helper-scripts/influxdb3-monolith/audit-cli-documentation.js @@ -11,7 +11,10 @@ import { promises as fs } from 'fs'; import { homedir } from 'os'; import { join, dirname } from 'path'; import { fileURLToPath } from 'url'; -import { validateVersionInputs, getRepositoryRoot } from '../common/validate-tags.js'; +import { + validateVersionInputs, + getRepositoryRoot, +} from '../common/validate-tags.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); @@ -107,7 +110,7 @@ class CLIDocAuditor { coreToken = (await fs.readFile(this.coreTokenFile, 'utf8')).trim(); } } - } catch (e) { + } catch { // Token file doesn't exist or can't be read } @@ -120,7 +123,7 @@ class CLIDocAuditor { ).trim(); } } - } catch (e) { + } catch { // Token file doesn't exist or can't be read } @@ -683,9 +686,10 @@ Replace the following: if (missingCount === 0) { output += 'No missing documentation files detected.\n'; } else { - output += `\n### Quick Actions\n\n`; - output += `Copy and paste these commands to create missing documentation:\n\n`; - output += `\`\`\`bash\n`; + output += '\n### Quick Actions\n\n'; + output += + 'Copy and paste these commands to create missing documentation:\n\n'; + output += '```bash\n'; for (const doc of missingDocs) { const relativePatch = join( 'helper-scripts/output/cli-audit/patches', @@ -696,7 +700,7 @@ Replace the following: output += `mkdir -p $(dirname ${doc.file})\n`; output += `cp ${relativePatch} ${doc.file}\n\n`; } - output += `\`\`\`\n`; + output += '```\n'; } output += '\n';