Skip to content

Commit

Permalink
feat(publish): use SENTRY_ENVIRONMENT variable for deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Mann authored and lgaticaq committed Jul 25, 2021
1 parent 08b5c87 commit 022a917
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
| `SENTRY_ORG` | The slug of the organization. |
| `SENTRY_PROJECT` | The slug of the project. |
| `SENTRY_URL` | The URL to use to connect to sentry. This defaults to https://sentry.io/. |
| `SENTRY_ENVIRONMENT`| The environment to specify with this release. This defaults to production. |
| `DEPLOY_START` | Sentry deploy start timestamp. Optional for deploy |
| `DEPLOY_END` | Sentry deploy end timestamp. Optional for deploy |

Expand Down
2 changes: 1 addition & 1 deletion src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const { createRelease, createDeploy, uploadSourceFiles } = require('./request')
const getDeployData = (pluginConfig, ctx) => {
/** @type {SentryDeployParams} */
const deployData = {
environment: pluginConfig.environment || 'production'
environment: ctx.env.SENTRY_ENVIRONMENT || pluginConfig.environment || 'production'
}
if (pluginConfig.deployName) {
deployData.name = pluginConfig.deployName
Expand Down
18 changes: 16 additions & 2 deletions test/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ describe('Publish', () => {
env: {
SENTRY_ORG: 'valid',
SENTRY_PROJECT: 'error',
SENTRY_AUTH_TOKEN: 'valid'
SENTRY_AUTH_TOKEN: 'valid',
SENTRY_ENVIRONMENT: 'environment'
},
commits: [
{
Expand Down Expand Up @@ -106,7 +107,7 @@ describe('Publish', () => {
.reply(201, {
name: 'amazon',
url: 'https://api.example.com/',
environment: 'production',
environment: ctx.env.SENTRY_ENVIRONMENT,
dateStarted: '2020-02-05T10:29:59Z',
dateFinished: '2020-02-05T10:30:43Z',
id: '5044917'
Expand Down Expand Up @@ -208,4 +209,17 @@ describe('Publish', () => {
`${releasePrefix}-${ctx.nextRelease.version}`
)
})

it('Deploy app with environment from environment', async () => {
ctx.env.SENTRY_PROJECT = 'project'

// @ts-ignore
const result = await publish(
{ tagsUrl },
ctx
)
expect(result.deploy.environment).to.equal(
ctx.env.SENTRY_ENVIRONMENT
)
})
})

0 comments on commit 022a917

Please sign in to comment.