2018-04-03 21:36:46 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
const pify = require('pify')
|
|
|
|
const exec = pify(require('child_process').exec, { multiArgs: true })
|
2019-11-14 14:17:55 +01:00
|
|
|
const VERSION = require('../dist/chrome/manifest.json').version // eslint-disable-line import/no-unresolved
|
2018-04-03 21:36:46 +02:00
|
|
|
|
|
|
|
start().catch(console.error)
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
async function start () {
|
2018-04-03 21:36:46 +02:00
|
|
|
const authWorked = await checkIfAuthWorks()
|
|
|
|
if (!authWorked) {
|
|
|
|
console.log(`Sentry auth failed...`)
|
|
|
|
}
|
|
|
|
// check if version exists or not
|
|
|
|
const versionAlreadyExists = await checkIfVersionExists()
|
|
|
|
// abort if versions exists
|
|
|
|
if (versionAlreadyExists) {
|
2018-10-10 16:24:25 +02:00
|
|
|
console.log(`Version "${VERSION}" already exists on Sentry, skipping version creation`)
|
|
|
|
} else {
|
2019-07-31 22:17:11 +02:00
|
|
|
// create sentry release
|
2018-10-10 16:24:25 +02:00
|
|
|
console.log(`creating Sentry release for "${VERSION}"...`)
|
|
|
|
await exec(`sentry-cli releases --org 'metamask' --project 'metamask' new ${VERSION}`)
|
|
|
|
console.log(`removing any existing files from Sentry release "${VERSION}"...`)
|
|
|
|
await exec(`sentry-cli releases --org 'metamask' --project 'metamask' 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
|
|
|
|
const versionHasArtifacts = versionAlreadyExists && await checkIfVersionHasArtifacts()
|
|
|
|
if (!versionHasArtifacts) {
|
|
|
|
// upload sentry source and sourcemaps
|
2019-12-05 22:59:48 +01:00
|
|
|
await exec(`./development/sentry-upload-artifacts.sh --release ${VERSION}`)
|
2018-10-10 16:24:25 +02:00
|
|
|
} else {
|
|
|
|
console.log(`Version "${VERSION}" already has artifacts on Sentry, skipping sourcemap upload`)
|
|
|
|
}
|
2018-04-03 21:36:46 +02:00
|
|
|
}
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
async function checkIfAuthWorks () {
|
2018-04-03 21:36:46 +02:00
|
|
|
const itWorked = await doesNotFail(async () => {
|
|
|
|
await exec(`sentry-cli releases --org 'metamask' --project 'metamask' list`)
|
|
|
|
})
|
|
|
|
return itWorked
|
|
|
|
}
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
async function checkIfVersionExists () {
|
2018-04-03 21:36:46 +02:00
|
|
|
const versionAlreadyExists = await doesNotFail(async () => {
|
|
|
|
await exec(`sentry-cli releases --org 'metamask' --project 'metamask' info ${VERSION}`)
|
|
|
|
})
|
|
|
|
return versionAlreadyExists
|
|
|
|
}
|
|
|
|
|
2018-10-10 16:24:25 +02: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
|
|
|
|
}
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
async function doesNotFail (asyncFn) {
|
2018-04-03 21:36:46 +02:00
|
|
|
try {
|
|
|
|
await asyncFn()
|
|
|
|
return true
|
|
|
|
} catch (err) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|