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 })
|
|
|
|
const VERSION = require('../dist/chrome/manifest.json').version
|
|
|
|
|
|
|
|
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) {
|
|
|
|
console.log(`Version "${VERSION}" already exists on Sentry, aborting sourcemap upload.`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// create sentry release
|
|
|
|
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`)
|
|
|
|
// upload sentry source and sourcemaps
|
|
|
|
console.log(`uploading source files Sentry release "${VERSION}"...`)
|
|
|
|
await exec(`for FILEPATH in ./dist/chrome/*.js; do [ -e $FILEPATH ] || continue; export FILE=\`basename $FILEPATH\` && echo uploading $FILE && sentry-cli releases --org 'metamask' --project 'metamask' files ${VERSION} upload $FILEPATH metamask/$FILE; done;`)
|
|
|
|
console.log(`uploading sourcemaps Sentry release "${VERSION}"...`)
|
|
|
|
await exec(`sentry-cli releases --org 'metamask' --project 'metamask' files ${VERSION} upload-sourcemaps ./dist/sourcemaps/ --url-prefix 'sourcemaps'`)
|
|
|
|
console.log('all done!')
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
|
}
|
|
|
|
}
|