-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-release-notes.mjs
More file actions
104 lines (92 loc) · 3.49 KB
/
sync-release-notes.mjs
File metadata and controls
104 lines (92 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import path from 'node:path';
import { appendFile } from 'node:fs/promises';
import {
createSourceFailureSummary,
createSyncSummaryMarkdown,
fetchReleaseNotesSnapshot,
hasManagedReleaseNotesOutput,
materializeReleaseNotes,
resolveReleaseNotesConfig,
writeFetchedSnapshot,
} from './release-notes-sync-lib.mjs';
function parseArgs(argv) {
const options = {
repoRoot: undefined,
repository: undefined,
outputPath: undefined,
source: undefined,
localRepoRoot: undefined,
};
for (let index = 0; index < argv.length; index += 1) {
const argument = argv[index];
if (argument === '--repo-root') {
options.repoRoot = argv[index + 1];
index += 1;
} else if (argument.startsWith('--repo-root=')) {
options.repoRoot = argument.slice('--repo-root='.length);
} else if (argument === '--repository') {
options.repository = argv[index + 1];
index += 1;
} else if (argument.startsWith('--repository=')) {
options.repository = argument.slice('--repository='.length);
} else if (argument === '--output') {
options.outputPath = argv[index + 1];
index += 1;
} else if (argument.startsWith('--output=')) {
options.outputPath = argument.slice('--output='.length);
} else if (argument === '--source') {
options.source = argv[index + 1];
index += 1;
} else if (argument.startsWith('--source=')) {
options.source = argument.slice('--source='.length);
} else if (argument === '--local-repo-root') {
options.localRepoRoot = argv[index + 1];
index += 1;
} else if (argument.startsWith('--local-repo-root=')) {
options.localRepoRoot = argument.slice('--local-repo-root='.length);
} else if (argument === '--help' || argument === '-h') {
console.log(`Usage: node scripts/sync-release-notes.mjs [options]
Options:
--repo-root <path> Override the docs repository root
--repository <slug> Override the GitHub repository slug
--output <path> Override the fetched snapshot output file
--source <mode> Override the source mode: auto, github, or local
--local-repo-root <path>
Override the local release-notes repository root
-h, --help Show this help
`);
process.exit(0);
} else {
throw new Error(`Unknown argument: ${argument}`);
}
}
return options;
}
const options = parseArgs(process.argv.slice(2));
const env = {
...process.env,
...(options.repository ? { DOCS_RELEASE_NOTES_REPOSITORY: options.repository } : {}),
...(options.source ? { DOCS_RELEASE_NOTES_SOURCE: options.source } : {}),
...(options.localRepoRoot ? { DOCS_RELEASE_NOTES_LOCAL_REPO_ROOT: options.localRepoRoot } : {}),
};
const config = resolveReleaseNotesConfig({ repoRoot: options.repoRoot, env });
let summary;
try {
const snapshot = await fetchReleaseNotesSnapshot({ config });
const outputPath = options.outputPath
? path.resolve(config.repoRoot, options.outputPath)
: config.fetchOutputPath;
await writeFetchedSnapshot({ snapshot, outputPath });
const materialized = await materializeReleaseNotes({ snapshot, config });
summary = createSyncSummaryMarkdown({ snapshot, materialized });
} catch (error) {
if (!(config.allowStaleOnSourceError && await hasManagedReleaseNotesOutput(config))) {
throw error;
}
summary = createSourceFailureSummary({ config, error });
}
const summaryPath = process.env.GITHUB_STEP_SUMMARY;
if (summaryPath) {
await appendFile(summaryPath, `${summary}\n`);
}
console.log(summary.trim());