2018-04-03 21:36:46 +02:00
|
|
|
#!/usr/bin/env node
|
2021-02-04 19:15:23 +01:00
|
|
|
const childProcess = require('child_process');
|
|
|
|
const pify = require('pify');
|
2020-08-18 21:18:25 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const exec = pify(childProcess.exec, { multiArgs: true });
|
|
|
|
const VERSION = require('../dist/chrome/manifest.json').version; // eslint-disable-line import/no-unresolved
|
2018-04-03 21:36:46 +02:00
|
|
|
|
2020-11-17 02:37:15 +01:00
|
|
|
start().catch((error) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
console.error(error);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2018-04-03 21:36:46 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async function start() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const authWorked = await checkIfAuthWorks();
|
2018-04-03 21:36:46 +02:00
|
|
|
if (!authWorked) {
|
2021-02-04 19:15:23 +01:00
|
|
|
throw new Error(`Sentry auth failed`);
|
2018-04-03 21:36:46 +02:00
|
|
|
}
|
|
|
|
// check if version exists or not
|
2021-02-04 19:15:23 +01:00
|
|
|
const versionAlreadyExists = await checkIfVersionExists();
|
2018-04-03 21:36:46 +02:00
|
|
|
// abort if versions exists
|
|
|
|
if (versionAlreadyExists) {
|
2020-11-03 00:41:28 +01:00
|
|
|
console.log(
|
|
|
|
`Version "${VERSION}" already exists on Sentry, skipping version creation`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-10 16:24:25 +02:00
|
|
|
} else {
|
2019-07-31 22:17:11 +02:00
|
|
|
// create sentry release
|
2021-02-04 19:15:23 +01:00
|
|
|
console.log(`creating Sentry release for "${VERSION}"...`);
|
2020-11-03 00:41:28 +01:00
|
|
|
await exec(
|
|
|
|
`sentry-cli releases --org 'metamask' --project 'metamask' new ${VERSION}`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
console.log(
|
|
|
|
`removing any existing files from Sentry release "${VERSION}"...`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
await exec(
|
|
|
|
`sentry-cli releases --org 'metamask' --project 'metamask' files ${VERSION} delete --all`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-04-03 21:36:46 +02:00
|
|
|
}
|
|
|
|
|
2018-10-10 16:24:25 +02:00
|
|
|
// check if version has artifacts or not
|
2020-11-03 00:41:28 +01:00
|
|
|
const versionHasArtifacts =
|
2021-02-04 19:15:23 +01:00
|
|
|
versionAlreadyExists && (await checkIfVersionHasArtifacts());
|
2020-08-14 13:47:43 +02:00
|
|
|
if (versionHasArtifacts) {
|
2020-11-03 00:41:28 +01:00
|
|
|
console.log(
|
|
|
|
`Version "${VERSION}" already has artifacts on Sentry, skipping sourcemap upload`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
return;
|
2018-10-10 16:24:25 +02:00
|
|
|
}
|
2020-08-14 13:47:43 +02:00
|
|
|
|
|
|
|
// upload sentry source and sourcemaps
|
2021-02-04 19:15:23 +01:00
|
|
|
await exec(`./development/sentry-upload-artifacts.sh --release ${VERSION}`);
|
2018-04-03 21:36:46 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async function checkIfAuthWorks() {
|
2018-04-03 21:36:46 +02:00
|
|
|
const itWorked = await doesNotFail(async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
await exec(
|
|
|
|
`sentry-cli releases --org 'metamask' --project 'metamask' list`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return itWorked;
|
2018-04-03 21:36:46 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async function checkIfVersionExists() {
|
2018-04-03 21:36:46 +02:00
|
|
|
const versionAlreadyExists = await doesNotFail(async () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
await exec(
|
|
|
|
`sentry-cli releases --org 'metamask' --project 'metamask' info ${VERSION}`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
return versionAlreadyExists;
|
2018-04-03 21:36:46 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async function checkIfVersionHasArtifacts() {
|
|
|
|
const artifacts = await exec(
|
|
|
|
`sentry-cli releases --org 'metamask' --project 'metamask' files ${VERSION} list`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-10 16:24:25 +02:00
|
|
|
// When there's no artifacts, we get a response from the shell like this ['', '']
|
2021-02-04 19:15:23 +01:00
|
|
|
return artifacts[0] && artifacts[0].length > 0;
|
2018-10-10 16:24:25 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async function doesNotFail(asyncFn) {
|
2018-04-03 21:36:46 +02:00
|
|
|
try {
|
2021-02-04 19:15:23 +01:00
|
|
|
await asyncFn();
|
|
|
|
return true;
|
2018-04-03 21:36:46 +02:00
|
|
|
} catch (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return false;
|
2018-04-03 21:36:46 +02:00
|
|
|
}
|
|
|
|
}
|