Skip to content

Commit

Permalink
feat: add releasePrefix to sentry release
Browse files Browse the repository at this point in the history
fixes that sentry releases are associated with an organization instead a project.
For more information about this topic read: getsentry/sentry-cli#482
  • Loading branch information
jembach authored and lgaticaq committed Oct 16, 2020
1 parent 1bf964c commit b529c0c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
| `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 |
| `releasePrefix`| String that is passed as prefix to the sentry release. <br/> Optional to fix the problem that releases are associated with the organization instead of the project ([Read More](https://github.com/getsentry/sentry-cli/issues/482)). <br/> Ex: `releasePrefix:"web1"` would resolve __only__ the sentry release to `web1-1.0.0`. <br/>__Important Notice:__ when you use this feature you also have to change the release name in your sentry client app. |

### Examples

Expand Down
13 changes: 8 additions & 5 deletions src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,21 @@ module.exports = async (pluginConfig, ctx) => {
ctx.logger.log('Retrieving commits data')
const commits = await parseCommits(pluginConfig, ctx)
ctx.logger.log('Commit data retrieved')
const sentryReleaseVersion = pluginConfig.releasePrefix
? `${pluginConfig.releasePrefix}-${ctx.nextRelease.version}`
: ctx.nextRelease.version
/** @type {SentryReleaseParams} */
const releaseDate = {
commits,
version: ctx.nextRelease.version,
version: sentryReleaseVersion,
projects: [project]
}
if (tagsUrl !== '') {
releaseDate.url = `${tagsUrl}/v${ctx.nextRelease.version}`
}
const org = ctx.env.SENTRY_ORG || pluginConfig.org
const url = ctx.env.SENTRY_URL || pluginConfig.url || 'https://sentry.io/'
ctx.logger.log('Creating release %s', ctx.nextRelease.version)
ctx.logger.log('Creating release %s', sentryReleaseVersion)
const release = await createRelease(
releaseDate,
ctx.env.SENTRY_AUTH_TOKEN,
Expand All @@ -79,21 +82,21 @@ module.exports = async (pluginConfig, ctx) => {
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, {
await cli.releases.uploadSourceMaps(sentryReleaseVersion, {
include: [sourcemaps],
urlPrefix: pluginConfig.urlPrefix,
rewrite: pluginConfig.rewrite || false
})
ctx.logger.log('Sourcemaps uploaded')
}
const deployData = getDeployData(pluginConfig, ctx)
ctx.logger.log('Creating deploy for release %s', ctx.nextRelease.version)
ctx.logger.log('Creating deploy for release %s', sentryReleaseVersion)
const deploy = await createDeploy(
deployData,
ctx.env.SENTRY_AUTH_TOKEN,
org,
url,
ctx.nextRelease.version
sentryReleaseVersion
)
ctx.logger.log('Deploy created')
return { release, deploy }
Expand Down
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface Config {
sourcemaps?: string
urlPrefix?: string
rewrite?: boolean
releasePrefix?: string
}

export enum PATCH_SET_TYPES {
Expand Down
53 changes: 53 additions & 0 deletions test/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,42 @@ describe('Publish', () => {
dateFinished: '2020-02-05T10:30:43Z',
id: '5044917'
})

nock(SENTRY_HOST, NOCK_OPTIONS)
.post(PATH_RELEASE)
.reply(201, {
authors: [],
commitCount: 0,
data: {},
dateCreated: new Date().toISOString(),
dateReleased: null,
deployCount: 0,
firstEvent: null,
lastCommit: null,
lastDeploy: null,
lastEvent: null,
newGroups: 0,
owner: null,
projects: [
{
name: 'project',
slug: 'project'
}
],
ref: '6ba09a7c53235ee8a8fa5ee4c1ca8ca886e7fdbb',
shortVersion: 'web1-1.0.0',
url: null,
version: 'web1-1.0.0'
})
.post('/api/0/organizations/valid/releases/web1-1.0.0/deploys/')
.reply(201, {
name: 'amazon',
url: 'https://api.example.com/',
environment: 'production',
dateStarted: '2020-02-05T10:29:59Z',
dateFinished: '2020-02-05T10:30:43Z',
id: '5044917'
})
})

it(SERVER_ERROR_TITLE, async () => {
Expand Down Expand Up @@ -164,4 +200,21 @@ describe('Publish', () => {
const result = await publish({ tagsUrl, sourcemaps, urlPrefix }, ctx)
expect(result.release.version).to.equal('1.0.0')
})

it('Deploy app with releasePrefix', async () => {
ctx.env.SENTRY_PROJECT = 'project'
const filePath = tempWrite.sync('sourcemaps', 'dist/app.js.map')
const sourcemaps = path.dirname(filePath)
ctx.cwd = path.dirname(sourcemaps)
const urlPrefix = '~/dist'
const releasePrefix = 'web1'
// @ts-ignore
const result = await publish(
{ tagsUrl, sourcemaps, urlPrefix, releasePrefix },
ctx
)
expect(result.release.version).to.equal(
`${releasePrefix}-${ctx.nextRelease.version}`
)
})
})

0 comments on commit b529c0c

Please sign in to comment.