Repository navigation
Expand file tree
/
Copy pathcli.mjs
More file actions
252 lines (246 loc) · 7.73 KB
/
Copy pathcli.mjs
File metadata and controls
252 lines (246 loc) · 7.73 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import { pathToFileURL } from 'node:url';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { assertArtifact } from './assert-artifact.mjs';
import { assertPeerMatrix } from './assert-peer-matrix.mjs';
import { assertReleaseParity } from './assert-release-parity.mjs';
import { printCanaryReport } from './canary-report.mjs';
import { writeCanaryStatus } from './canary-status.mjs';
import { printSanityCompatEligibility } from './eligibility.mjs';
import { packCompatibilityArtifact } from './pack.mjs';
import { preparePublish } from './prepare-publish.mjs';
import { printConsumerMatrix } from './print-consumer-majors.mjs';
import { runCompatibilityPipeline } from './run.mjs';
import { testConsumers } from './test-consumer.mjs';
export function runCli(args = hideBin(process.argv)) {
return yargs(args)
.scriptName('angular-compat')
.command(
'assert',
'Validate the configured Angular compatibility peer matrix.',
(command) => command,
() => assertPeerMatrix(),
)
.command(
'artifact',
'Validate the packed compatibility tarball shape.',
(command) => addTarballOption(command),
(argv) => assertArtifact(toOptions(argv)),
)
.command(
'affected',
'Decide whether Sanity compatibility jobs should run.',
(command) =>
command
.option('base-ref', {
describe: 'Git base ref to compare against.',
type: 'string',
})
.option('head-ref', {
describe: 'Git head ref to compare.',
type: 'string',
default: 'HEAD',
})
.option('changed-file', {
describe:
'Changed file path to evaluate without reading git diff. Can be repeated.',
type: 'string',
array: true,
})
.option('force', {
describe: 'Force compatibility jobs to run.',
type: 'boolean',
default: false,
})
.option('github-output', {
describe: 'GitHub Actions output file to write run/reason values.',
type: 'string',
}),
(argv) =>
printSanityCompatEligibility({
baseRef: argv.baseRef,
changedFiles: argv.changedFile,
force: argv.force,
githubOutput: argv.githubOutput,
headRef: argv.headRef,
}),
)
.command(
'canary-status',
'Write an advisory Angular canary status JSON file.',
(command) =>
command
.option('version-set-json', {
describe: 'JSON representation of the canary version set.',
type: 'string',
demandOption: true,
})
.option('exit-code', {
describe: 'Exit code from the canary compatibility command.',
type: 'number',
demandOption: true,
})
.option('log', {
describe: 'Path to the captured canary compatibility log.',
type: 'string',
demandOption: true,
})
.option('metadata', {
describe:
'Path to structured metadata from the canary compatibility command.',
type: 'string',
})
.option('out', {
describe: 'Path where the canary status JSON should be written.',
type: 'string',
demandOption: true,
}),
(argv) =>
writeCanaryStatus({
exitCode: argv.exitCode,
logPath: argv.log,
metadataPath: argv.metadata,
outPath: argv.out,
versionSetJson: argv.versionSetJson,
}),
)
.command(
'canary-report',
'Render the advisory Angular canary report from status artifacts.',
(command) =>
command
.option('status-dir', {
describe: 'Directory containing canary status JSON artifacts.',
type: 'string',
default: '.compat/canary-status',
})
.option('download-outcome', {
describe: 'Outcome from the artifact download step.',
type: 'string',
default: 'success',
})
.option('run-url', {
describe: 'Workflow run URL to include in the rendered report.',
type: 'string',
})
.option('workflow-name', {
describe: 'Workflow name to include in the rendered report.',
type: 'string',
})
.option('run-number', {
describe: 'Workflow run number to include in the rendered report.',
type: 'number',
}),
(argv) =>
printCanaryReport({
downloadOutcome: argv.downloadOutcome,
runNumber: argv.runNumber,
runUrl: argv.runUrl,
statusDir: argv.statusDir,
workflowName: argv.workflowName,
}),
)
.command(
'matrix',
'Print the stable or canary Angular compatibility matrix as JSON.',
(command) =>
command.option('canary', {
describe:
'Print advisory canary version sets instead of stable consumers.',
type: 'boolean',
default: false,
}),
(argv) => printConsumerMatrix(toOptions(argv)),
)
.command(
'pack',
'Build and pack the compatibility-tested library artifact.',
(command) => command,
() => packCompatibilityArtifact(),
)
.command(
'prepare-publish',
'Prepare a built package manifest for preview or release publishing.',
(command) =>
command
.option('package-root', {
describe: 'Built package directory containing package.json.',
type: 'string',
})
.option('package-version', {
describe: 'Optional semver version to write before publishing.',
type: 'string',
}),
(argv) =>
preparePublish({
packageRoot: argv.packageRoot,
version: argv.packageVersion,
}),
)
.command(
'release-parity',
'Assert that release publishing uses the compatibility pipeline.',
(command) => command,
() => assertReleaseParity(),
)
.command(
'run',
'Run the full compatibility pipeline.',
(command) => command,
() => runCompatibilityPipeline(),
)
.command(
'test',
'Test the packed artifact in generated Angular consumers.',
(command) =>
addTarballOption(command)
.option('angular', {
describe:
'Run the latest configured version set for the given Angular major.',
type: 'number',
})
.option('set', {
describe: 'Run one configured compatibility version set by id.',
type: 'string',
})
.option('skip-runtime', {
describe: 'Skip the Playwright runtime smoke test.',
type: 'boolean',
default: false,
})
.option('metadata-out', {
describe:
'Path where generated consumer metadata should be written.',
type: 'string',
})
.conflicts('angular', 'set'),
(argv) => testConsumers(toOptions(argv)),
)
.demandCommand(1, 'Specify a compatibility command.')
.recommendCommands()
.strict()
.help()
.parse();
}
function addTarballOption(command) {
return command.option('tarball', {
describe: 'Path to a packed .tgz artifact.',
type: 'string',
});
}
function toOptions(argv) {
return {
angular: argv.angular,
canary: argv.canary,
metadataOut: argv.metadataOut,
set: argv.set,
skipRuntime: argv.skipRuntime,
tarball: argv.tarball,
};
}
if (
process.argv[1] &&
import.meta.url === pathToFileurl(/sitelet?url=https%3A%2F%2Fgithub.com%2Flimitless-angular%2Flimitless-angular%2Fblob%2Fmain%2Ftools%2Fangular-compat%2Fprocess.argv%5B1%5D).href
) {
runCli();
}