-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathindex.ts
125 lines (110 loc) · 3.3 KB
/
index.ts
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
import path from 'path';
import { validatePackageVariant } from './config';
import { downloadMongoDb } from '@mongodb-js/mongodb-downloader';
import { getArtifactUrl } from './evergreen';
import { triggerRelease } from './local';
import type { ReleaseCommand } from './release';
import { release } from './release';
import type { Config, PackageVariant } from './config';
import { updateJsonFeedCTA } from './download-center';
import Ajv from 'ajv';
export { getArtifactUrl, downloadMongoDb };
const validCommands: (ReleaseCommand | 'trigger-release' | 'update-cta')[] = [
'bump',
'compile',
'package',
'upload',
'draft',
'publish',
'sign',
'download-crypt-shared-library',
'download-and-list-artifacts',
'trigger-release',
'update-cta',
] as const;
const isValidCommand = (
cmd: string
): cmd is ReleaseCommand | 'trigger-release' | 'update-cta' =>
(validCommands as string[]).includes(cmd);
const getBuildConfig = (): Config => {
const config: Config = require(path.join(
__dirname,
'..',
'..',
'..',
'config',
'build.conf.js'
));
const cliBuildVariant = process.argv
.map((arg) => /^--build-variant=(.+)$/.exec(arg))
.filter(Boolean)[0];
if (cliBuildVariant) {
config.packageVariant = cliBuildVariant[1] as PackageVariant;
validatePackageVariant(config.packageVariant);
}
const ajv = new Ajv();
const validateSchema = ajv.compile(config.ctaConfigSchema);
if (!validateSchema(config.ctaConfig)) {
console.warn('CTA schema validation failed:', validateSchema.errors);
throw new Error('CTA validation failed, see above for details');
}
config.isDryRun ||= process.argv.includes('--dry-run');
config.useAuxiliaryPackagesOnly ||= process.argv.includes('--auxiliary');
return config;
};
if (require.main === module) {
Error.stackTraceLimit = 200;
(async () => {
const command = process.argv[2];
if (!isValidCommand(command)) {
throw new Error(
`USAGE: npm run evergreen-release <${validCommands.join('|')}>`
);
}
switch (command) {
case 'trigger-release':
await triggerRelease(process.argv.slice(3));
break;
case 'update-cta':
const {
ctaConfig,
downloadCenterAwsKey,
downloadCenterAwsSecret,
downloadCenterAwsKeyNew,
downloadCenterAwsSecretNew,
downloadCenterAwsSessionTokenNew,
isDryRun,
} = getBuildConfig();
if (!downloadCenterAwsKey || !downloadCenterAwsSecret) {
throw new Error('Missing AWS credentials for download center');
}
if (
!downloadCenterAwsKeyNew ||
!downloadCenterAwsSecretNew ||
!downloadCenterAwsSessionTokenNew
) {
throw new Error('Missing AWS credentials for new download center');
}
await updateJsonFeedCTA(
ctaConfig,
downloadCenterAwsKey,
downloadCenterAwsSecret,
downloadCenterAwsKeyNew,
downloadCenterAwsSecretNew,
downloadCenterAwsSessionTokenNew,
!!isDryRun
);
break;
default:
const config = getBuildConfig();
await release(command, config);
break;
}
})().then(
() => process.exit(0),
(err) =>
process.nextTick(() => {
throw err;
})
);
}