Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add option to set dist on sourcemaps #125

Merged
merged 6 commits into from
Apr 4, 2023

Conversation

tanyagray
Copy link
Contributor

@tanyagray tanyagray commented Feb 17, 2023

Adds support for dist as input value for GitHub Action:

    - 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

The above sentry-cli 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.

Have not added tests for the value being passed to the CLI as that doesn't appear to be covered for any of the existing values. Did manually debug and ensure that the resulting execute call included the --dist fake-dist param.


Before: Sentry UI showing dist 'none' for sourcemap artifacts
Screen Shot 2023-02-24 at 12 10 23 PM


After: Sentry UI showing SHA as the dist for sourcemaps (as passed to action):
Screen Shot 2023-02-24 at 12 20 57 PM

Resolves #74

@tanyagray tanyagray requested a review from a team February 17, 2023 05:19
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 getsentry#74
@tanyagray tanyagray force-pushed the feat/74-sourcemaps-dist branch from 9c18acc to 067fe64 Compare February 17, 2023 05:21
});

test('should return a string when dist is provided', () => {
process.env['INPUT_DIST'] = 'foo-dist';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the usage of this env? I don't see it used in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the github action runner creates all inputs as env vars, prefixed with INPUT_, so INPUT_DIST is equivalent to ${ inputs.dist } in the action itself, or with: dist: 'foo-dist' via a workflow.

When you specify an input in a workflow file or use a default input value, GitHub creates an environment variable for the input with the name INPUT_<VARIABLE_NAME>. The environment variable created converts input names to uppercase letters and replaces spaces with _ characters.
Source

This is how the Sentry Action tests are implemented, as it's (presumably) easier to unit test by setting env vars, than by running the workflow with different sets of with: params. I just followed the format used for the existing tests rather than implementing any new testing approach.

@@ -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 }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the github.sha not get figured out automatically? I thought the usage of dist is more for when we do not want github.sha to be used.

I do not know the code enough but that's what I remember.

Copy link
Contributor Author

@tanyagray tanyagray Feb 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oooh this is interesting... I wonder if this is a bug on its own then.

When using the github action as it is currently, dist is not set at all and shows as "none" in the Sentry UI, which causes source maps not to match up at all.

Without this change I've made in this PR, this is what I see in the Sentry UI when using the GH action to upload:
Screen Shot 2023-02-24 at 12 10 23 PM

Note the "none" on the artifacts. This should be the dist and sourcemaps won't work correctly without the dist value matching on both sourcemaps and the code/application at runtime (via eg. Sentry.init({ dist }) in JS`)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's reasonable for dist to default to the github SHA, i could likely update the PR to do that. There isn't much in the way of docs about what dist should be, other than a suggestion it might be your build number (?) but that doesnt seem correct for use in GH workflows -- SHA seems more reasonable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added screenshots to the main issue description too for before/after

@@ -11,6 +11,7 @@ import * as options from './options';

const environment = options.getEnvironment();
const sourcemaps = options.getSourcemaps();
const dist = options.getDist();
Copy link
Contributor Author

@tanyagray tanyagray Feb 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where the env var INPUT_DIST is used, options.getDist() uses the github core.getInput('dist') to get the input.

Added a comment on that line too.

@@ -45,6 +46,7 @@ import * as options from './options';
const sourceMapOptions = {
include: sourcemaps,
projects: localProjects,
dist,
Copy link
Contributor Author

@tanyagray tanyagray Feb 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where $INPUT_DIST / ${ inputs.dist } / with: dist: 'foo-dist' is passed to the sentry sourcemap upload command.

This is the most important line, this is primarily what is missing right now. You need to pass dist in the sourcemap options for it to be included in the execution of the cli.uploadSourceMaps() function (line 53 below)

* @returns string
*/
export const getDist = (): string | undefined => {
const distOption: string = core.getInput('dist');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core.getInput('dist') gets that env var $INPUT_DIST that GH creates on behalf of each input.

@tanyagray tanyagray requested a review from armenzg February 23, 2023 23:30
@tanyagray
Copy link
Contributor Author

tanyagray commented Feb 23, 2023

@armenzg have left a bunch more detailed comments and screenshots to help with the context-switching :)

src/options.ts Outdated Show resolved Hide resolved
__tests__/main.test.ts Outdated Show resolved Hide resolved
Copy link
Member

@armenzg armenzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic work! Thank you for putting the extra effort to make comments on your code and putting the screenshots in place!

@armenzg
Copy link
Member

armenzg commented Feb 24, 2023

It seems that the step ncc build src/main.ts fails to work. Do you know what it is about?
https://github.com/getsentry/action-release/actions/runs/4257979812/jobs/7419509851#step:4:56

@hermitpopcorn
Copy link

Maybe because the change made in ec7fe19 was not reflected in the function's return types? @tanyagray

export const getDist = (): string | undefined => {

@Amphaal
Copy link

Amphaal commented Mar 28, 2023

Bumping, as this feature is now kinda required for the most recent versions of Sentry since sourcemaps automatic mappings depends on it 😢

@tanyagray
Copy link
Contributor Author

Bumping, as this feature is now kinda required for the most recent versions of Sentry since sourcemaps automatic mappings depends on it 😢

This must be why I had trouble with it. I was very confused why I was following the docs and it still wasn't working.

I ended up abandoning using the github action and writing my own workflow using the CLI directly, but will try make some time tomorrow to make the change suggested by @hermitpopcorn, thanks for that!

Cheers for the bump 🙏

@Amphaal
Copy link

Amphaal commented Mar 28, 2023

Bumping, as this feature is now kinda required for the most recent versions of Sentry since sourcemaps automatic mappings depends on it 😢

This must be why I had trouble with it. I was very confused why I was following the docs and it still wasn't working.

I ended up abandoning using the github action and writing my own workflow using the CLI directly, but will try make some time tomorrow to make the change suggested by @hermitpopcorn, thanks for that!

Cheers for the bump 🙏

So, I was also on my way to do exactly the same thing as you did...

I stumbled on https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js/, which points to a very handy
(sentry-cli sourcemaps explain), which I tried on an error I produced after uploading the artifacts:

Capture d’écran 2023-03-28 à 10 51 36

...Which indicates that the folder binding that this Action interprets from with.sourcemaps is not understood by Sentry !

So, I tried playing around with with.sourcemaps, testing both './build/web' and build/web, which resulted in incorrect binding in both cases :

Capture d’écran 2023-03-28 à 10 56 02

Then, I replaced this action by a bulk command to test the naive behavior of the latest sentry-cli in my ./.github/workflows/deploy_web.yml:

      - name: "Sentry: Create Release w/ sourcemaps"
        env:
          SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_TOKEN }}
          SENTRY_ORG: qalisa
          SENTRY_PROJECT: ivy-app
          SENTRY_URL: https://sentry.ivy.community/
        run: |
          # Install Sentry CLI
          curl -sL https://sentry.io/get-cli/ | bash

          # Create new Sentry release
          export SENTRY_RELEASE=com.qalisa.ivy@${{ steps.version.outputs.value }}+${{ env.IVY_BUILD_NUMBER }}
          sentry-cli releases new $SENTRY_RELEASE
          sentry-cli releases set-commits --auto $SENTRY_RELEASE
          sentry-cli releases files $SENTRY_RELEASE upload-sourcemaps build/web
          sentry-cli releases finalize $SENTRY_RELEASE

Which produced correct outputs :

Capture d’écran 2023-03-28 à 10 59 33

My final guess is that, either the outdated sentry-cli of this action does not have the user expected behavior, or with.sourcemaps enforces a prefixed /.
In both cases, for now, we cannot use this action since it would require --url-prefix handling, which is not implemented right now... 😭

In hope this lengthy response helps someone ! 👍

@Amphaal
Copy link

Amphaal commented Mar 28, 2023

Bumping, as this feature is now kinda required for the most recent versions of Sentry since sourcemaps automatic mappings depends on it 😢

I can confirm that, if only the build number changes between release publications via sentry-cli, --dist is required, and must match the build number 👍 So this PR is indeed still relevant for this specific use-case.

Capture d’écran 2023-03-28 à 11 22 32

export const getDist = (): string | undefined => {
const distOption: string = core.getInput('dist');
if (!distOption) {
return null;
Copy link
Member

@armenzg armenzg Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing this error in the CI logs.

TS2322: Type 'null' is not assignable to type 'string | undefined'.

Would returning undefined work? or should the return type be changed?

Copy link
Contributor Author

@tanyagray tanyagray Apr 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this was my mistake, i originally has this function configured to return undefined, but changed it to null after seeing all the other properties use null not undefined... I just didn't update the return type.

vscode corrected me as soon as i opened the PR, not sure why it didn't point it out earlier.

hopefully this is enough for a CI pass 🤞

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can see some of the sentry-cli integration tests use null so I expect this is correct.

Screen Shot 2023-04-03 at 12 00 26 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made this change and committed 👍

src/options.ts Outdated Show resolved Hide resolved
@armenzg armenzg merged commit 455699b into getsentry:master Apr 4, 2023
@armenzg
Copy link
Member

armenzg commented Apr 4, 2023

Thank you @tanyagray for your perseverance and willingness to help everyone! 🎉

@benasher44
Copy link

Thanks for the fix! Can this please be added to the v1 tag? Our sourcemaps/traces are currently broken, and this should fix it. I went to go add the dist arg, but then I found that it wasn't accepted yet.

@armenzg
Copy link
Member

armenzg commented Apr 19, 2023

Hi @benasher44
I believe I've handled it here:
#145

@benasher44
Copy link

Amazing, thank you!

armenzg added a commit that referenced this pull request Apr 20, 2023
In #125, we added support for using `dist` with sourcemaps, however, we return `null` when not specified and that gets converted into the string `"null"` down the pipeline which has broken the sourcemaps for various customers in the last two weeks.

Also, ss indicated in #138, `dist` is optional for sourcemaps when used with the CLI. Updating the README.me to handle it.

This also removes a warning which shows when the action is run:
```
Warning: Unexpected input(s) 'dist', valid inputs are ['entryPoint', 'args', 'environment', 'sourcemaps', 'finalize', 'ignore_missing', 'ignore_empty', 'started_at', 'version', 'version_prefix',
'set_commits', 'projects', 'url_prefix', 'strip_common_prefix', 'working_directory']
```
armenzg added a commit that referenced this pull request Apr 20, 2023
In #125, we added support for using `dist` with sourcemaps, however, we return `null` when not specified and that gets converted into the string `"null"` down the pipeline which has broken the sourcemaps for various customers in the last two weeks.

Also, ss indicated in #138, `dist` is optional for sourcemaps when used with the CLI. Updating the README.me to handle it.

This also removes a warning which shows when the action is run:
```
Warning: Unexpected input(s) 'dist', valid inputs are ['entryPoint', 'args', 'environment', 'sourcemaps', 'finalize', 'ignore_missing', 'ignore_empty', 'started_at', 'version', 'version_prefix',
'set_commits', 'projects', 'url_prefix', 'strip_common_prefix', 'working_directory']
```
armenzg added a commit that referenced this pull request Apr 20, 2023
In #125, we added support for using `dist` with sourcemaps, however, we return `null` when not specified and that gets converted into the string `"null"` down the pipeline which has broken the sourcemaps for various customers in the last two weeks.

Also, ss indicated in #138, `dist` is optional for sourcemaps when used with the CLI. Updating the README.me to handle it.

This also removes a warning which shows when the action is run:
```
Warning: Unexpected input(s) 'dist', valid inputs are ['entryPoint', 'args', 'environment', 'sourcemaps', 'finalize', 'ignore_missing', 'ignore_empty', 'started_at', 'version', 'version_prefix',
'set_commits', 'projects', 'url_prefix', 'strip_common_prefix', 'working_directory']
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to set dist on sourcemaps
5 participants