-
Notifications
You must be signed in to change notification settings - Fork 195
fix: fix the builds for public projects that use yarn 2 (or above) with workspaces #763
fix: fix the builds for public projects that use yarn 2 (or above) with workspaces #763
Conversation
…n 2 or above with workspaces
ac4f18e
to
536caf3
Compare
added to backend/support pairing - @audreyshub could you please raise this with the next person you meet with to ask the relevant team to review this for us? |
Thank you for your contribution @fulopkovacs! 🎉 And thanks @fool for raising this. I've added this to our board so we can triage it and prioritise the review next Monday during our planning session. |
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.
Apologies for taking so long to review this @fulopkovacs and thank you for your contribution!
Overall the approach looks good, however I think we could simplify this and reduce the number of code branches if we simply checked for the installer and the yarn version up ahead. Let me know what you think.
I was also wondering how would you feel about adding an automated test for this? You can rely on the helper functions we have to setup a fixture workspace in order to validate this:
build-image/tests/node/yarn.bats
Line 16 in 122eea9
set_fixture_as_repo 'simple-node' "$TMP_DIR"
run-build-functions.sh
Outdated
workspace_error_message=$(jq -r ".data" "$workspace_errors_logfile" 2>/dev/null) | ||
package_manager_version=$(yarn --version) | ||
if [ "${package_manager_version:0:1}" -gt 1 ] && [ "$workspace_error_message" = "Workspaces can only be enabled in private projects." ] |
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.
Since we know the installer
up ahead and we can check for yarn's version (similar to what we're doing in here already) I was thinking we could simplify things here a bit and not require us to check the error logs of the first command execution? We could instead check:
- if the installer is yarn and we're using version greater than 1, run the remainder of this
then
block - else run the
YARN_IGNORE_PATH=1
block.
Something like (nvm the chaos and indentation):
local package_manager_version
package_manager_version=$(yarn --version)
if [ "$installer" = "yarn"] && [ "${package_manager_version:0:1}" -gt 1 ]
then
# the yarn berry workspaces logic
(...)
else
(...)
workspace_output="$(YARN_IGNORE_PATH=1 yarn workspaces --json info 2>/dev/null)"
(etc.)
fi
# Handle the output of the executions above
if [ ${#package_locations[@]} -ne 0 ]
then
echo "$installer workspaces detected"
# Extract all the packages and respective locations.
restore_js_workspaces_cache "${package_locations[@]}"
else
echo "No $installer workspaces detected"
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.
@JGAntunes Hey 👋,
sorry for replying 4 days late, I forgot about this issue... 😅 Your suggestion seems to be reasonable, I'd be happy to try it and add add a test this week, if that's okay for you (tbh I might have to work on it on the weekend, because currently it doesn't fit into our schedule at work).
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.
@fulopkovacs sure thing, however works better for you 👍 again, apologies for taking so long to follow up.
…e yarn 2 or above with workspaces
…rn 2 or above with workspaces
@@ -0,0 +1,3 @@ | |||
nodeLinker: node-modules | |||
|
|||
yarnPath: .yarn/releases/yarn-3.2.0.cjs |
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.
@JGAntunes Shipping a binary for a specific version of yarn might be controversial, but
- it's a valid real-world use case (we use this configuration at work)
- it's faster to run the tests, because we don't have to download a new yarn version.
@JGAntunes I finally pass the PR back to review! 😁 There were a few surprises with the tests (e.g.: many of the tests in One of our biggest pain point gets addressed, if this PR gets merged, but there will still be the problem of caching, which doesn't really work with yarn berry now (35-45s for us for every deploy). Are there any (public) news about that? I saw a PR about it (#465), but it didn't receive much attention from your side (I didn't check the code of the PR though). (Btw having worked with the code base and seeing the tests I understand that full support for yarn berry would require quite a bit of planning and effort, so I don't expect you to fix the issue overnight. I would be happy with just a bit more clarity about the place of this feature on the roadmap |
Support got already implemented inside #858 |
Summary
Fixes #762
The problem it solves
Currently builds are failing for public projects that use yarn 2 (or above) with workspaces. The cached node modules are cached and restored to the wrong location.
The bug
A bit of context: in yarn 1.x only private repos can have workspaces, but this limitation was removed in yarn 2:
The bug is in the
run-build-functions.sh
file:As you can see it tries to output information about the workspaces with yarn 1.x. in the command substitution and redirects STDERR to
/dev/null
. After that it only checks if the process exited with 0 or an error code, but ignores the error message, which would tell us, that "workspaces can only be enabled in private projects". Here's an example for the problem from the theatre-js/theatre repo:The solution
yarn workspaces list --json
command to get the information about the workspacesHow I tested the solution
We have a public repo whose builds are failing without clearing the cache after every build. Here's how the cached folders look like with the current build script:
The yarn workspaces are not detected in the logs:
But here's the previous pictures look like for the fixed build script:
![image](https://user-images.githubusercontent.com/43729152/160356360-2e4a1ff5-8f39-4b4d-a5a4-f80bdab5c2f1.png)
![image](https://user-images.githubusercontent.com/43729152/160356531-ff4159d4-d1cc-46c9-995c-8b7c6033af1f.png)
I'm not sure if I missed anything, but feel free to tell me if there are things to change!☺️
For us to review and ship your PR efficiently, please perform the following steps:
A picture of a cute animal (not mandatory, but encouraged)
![image](https://user-images.githubusercontent.com/43729152/160351694-bcb3f991-fe7d-4f94-ac5b-34fd4d5bf317.png)