-
Notifications
You must be signed in to change notification settings - Fork 57
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
Conversation
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
9c18acc
to
067fe64
Compare
}); | ||
|
||
test('should return a string when dist is provided', () => { | ||
process.env['INPUT_DIST'] = 'foo-dist'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 }} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
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`)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
@armenzg have left a bunch more detailed comments and screenshots to help with the context-switching :) |
There was a problem hiding this 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!
It seems that the step |
Maybe because the change made in ec7fe19 was not reflected in the function's return types? @tanyagray Line 88 in ec7fe19
|
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 ...Which indicates that the folder binding that this Action interprets from So, I tried playing around with Then, I replaced this action by a bulk command to test the naive behavior of the latest
Which produced correct outputs : My final guess is that, either the outdated In hope this lengthy response helps someone ! 👍 |
I can confirm that, if only the build number changes between release publications via |
export const getDist = (): string | undefined => { | ||
const distOption: string = core.getInput('dist'); | ||
if (!distOption) { | ||
return null; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 🤞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 👍
Thank you @tanyagray for your perseverance and willingness to help everyone! 🎉 |
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. |
Hi @benasher44 |
Amazing, thank you! |
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'] ```
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'] ```
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'] ```
Adds support for
dist
as input value for GitHub Action:Note that this repo uses
@sentry/cli@^1.67.2
and there is a related fix in2.3.1
:The above
sentry-cli
fix was to move thedist
option from being underSentryCliOptions
(incorrect) to be underSentryCliUploadSourceMapsOptions
(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](https://user-images.githubusercontent.com/153077/221053463-c6d0ffbd-4a7e-4109-b701-cbce5a59c0cb.png)
After: Sentry UI showing SHA as the dist for sourcemaps (as passed to action):
![Screen Shot 2023-02-24 at 12 20 57 PM](https://user-images.githubusercontent.com/153077/221053649-9f7a9793-5274-4fa4-8aa6-17dc68dfe3f5.png)
Resolves #74