2018-04-03 21:36:46 +02:00
|
|
|
#!/usr/bin/env node
|
2021-02-04 19:15:23 +01:00
|
|
|
const VERSION = require('../dist/chrome/manifest.json').version; // eslint-disable-line import/no-unresolved
|
2021-05-19 19:24:45 +02:00
|
|
|
const { runCommand, runInShell } = require('./lib/run-command');
|
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-05-18 18:26:22 +02:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
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}"...`);
|
2021-05-19 19:24:45 +02:00
|
|
|
await runCommand('sentry-cli', ['releases', 'new', VERSION]);
|
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
|
|
|
);
|
2021-05-19 19:24:45 +02:00
|
|
|
await runCommand('sentry-cli', [
|
|
|
|
'releases',
|
|
|
|
'files',
|
|
|
|
VERSION,
|
|
|
|
'delete',
|
|
|
|
'--all',
|
|
|
|
]);
|
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-05-19 19:24:45 +02:00
|
|
|
await runInShell('./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() {
|
2021-05-19 19:24:45 +02:00
|
|
|
return await doesNotFail(() =>
|
|
|
|
runCommand('sentry-cli', ['releases', 'list']),
|
|
|
|
);
|
2018-04-03 21:36:46 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async function checkIfVersionExists() {
|
2021-05-19 19:24:45 +02:00
|
|
|
return await doesNotFail(() =>
|
|
|
|
runCommand('sentry-cli', ['releases', 'info', VERSION]),
|
|
|
|
);
|
2018-04-03 21:36:46 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async function checkIfVersionHasArtifacts() {
|
2021-05-19 19:24:45 +02:00
|
|
|
const [artifact] = await runCommand('sentry-cli', [
|
|
|
|
'releases',
|
|
|
|
'files',
|
|
|
|
VERSION,
|
|
|
|
'list',
|
|
|
|
]);
|
2018-10-10 16:24:25 +02:00
|
|
|
// When there's no artifacts, we get a response from the shell like this ['', '']
|
2021-05-19 19:24:45 +02:00
|
|
|
return artifact?.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;
|
2021-05-19 19:24:45 +02:00
|
|
|
} catch (error) {
|
|
|
|
if (error.message === `Exited with code '1'`) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
throw error;
|
2018-04-03 21:36:46 +02:00
|
|
|
}
|
|
|
|
}
|