forked from MetaMask/metamask-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsentry-publish.js
executable file
·133 lines (118 loc) · 3.44 KB
/
sentry-publish.js
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
#!/usr/bin/env node
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const { runCommand, runInShell } = require('./lib/run-command');
const { getVersion } = require('./lib/get-version');
const { BuildType } = require('./lib/build-type');
start().catch((error) => {
console.error(error);
process.exit(1);
});
async function start() {
const { argv } = yargs(hideBin(process.argv)).usage(
'$0 [options]',
'Publish a release to Sentry',
(_yargs) =>
_yargs
.option('org', {
default: 'metamask',
description: 'The Sentry organization',
type: 'string',
})
.option('project', {
default: 'metamask',
description: 'The Sentry project to publish',
type: 'string',
})
.option('build-type', {
default: BuildType.main,
description: 'The MetaMask extension build type',
choices: Object.values(BuildType),
})
.option('build-version', {
default: 0,
description: 'The MetaMask extension build version',
type: 'number',
}),
);
const { buildType, buildVersion, org, project } = argv;
process.env.SENTRY_ORG = org;
process.env.SENTRY_PROJECT = project;
const authWorked = await checkIfAuthWorks();
if (!authWorked) {
throw new Error(`Sentry auth failed`);
}
const version = getVersion(buildType, buildVersion);
// check if version exists or not
const versionAlreadyExists = await checkIfVersionExists(version);
// abort if versions exists
if (versionAlreadyExists) {
console.log(
`Version "${version}" already exists on Sentry, skipping version creation`,
);
} else {
// create sentry release
console.log(`creating Sentry release for "${version}"...`);
await runCommand('sentry-cli', ['releases', 'new', version]);
console.log(
`removing any existing files from Sentry release "${version}"...`,
);
await runCommand('sentry-cli', [
'releases',
'files',
version,
'delete',
'--all',
]);
}
// check if version has artifacts or not
const versionHasArtifacts =
versionAlreadyExists && (await checkIfVersionHasArtifacts(version));
if (versionHasArtifacts) {
console.log(
`Version "${version}" already has artifacts on Sentry, skipping sourcemap upload`,
);
return;
}
const additionalUploadArgs = [];
if (buildType !== BuildType.main) {
additionalUploadArgs.push('--dist-directory', `dist-${buildType}`);
}
// upload sentry source and sourcemaps
await runInShell('./development/sentry-upload-artifacts.sh', [
'--release',
version,
...additionalUploadArgs,
]);
}
async function checkIfAuthWorks() {
return await doesNotFail(() =>
runCommand('sentry-cli', ['releases', 'list']),
);
}
async function checkIfVersionExists(version) {
return await doesNotFail(() =>
runCommand('sentry-cli', ['releases', 'info', version]),
);
}
async function checkIfVersionHasArtifacts(version) {
const [artifact] = await runCommand('sentry-cli', [
'releases',
'files',
version,
'list',
]);
// When there's no artifacts, we get a response from the shell like this ['', '']
return artifact?.length > 0;
}
async function doesNotFail(asyncFn) {
try {
await asyncFn();
return true;
} catch (error) {
if (error.message === `Exited with code '1'`) {
return false;
}
throw error;
}
}