1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00
metamask-extension/development/sentry-publish.js
Mark Stacey 37dc19a352
Migrate Sentry settings to environment variables (#11085)
Sentry is now configured with environment variables, rather than with
hard-coded values. This makes it easier to test Sentry functionality
using a different Sentry account, as we did recently during QA of
v9.5.1.

The only change for the normal build process is the introduction of the
`SENTRY_DSN_DEV` variable, which can be set via `.metamaskrc` or via an
environment variable. This determines where error reports are sent. It
still defaults to our team Sentry account's `metamask-testing` project.

The `sentry:publish` script now requires SENTRY_ORG and SENTRY_PROJECT
to be set in order to publish release artifacts. The CircleCI
configuration has been updated with these values, so it should act the
same as it did before. Previously we had used a CLI flag to specify the
organization and project, but Sentry already natively supports these
environment variables [1].

[1]: https://docs.sentry.io/product/cli/configuration/#configuration-values
2021-05-18 13:56:22 -02:30

83 lines
2.4 KiB
JavaScript

#!/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);
});
async function start() {
if (!process.env.SENTRY_ORG) {
throw new Error('Missing required "SENTRY_ORG" environment variable');
} else if (!process.env.SENTRY_PROJECT) {
throw new Error('Missing required "SENTRY_PROJECT" environment variable');
}
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) {
console.log(
`Version "${VERSION}" already exists on Sentry, skipping version creation`,
);
} else {
// create sentry release
console.log(`creating Sentry release for "${VERSION}"...`);
await exec(`sentry-cli releases new ${VERSION}`);
console.log(
`removing any existing files from Sentry release "${VERSION}"...`,
);
await exec(`sentry-cli releases files ${VERSION} delete --all`);
}
// check if version has artifacts or not
const versionHasArtifacts =
versionAlreadyExists && (await checkIfVersionHasArtifacts());
if (versionHasArtifacts) {
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}`);
}
async function checkIfAuthWorks() {
const itWorked = await doesNotFail(async () => {
await exec(`sentry-cli releases list`);
});
return itWorked;
}
async function checkIfVersionExists() {
const versionAlreadyExists = await doesNotFail(async () => {
await exec(`sentry-cli releases info ${VERSION}`);
});
return versionAlreadyExists;
}
async function checkIfVersionHasArtifacts() {
const artifacts = await exec(`sentry-cli releases files ${VERSION} list`);
// When there's no artifacts, we get a response from the shell like this ['', '']
return artifacts[0] && artifacts[0].length > 0;
}
async function doesNotFail(asyncFn) {
try {
await asyncFn();
return true;
} catch (err) {
return false;
}
}