-
Notifications
You must be signed in to change notification settings - Fork 490
Validate change-notes as a PR check #4116
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
base: main
Are you sure you want to change the base?
Changes from all commits
b1c1bbb
a691c16
f60f4d9
f45ef9d
6041eff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| #!/usr/bin/env npx tsx | ||
|
|
||
| import * as fs from "node:fs"; | ||
| import { pathToFileURL } from "node:url"; | ||
| import { parseArgs } from "node:util"; | ||
|
|
||
| import { isValidChangenoteFile } from "./changelog/validate.mjs"; | ||
| import { isValidAllChangenoteFiles } from "./changelog/validate.mjs"; | ||
| import { CHANGENOTES_DIR } from "./config"; | ||
|
|
||
| const entryPoint = process.argv[1]; | ||
| if (entryPoint && import.meta.url === pathToFileURL(entryPoint).href) { | ||
|
|
@@ -20,34 +22,35 @@ function main(): number { | |
| allowPositionals: true, | ||
| strict: true, | ||
| }); | ||
| const [command, ...paths] = positionals; | ||
| const [command] = positionals; | ||
| switch (command) { | ||
| case undefined: | ||
| case "help": | ||
| return usage(); | ||
| case "validate": | ||
| return validate(paths); | ||
| return validate(); | ||
| default: | ||
| console.error(`Unknown command: ${command}`); | ||
| return 1; | ||
| } | ||
| } | ||
|
|
||
| function usage(): number { | ||
| console.log(`Usage: changenotes.mts validate <path> [<path> ...]`); | ||
| console.log(`Usage: changenotes.mts validate`); | ||
| return 0; | ||
| } | ||
|
|
||
| function validate(paths: string[]): number { | ||
| let valid = true; | ||
| if (paths.length === 0) { | ||
| console.error("error: no paths provided (see 'help' command for usage)"); | ||
| return 1; | ||
| } | ||
| for (const path of paths) { | ||
| if (!isValidChangenoteFile(path)) { | ||
| valid = false; | ||
| function validate(): number { | ||
| try { | ||
| if (isValidAllChangenoteFiles(fs.readdirSync(CHANGENOTES_DIR))) { | ||
| console.log(`All changenote files in '${CHANGENOTES_DIR}' are valid.`); | ||
| return 0; | ||
| } | ||
| } catch (error) { | ||
| console.error( | ||
| `Failed to read change-notes directory (${CHANGENOTES_DIR})`, | ||
| error, | ||
|
Comment on lines
+45
to
52
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: Be consistent in the log messages with "changenote(s)" vs "change-note(s)" and using single quotes vs parentheses to delimit the path. For the former, either "changenote(s)" or "change note(s)" is fine, but I'd avoid "change-note(s)". For the latter, we generally use single quotes in the codebase. |
||
| ); | ||
| } | ||
| return valid ? 0 : 1; | ||
| return 1; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.