import { readFile } from 'fs/promises'; import path from 'path'; import { cwd } from 'process'; import * as core from '@actions/core'; import { Command, Option } from 'commander'; import { YAMLDocumentValidator } from '~/yaml-document-validator/validator'; import { AUTHOR_SCHEMA } from './author.schema'; const program = new Command(); export default program .command('author:validate') .description('Validates the author YAML file') .argument('', 'path to an author.yaml') .addOption( new Option('--reporter ', 'reporter') .choices(['console', 'github']) .default('console'), ) .addOption(new Option('--reporter-level ', 'reporter level')) .action(async (filepaths: string[]) => { let issueCount = 0; for (const filepath of filepaths) { const validatorSource = { filepath, content: await readFile(path.resolve(cwd(), filepath), 'utf8'), }; const validator = new YAMLDocumentValidator( validatorSource, AUTHOR_SCHEMA, ); const issues = await validator.run({ strict: true, abortEarly: false }); if (issues.length > 0) { issues.forEach((issue) => { core.error(issue.message, { file: issue.filepath, startLine: issue.line, startColumn: issue.col, }); }); issueCount += issues.length; } else { core.debug(`${filepath}: no issues detected`); } } core.info( `${filepaths.length} files validated, ${issueCount} issues found`, ); if (issueCount > 0) { core.setFailed(`${issueCount} issues found`); } });