Skip to content

Conversation

@anthonyshew
Copy link
Contributor

@anthonyshew anthonyshew commented Apr 17, 2024

Description

I dropped in to look at how the Node.js website team is using Turborepo and saw a few places I could help out with small optimizations.

Validation

I've dropped a few comments in the file changes. To test things locally, you can try running the commands I've altered to see the new behaviors. Additionally, you can change files in the repo to see how the caching works across runs/tasks.

One thing I can't confidently test is the GitHub Action script that I've edited. You'll notice that I collapsed two steps into one to run more turbo tasks in parallel. I'll lean on a maintainer's help there to make sure I've not created an issues/missed any context.

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run npx turbo format to ensure the code follows the style guide.
  • I have run npx turbo test to check if all tests are passing.
  • I have run npx turbo build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

@vercel
Copy link

vercel bot commented Apr 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nodejs-org ✅ Ready (Inspect) Visit Preview Apr 24, 2024 5:54pm

@anthonyshew anthonyshew force-pushed the turbo-optimizations branch from f5ef2aa to b47833b Compare April 17, 2024 22:21
@anthonyshew anthonyshew changed the title A few optimizations for Turborepo setup. fix: Optimizations for Turborepo setup Apr 17, 2024
# We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user
# the `${{ needs.base.outputs.turbo_args }}` is a string substitution happening from the base job
run: npx --package=turbo@latest -- turbo prettier ${{ needs.base.outputs.turbo_args }}
run: npx --package=turbo@latest -- turbo lint:js lint:md lint:css prettier ${{ needs.base.outputs.turbo_args }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tasks can all be made to run in parallel, saving some time.

"{app,pages}/**/*.{mdx,md}",
"*.{md,mdx,json,ts,tsx,mjs,yml}"
],
"outputs": ["coverage/**", "junit.xml"]
Copy link
Contributor Author

@anthonyshew anthonyshew Apr 18, 2024

Choose a reason for hiding this comment

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

This appears to be a duplicate of the test:unit task so we can remove it and run test:unit instead.

"lint": {
"cache": false,
"outputs": [".eslintjscache", ".eslintmdcache", ".stylelintcache"]
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't end up needing this task because we can use the other linting tasks in parallel instead. An example of this can be found in the package.json changes.

@anthonyshew anthonyshew force-pushed the turbo-optimizations branch from 07d5e0f to 7a4fa1b Compare April 18, 2024 15:33
".stylelintcache",
".prettiercache"
]
"cache": false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any time cache is false, nothing will be sent to outputs. So, we can remove these lines for clarity.

# We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user
# the `${{ needs.base.outputs.turbo_args }}` is a string substitution happening from the base job
run: npx --package=turbo@latest -- turbo prettier ${{ needs.base.outputs.turbo_args }}
run: npx --package=turbo@latest -- turbo lint:js lint:md lint:css prettier ${{ needs.base.outputs.turbo_args }
Copy link
Member

Choose a reason for hiding this comment

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

isn't it dangerous to use the latest version? what if breaking changes are made? we should use the version our website use

Copy link
Contributor Author

@anthonyshew anthonyshew Apr 19, 2024

Choose a reason for hiding this comment

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

I also wondered about this but wasn't going to take the liberty to question it, especially given that the comment right above describes the motivation. I figured a core team member consciously made this choice, carefully considering the tradeoffs - and that I'm not thinking about it deeply enough to understand the hijacking surface being described. I'd be interested in learning more!

Copy link
Member

Choose a reason for hiding this comment

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

I missed that comment 😅

Copy link
Member

Choose a reason for hiding this comment

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

Right, I believe we could use commit pinning here; Bug the idea behind is, I might be wrong, that NPM checks what is the latest version on the registry, and then compares what the latest locally version is installed, so it complicates even if a tiny bit more, that the attacker must match both versions if they want to poison a GitHub Action cache.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 19, 2024

Lighthouse Results

URL Performance Accessibility Best Practices SEO Report
/en 🟠 79 🟢 100 🟢 100 🟢 91 🔗
/en/about 🟢 99 🟢 100 🟢 100 🟢 91 🔗
/en/about/previous-releases 🟢 98 🟢 98 🟢 100 🟢 92 🔗
/en/download 🟢 100 🟢 100 🟢 100 🟢 91 🔗
/en/blog 🟢 99 🟢 100 🟢 100 🟢 92 🔗

@github-actions
Copy link
Contributor

Unit Test Coverage Report

Lines Statements Branches Functions
Coverage: 91%
90.1% (583/647) 76.08% (175/230) 92.12% (117/127)

Unit Test Report

Tests Skipped Failures Errors Time
128 0 💤 0 ❌ 0 🔥 5.393s ⏱️

@ovflowd
Copy link
Member

ovflowd commented Apr 21, 2024

@anthonyshew apparently the new updated command causes a loop?

x root task //#lint (turbo run lint:md lint:js lint:css) looks like it
  | invokes turbo and might cause a loop

@anthonyshew
Copy link
Contributor Author

anthonyshew commented Apr 22, 2024

@ovflowd Hm, that's weird. I changed the GitHub Actions run to not use turbo lint and, instead, call the individual tasks here. Would there be any reason to believe that a stale version of the GitHub Action was run?

For what it's worth, I also see steps listed in the Action failure that have been removed as a part of this pull request.

@ovflowd
Copy link
Member

ovflowd commented Apr 22, 2024

@ovflowd Hm, that's weird. I changed the GitHub Actions run to not use turbo lint and, instead, call the individual tasks here. Would there be any reason to believe that a stale version of the GitHub Action was run?

For what it's worth, I also see steps listed in the Action failure that have been removed as a part of this pull request.

Hmmm, yes? Because the actual workflows used on a PR are the ones from main branch for security reasons.

If you believe this PR is safe to merge we can give it a go and see if things pass on main

@anthonyshew
Copy link
Contributor Author

@ovflowd Makes sense! I was thinking that was set up but didn't want to assume.

As a brief explanation, the new Action will be using turbo lint:md lint:js lint:css directly so turbo won't be calling turbo, per the error message.

I'm confident that this is safe to merge in that regard and happy to play the part of on-call to quickly fix-forward anything that may come up.

@ovflowd
Copy link
Member

ovflowd commented Apr 24, 2024

Let's see if main branch passes, @anthonyshew :)

@ovflowd
Copy link
Member

ovflowd commented Apr 24, 2024

FYI @nodejs/nodejs-website I forced a merge, since the checks would have failed regardless, since the Workflow was being updated.

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.

6 participants