1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 03:20:23 +01:00
metamask-extension/development/sentry-publish.js
Olaf Tomalka 95c37e1ba3
feat: add yaml feature management (#18125)
* feat: add yaml feature management

Add yaml feature file per build type.
Also add method to parse yaml and set
enabled features env to true. The build
process will then replace any process.env[feature]
that exists on the config by its value

* chore: add example for desktop

* Added initial draft of build features

* [TMP] Sync between computers

* Is able to succesfully build stable extension with snaps feature

* Removing var context from builds.yml

* Add asssets to builds.yml

* Minor bug fixes and removing debug logs

* [WIP] Test changes

* Removed TODOs

* Fix regession bug

Also
* remove debug logs
* merge Variables.set and Variables.setMany with an overload

* Fix build, lint and a bunch of issues

* Update LavaMoat policies

* Re-add desktop build type

* Fix some tests

* Fix desktop build

* Define some env variables used by MV3

* Fix lint

* Fix remove-fenced-code tests

* Fix README typo

* Move new code

* Fix missing asset copy

* Move Jest env setup

* Fix path for test after rebase

* Fix code fences

* Fix fencing and LavaMoat policies

* Fix MMI code-fencing after rebase

* Fix MMI code fencing after merge

* Fix more MMI code fencing

---------

Co-authored-by: cryptotavares <joao.tavares@consensys.net>
Co-authored-by: Frederik Bolding <frederik.bolding@gmail.com>
Co-authored-by: Brad Decker <bhdecker84@gmail.com>
2023-04-25 16:32:51 +02:00

134 lines
3.5 KiB
JavaScript
Executable File

#!/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 { loadBuildTypesConfig } = 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: loadBuildTypesConfig().default,
description: 'The MetaMask extension build type',
choices: Object.keys(loadBuildTypesConfig().buildTypes),
})
.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 !== loadBuildTypesConfig().default) {
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;
}
}