Skip to content

Commit

Permalink
feat(publish): enable upload sourcemaps
Browse files Browse the repository at this point in the history
fix #80
  • Loading branch information
lgaticaq committed Mar 27, 2020
1 parent a16679d commit f63fa5d
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 28 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
| `environment` | Sentry environment. Optional for deploy. Default production |
| `deployName` | Deploy name. Optional for deploy |
| `deployUrl` | Deploy url. Optional for deploy |
| `sourcemaps` | Directory with sourcemaps. Example `dist`. Optional for upload sourcemaps |
| `urlPrefix` | URL prefix for sourcemaps. Example `~/dist`. Optional for upload sourcemaps |
| `rewrite` | Boolean to indicate rewrite sourcemaps. Default `false`. Optional for upload sourcemaps |

### Examples

Expand All @@ -82,6 +85,33 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
}
```

#### Upload sourcemaps
```json
{
"plugins": [
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git",
"@semantic-release/gitlab",
[
"@semantic-release/exec",
{
"prepareCmd": "npm run build"
}
],
[
"@eclass/semantic-release-sentry-releases",
{
"repositoryUrl": "https://github.com/owner/repo",
"tagsUrl": "https://github.com/owner/repo/releases/tag/",
"sourcemaps": "dist",
"urlPrefix": "~/dist"
}
]
]
}
```

```yml
# .gitlab-ci.yml
release:
Expand Down
146 changes: 127 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"homepage": "https://github.com/eclass/semantic-release-sentry-releases#readme",
"dependencies": {
"@semantic-release/error": "^2.1.0",
"@sentry/cli": "1.51.1",
"aggregate-error": "^3.0.1"
},
"devDependencies": {
Expand All @@ -37,8 +38,10 @@
"@eclass/semantic-release-npm-github-config": "3.0.0",
"@semantic-release/changelog": "5.0.1",
"@semantic-release/git": "9.0.0",
"@sentry/types": "5.15.0",
"@types/chai": "4.2.11",
"@types/mocha": "7.0.2",
"@types/mock-require": "2.0.0",
"@types/node": "12.12.31",
"@types/semantic-release": "15.13.1",
"chai": "4.2.0",
Expand All @@ -55,11 +58,13 @@
"husky": "4.2.3",
"lint-staged": "10.0.9",
"mocha": "7.1.1",
"mock-require": "3.0.3",
"nock": "12.0.3",
"nyc": "15.0.0",
"nyc-config-common": "1.0.1",
"prettier-standard": "16.2.1",
"semantic-release": "17.0.4",
"temp-write": "4.0.0",
"typescript": "3.8.3"
},
"peerDependencies": {
Expand Down
27 changes: 24 additions & 3 deletions src/publish.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const path = require('path')
const SentryCli = require('@sentry/cli')
const getError = require('./get-error')
const { createRelease, createDeploy } = require('./request')

Expand Down Expand Up @@ -25,6 +27,7 @@ const { createRelease, createDeploy } = require('./request')
module.exports = async (pluginConfig, ctx) => {
try {
const url = pluginConfig.tagsUrl || ''
const project = ctx.env.SENTRY_PROJECT || pluginConfig.project
/** @type {SentryReleaseParams} */
const releaseDate = {
commits: ctx.commits.map(commit => {
Expand All @@ -41,15 +44,30 @@ module.exports = async (pluginConfig, ctx) => {
return newCommit
}),
version: ctx.nextRelease.version,
projects: [ctx.env.SENTRY_PROJECT || pluginConfig.project]
projects: [project]
}
if (url !== '') releaseDate.url = url
if (url !== '') releaseDate.url = `${url}/v${ctx.nextRelease.version}`
const org = ctx.env.SENTRY_ORG || pluginConfig.org
ctx.logger.log('Creating release %s', ctx.nextRelease.version)
const release = await createRelease(
releaseDate,
ctx.env.SENTRY_AUTH_TOKEN,
org
)
ctx.logger.log('Release created')
process.env.SENTRY_ORG = org
process.env.SENTRY_PROJECT = project
const cli = new SentryCli()
if (pluginConfig.sourcemaps && pluginConfig.urlPrefix) {
const sourcemaps = path.resolve(ctx.cwd, pluginConfig.sourcemaps)
ctx.logger.log('Uploading sourcemaps from %s', sourcemaps)
await cli.releases.uploadSourceMaps(ctx.nextRelease.version, {
include: [sourcemaps],
urlPrefix: pluginConfig.urlPrefix,
rewrite: pluginConfig.rewrite || false
})
ctx.logger.log('Sourcemaps uploaded')
}
/** @type {SentryDeployParams} */
const deployData = {
environment: pluginConfig.environment || 'production'
Expand All @@ -58,22 +76,25 @@ module.exports = async (pluginConfig, ctx) => {
deployData.name = pluginConfig.deployName
}
if (pluginConfig.deployUrl) {
deployData.name = pluginConfig.deployUrl
deployData.url = pluginConfig.deployUrl
}
if (ctx.env.DEPLOY_START) {
deployData.dateStarted = ctx.env.DEPLOY_START
}
if (ctx.env.DEPLOY_END) {
deployData.dateStarted = ctx.env.DEPLOY_END
}
ctx.logger.log('Creating deploy for release %s', ctx.nextRelease.version)
const deploy = await createDeploy(
deployData,
ctx.env.SENTRY_AUTH_TOKEN,
org,
ctx.nextRelease.version
)
ctx.logger.log('Deploy created')
return { release, deploy }
} catch (err) {
ctx.logger.error(err)
throw getError('ESENTRYDEPLOY', ctx)
}
}
Loading

0 comments on commit f63fa5d

Please sign in to comment.