-
Notifications
You must be signed in to change notification settings - Fork 893
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
Storybook - better determine correct brave-core output path allowing specification via param or fallback to most recently built #21443
Conversation
@@ -36,7 +36,7 @@ | |||
"pep8": "pycodestyle --max-line-length 120 -r script", | |||
"pylint": "node ./build/commands/scripts/commands.js pylint", | |||
"web-ui-gen-grd": "node components/webpack/gen-webpack-grd", | |||
"web-ui-gen-tsconfig": "node components/webpack/gen-tsconfig", | |||
"web-ui-gen-tsconfig": "node build/commands/scripts/genTsConfig", |
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.
Can we make web-ui-gen-tsconfig
and build-storybook
take the target_arch
, target_os
andtarget_environment
as parameters, which then get forwarded via the environment variables or some other way? We have npm run build Component
so npm run build-storybook Component
makes intuitive sense. Similarly for npm run build -- Static --target_arch=arm64
and target_os
.
Actually, in my opinion, it seems like the storybook should be a GN target. Then we would automatically get all the target_arch etc. logic for free. But it may be beyond the scope of this PR.
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 is a storybook GN target which ensures the dependencies are built.
I do not think running storybook via GN is necessarily the best or obvious approach. Storybook is not an artifact of brave-core but a tool that uses the artifacts from brave-core as 1 of its dependencies. It creates a long running web server with a watch on all dependencies.
I do agree it's nicer for local developers to have cli parameters to run against different output directories. As far as I know, the storybook
and build-storybook
commands do not expose custom cli parameters to their configurations. We would have to write wrapper commands to accept cli parameters. I used environment variables for now since this is a CI-only issue and CI needs to be unblocked without waiting for someone to have the time to change everything about how we use storybook. It can be done as a follow-up when someone has available time. For now, the same .env file variables will be respected.
web-ui-gen-tsconfig
is already only internally run from GN. It's also not called from this storybook config, only the browser build. I just refactored it so it can be called as a function. It doesn't need to accept parameters because it isn't run directly by the user or CI.
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.
CI needs to be unblocked without waiting for someone to have the time to change everything about how we use storybook. It can be done as a follow-up
I understand and agree; The priority is to unblock CI. We can do additional work in a follow-up.
Storybook is not an artifact of brave-core but a tool that uses the artifacts from brave-core as 1 of its dependencies.
In my opinion, the fact that Storybook has GN dependencies and itself needs target_os
etc. indicates to me that GN is a natural place for it to be called from.
this is a CI-only issue
I also experienced the issue during local development, so it's not a CI-only issue in my opinion.
// resource dependencies: | ||
// 1. Default for local builds for the actual platform / architecture | ||
// 2. platform / architecture overriden by environment variables | ||
// 3. most recently built - this caters to the common scenario when a |
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 would personally not implement the "most recently built" logic. It is ambiguous and has already caused problems for me. Yes, that was with the gen
subdirectory; But the principle remains the same and I strongly suspect that there will be a day where it causes a confusing surprise for another developer (directly or through CI).
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 keeping it for now to provide backwards compatibility. Since this is 99% a local dev debug and development preview tool, the risk is minimal, and in fact the chances of getting it wrong is improved.
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.
:+1 I'm pretty happy to keep this in - I think it'll work most of the time and you can make things explicit if you need to now.
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.
I have some concerns about this PR as well @mherrmann and discussing with @petemill
Also, don't we need this change as well? |
(I heard that the problem also occurred on Arm64 macOS, so I added the associated CI label.) |
Yes all generated JS used by any stories should be referenced there. |
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.
LGTM @petemill - thanks for doing this!
// resource dependencies: | ||
// 1. Default for local builds for the actual platform / architecture | ||
// 2. platform / architecture overriden by environment variables | ||
// 3. most recently built - this caters to the common scenario when a |
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.
:+1 I'm pretty happy to keep this in - I think it'll work most of the time and you can make things explicit if you need to now.
ed9f916
to
d34e65c
Compare
d34e65c
to
028b844
Compare
028b844
to
e3044da
Compare
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.
// resource dependencies: | ||
// 1. Default for local builds for the actual platform / architecture | ||
// 2. platform / architecture overriden by environment variables | ||
// 3. most recently built - this caters to the common scenario when a |
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.
// 3. most recently built - this caters to the common scenario when a | ||
// non-standard target has been built but no arguments are provided to storybook | ||
config.update({ | ||
target_arch: process.env.TARGET_ARCH, |
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 PR description says that target_arch
etc. can be provided by the usual brave-core .npmrc / .env params. I'm not sure this section of the code achieves this.
In my understanding of the PR description, I should be able to run npm config set target_arch arm64
or to add target_arch=arm64
to my .env
file. But the former is no longer supported (it gives error "target_arch is not a valid npm option"). And the latter has no effect.
For me, the only way this code has an effect is when the environment variable TARGET_ARCH
is set, or defined in the same upper-case spelling in .env
. I can't think of a situation in practice where a developer will do this. Maybe I'm missing something and there are real-world situations where CI or a dev will do this. But unless that is realistically the case, I would remove this code because it will effectively be unused.
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.
IT will support whatever we currently support for our other commands. If more recent versions of npm don't allow custom params then you must use what we already support. What most devs and CI use is CLI params to npm run sync
and npm run build
. However, Storybook doesn't support custom arguments, so for this command we specify via environment param instead.
@@ -36,7 +36,7 @@ | |||
"pep8": "pycodestyle --max-line-length 120 -r script", | |||
"pylint": "node ./build/commands/scripts/commands.js pylint", | |||
"web-ui-gen-grd": "node components/webpack/gen-webpack-grd", | |||
"web-ui-gen-tsconfig": "node components/webpack/gen-tsconfig", | |||
"web-ui-gen-tsconfig": "node build/commands/scripts/genTsConfig", |
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.
CI needs to be unblocked without waiting for someone to have the time to change everything about how we use storybook. It can be done as a follow-up
I understand and agree; The priority is to unblock CI. We can do additional work in a follow-up.
Storybook is not an artifact of brave-core but a tool that uses the artifacts from brave-core as 1 of its dependencies.
In my opinion, the fact that Storybook has GN dependencies and itself needs target_os
etc. indicates to me that GN is a natural place for it to be called from.
this is a CI-only issue
I also experienced the issue during local development, so it's not a CI-only issue in my opinion.
.filter(a => fs.existsSync(a)) | ||
.sort((a, b) => fs.statSync(b).mtime - fs.statSync(a).mtime) |
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.
@bridiver this is the section of code I disagree with; I believe its goal is to pick the last-modified out/
directory (out/Component
, out/Release
, etc.) as the directory to use for the build.
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 maintaining current functionality and adding the new functionality on top for now. We can remove in a follow-up.
@@ -19,6 +19,7 @@ group("storybook") { | |||
"//brave/components/brave_news/common:mojom_js", | |||
"//brave/components/brave_shields/common:mojom_js", | |||
"//brave/components/brave_vpn/common/mojom:mojom_js", | |||
"//brave/components/brave_rewards/common/mojom:mojom_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.
Do we maybe also need the following here?
"//brave/components/playlist/common/mojom:mojom_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.
Perhaps, but that has assert(enable_playlist)
and it's more controversial to remove, so we can do as follow-up.
Our PR builds on arm64 are still red until we fix this. Can we find a way to get it in @petemill? |
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.
unblocking js-deps-reviewers. There's no additional dependency changes happening so approving. Added one question as well.
// 3. most recently built - this caters to the common scenario when a | ||
// non-standard target has been built but no arguments are provided to storybook | ||
config.update({ | ||
target_arch: process.env.TARGET_ARCH, |
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.
Would this work as expected in a parallels VM or VirtualBox VM? From what I remember they normal replicate the architecture information from the host, so I don't think it would be a problem, but wanted to double check if you've thought about that at all.
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.
Not sure why this would be an issue separate to the main build command but either way this PR allows the user to override with cli, which was not possible before
e3044da
to
a3a6f2f
Compare
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 not perfect and IMO should be solved in a way when we set the build directory explicitly on CI.
but right now to unblock existing pipelines this approach should do just fine.
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.
pls ignore this comment. accidental leftover.
4a16455
to
cb29d93
Compare
…specification via param or fallback to most recently built Plus, generate tsconfig file for even more specific path mapping Ensure rewards mojom is built before storybook
cb29d93
to
8e2b0a8
Compare
|
All green now. |
Unless anyone objects, then I'm going to merge this as it unblocks certain CI builds. It doesn't introduce the unpopular edit: ...once I fix |
If I understand this correctly, then it is about the following:
As far as I see, that code is still part of the PR. Can we remove it? |
@mherrmann That is not introduced in this PR. It is currently on master. It enables all the frontend developers to run All this PR does is introduce an override for that output path lookup, which can be provided via the environment variables. |
@petemill ah yes, sorry. I only saw the code in the diff as "added"; I did not see that it was removed by the diff as well. |
Plus, generate tsconfig file for even more specific path mapping.
Target / target arch / etc can be explicitly provided by environment variables (or the usual brave-core .npmrc / .env params):
Devops PR that provides these variables in CI https://github.com/brave/devops/pull/11412
But failing that, it will make a good guess based on the most recently built target directory (looking at modified time). Previous to this PR it did the same but only for the
gen
subdirectory, which seems to be less accurate.This should satisfy all use cases (the lazy local dev and the explicit CI environment).
However, annother added change on this PR is to start with config's default output directory based on the current architecture.
Resolves brave/brave-browser#34984
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
wikinpm run lint
,npm run presubmit
wiki,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan: