1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
metamask-extension/development/sentry-publish.js

87 lines
2.4 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
const childProcess = require('child_process');
const pify = require('pify');
const exec = pify(childProcess.exec, { multiArgs: true });
const VERSION = require('../dist/chrome/manifest.json').version; // eslint-disable-line import/no-unresolved
start().catch((error) => {
console.error(error);
process.exit(1);
});
2020-11-03 00:41:28 +01:00
async function start() {
const authWorked = await checkIfAuthWorks();
if (!authWorked) {
throw new Error(`Sentry auth failed`);
}
// check if version exists or not
const versionAlreadyExists = await checkIfVersionExists();
// 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`,
);
} else {
// create sentry release
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}`,
);
2020-11-03 00:41:28 +01:00
console.log(
`removing any existing files from Sentry release "${VERSION}"...`,
);
2020-11-03 00:41:28 +01:00
await exec(
`sentry-cli releases --org 'metamask' --project 'metamask' files ${VERSION} delete --all`,
);
}
// check if version has artifacts or not
2020-11-03 00:41:28 +01:00
const versionHasArtifacts =
versionAlreadyExists && (await checkIfVersionHasArtifacts());
if (versionHasArtifacts) {
2020-11-03 00:41:28 +01:00
console.log(
`Version "${VERSION}" already has artifacts on Sentry, skipping sourcemap upload`,
);
return;
}
// upload sentry source and sourcemaps
await exec(`./development/sentry-upload-artifacts.sh --release ${VERSION}`);
}
2020-11-03 00:41:28 +01:00
async function checkIfAuthWorks() {
const itWorked = await doesNotFail(async () => {
await exec(
`sentry-cli releases --org 'metamask' --project 'metamask' list`,
);
});
return itWorked;
}
2020-11-03 00:41:28 +01:00
async function checkIfVersionExists() {
const versionAlreadyExists = await doesNotFail(async () => {
2020-11-03 00:41:28 +01:00
await exec(
`sentry-cli releases --org 'metamask' --project 'metamask' info ${VERSION}`,
);
});
return versionAlreadyExists;
}
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`,
);
// When there's no artifacts, we get a response from the shell like this ['', '']
return artifacts[0] && artifacts[0].length > 0;
}
2020-11-03 00:41:28 +01:00
async function doesNotFail(asyncFn) {
try {
await asyncFn();
return true;
} catch (err) {
return false;
}
}