Skip to content

Commit

Permalink
feat: Add option to set dist on sourcemaps
Browse files Browse the repository at this point in the history
Adds support for `dist` as input value for GitHub Action:

```yaml
    - uses: getsentry/action-release@v1
      with:
        environment: 'production'
        sourcemaps: './lib'
        dist: ${{ github.sha }}
```

Note that this repo uses `@sentry/cli@^1.67.2` and there is a related fix in `2.3.1`:

> fix: move dist option to SentryCliUploadSourceMapsOptions (#1269) by @ikenfin
> [changelog](https://github.com/getsentry/sentry-cli/blob/master/CHANGELOG.md#231)

This fix was to move the `dist` option from being under `SentryCliOptions` (incorrect) to be under `SentryCliUploadSourceMapsOptions` (correct)

This does not affect the GH action as those types are not referenced directly by the action.

Resolves #74
  • Loading branch information
tanyagray committed Feb 17, 2023
1 parent e9ba614 commit 067fe64
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Adding the following to your workflow will create a new Sentry release and tell
|`ignore_missing`|When the flag is set and the previous release commit was not found in the repository, will create a release with the default commits count instead of failing the command.|`false`|
|`ignore_empty`|When the flag is set, command will not fail and just exit silently if no new commits for a given release have been found.|`false`|
|`sourcemaps`|Space-separated list of paths to JavaScript sourcemaps. Omit to skip uploading sourcemaps.|-|
|`dist`|Unique identifier for the distribution, used to further segment your release. Usually your build number. _Note: Required when uploading sourcemaps._|-|
|`started_at`|Unix timestamp of the release start date. Omit for current time.|-|
|`version`|Identifier that uniquely identifies the releases. _Note: the `refs/tags/` prefix is automatically stripped when `version` is `github.ref`._|<code>${{&nbsp;github.sha&nbsp;}}</code>|
|`version_prefix`|Value prepended to auto-generated version. For example "v".|-|
Expand All @@ -79,6 +80,7 @@ Adding the following to your workflow will create a new Sentry release and tell
with:
environment: 'production'
sourcemaps: './lib'
dist: ${{ github.sha }}
```

- Create a new Sentry release for the `production` environment of your project at version `v1.0.1`.
Expand Down
16 changes: 16 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from 'path';
import * as process from 'process';
import {
getBooleanOption,
getDist,
getSourcemaps,
getStartedAt,
getVersion,
Expand Down Expand Up @@ -66,6 +67,21 @@ describe('options', () => {
});
});

describe('getDist', () => {
afterEach(() => {
delete process.env['INPUT_DIST'];
});

test('should return undefined when dist is omitted', async () => {
expect(getDist()).toBeUndefined();
});

test('should return a string when dist is provided', () => {
process.env['INPUT_DIST'] = 'foo-dist';
expect(getDist()).toEqual('foo-dist');
});
});

describe('getStartedAt', () => {
const errorMessage =
'started_at not in valid format. Unix timestamp or ISO 8601 date expected';
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
sourcemaps:
description: 'Space-separated list of paths to JavaScript sourcemaps. Omit to skip uploading sourcemaps.'
required: false
dist:
description: 'Unique identifier for the distribution, used to further segment your release. Usually your build number.'
required: false
finalize:
description: 'When false, omit marking the release as finalized and released.'
default: true
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as options from './options';

const environment = options.getEnvironment();
const sourcemaps = options.getSourcemaps();
const dist = options.getDist();
const shouldFinalize = options.getBooleanOption('finalize', true);
const ignoreMissing = options.getBooleanOption('ignore_missing', false);
const ignoreEmpty = options.getBooleanOption('ignore_empty', false);
Expand Down Expand Up @@ -45,6 +46,7 @@ import * as options from './options';
const sourceMapOptions = {
include: sourcemaps,
projects: localProjects,
dist,
urlPrefix,
stripCommonPrefix,
};
Expand Down
13 changes: 13 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ export const getSourcemaps = (): string[] => {
return sourcemapsOption.split(' ');
};

/**
* Dist is optional, but should be a string when provided.
* @returns string
*/
export const getDist = (): string | undefined => {
const distOption: string = core.getInput('dist');
if (!distOption) {
return undefined;
}

return distOption;
};

/**
* Fetch boolean option from input. Throws error if option value is not a boolean.
* @param input string
Expand Down

0 comments on commit 067fe64

Please sign in to comment.