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

Fix other workflows to install Corepack as prereq #246

Merged
merged 2 commits into from
Sep 17, 2024

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Jun 11, 2024

A recent commit upgraded the version of Yarn to v4 and removed the Yarn binary from the repo, thereby requiring that Corepack be installed in order to install dependencies. The build-lint-test was updated to install Corepack, but not the documentation-related workflows, so they are failing.

This commit fixes those workflows to install Corepack. It also cleans up some work that was done in previous commits:

  • In the build-lint-test workflow we ensure that prepare is run once per Node version we are testing and that build and lint use the latest Node version we are testing.
  • In steps where we are installing Node just to gain access to the corepack executable, we use .nvmrc (the version of Node we use for development) to know which version of Node to install rather than using the latest LTS (lts/*). For jobs that do not need to concern themselves with being run in multiple Node versions, this ensures that consistent Node versions are used in this step vs. the step that is used to simply restore the Yarn cache.
  • The checkout step always goes first, this way .nvmrc can be read.

A recent commit upgraded the version of Yarn to v4 and removed the Yarn
binary from the repo, thereby requiring that Corepack be installed in
order to install dependencies. The `build-lint-test` was updated to
install Corepack, but not the documentation-related workflows, so they
are failing.

This commit fixes those workflows to install Corepack. It also cleans up
some work that was done in previous commits:

- In the `build-lint-test` workflow we ensure that `prepare` is run once
per Node version we are testing and that `build` and `lint` use the
latest Node version we are testing.
- In steps where we are installing Node just to gain access to the
`corepack` executable, we use `.nvmrc` (the version of Node we use for
development) to know which version of Node to install rather than using
the latest LTS (`lts/*`). For jobs that do not need to concern
themselves with being run in multiple Node versions, this ensures that
consistent Node versions are used in this step vs. the step that is used
to simply restore the Yarn cache.
- The checkout step always goes first, this way `.nvmrc` can be read.
@mcmire mcmire marked this pull request as ready for review June 20, 2024 22:41
@mcmire mcmire requested a review from a team as a code owner June 20, 2024 22:41
@mcmire mcmire requested a review from a team June 20, 2024 22:42
strategy:
matrix:
node-version: [18.x, 20.x]
steps:
- name: Use Node.js
- uses: actions/checkout@v4
- name: Install Corepack via Node
uses: actions/setup-node@v4
Copy link
Contributor

@legobeat legobeat Jun 21, 2024

Choose a reason for hiding this comment

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

The checkout step always goes first, this way .nvmrc can be read.

There was a valid reason to do actions/setup-node before checkout because of the action not being corepack-compatible. IIRC it throws an error when the preinstalled yarn version does not match the packageManager one in package.json (which is then working after a corepack enable).

Could potentially cause issues with any dependencies that rely on the specific package manager version in their installation step, if any (since setup-node performs dependency installation in presence of package.json)?

Copy link
Contributor Author

@mcmire mcmire Jun 21, 2024

Choose a reason for hiding this comment

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

I didn't find evidence in the source that it installs dependencies — I think you still have to do that yourself.

It does run yarn to figure out how to cache Yarn files, and Yarn v1 is preinstalled on the GitHub runners, and Yarn v1 throws if packageManager refers to a non-1.x release. So you're right about that. But... setup-node should only try to run yarn if you pass the cache option to setup-node. I left that option off the first setup-node call (as you'd done) and I re-ran setup-node with caching after installing Corepack. I don't see how that could cause issues, but do you still see a case in which this could fail?

As for your final point:

Could potentially cause issues with any dependencies that rely on the specific package manager version in their installation step

Does Yarn consult packageManager for dependencies? I wasn't aware that it did that. I thought it only consulted it for the root package.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does Yarn consult packageManager for dependencies? I wasn't aware that it did that. I thought it only consulted it for the root package.

It does a few somewhat unexpected things, yes.. Among them: yarnpkg/berry#6258

@mcmire mcmire mentioned this pull request Jun 25, 2024
3 tasks
Copy link
Contributor

@kanthesha kanthesha left a comment

Choose a reason for hiding this comment

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

LGTM.

@@ -7,41 +7,47 @@ jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
node-version: [18.x, 20.x]
node-version: [18.x, 20.x, 22.x]

runs-on: ubuntu-latest
needs:
- prepare
strategy:
matrix:
node-version: [18.x, 20.x]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
node-version: [18.x, 20.x]
node-version: [18.x, 20.x, 22.x]

runs-on: ubuntu-latest
needs:
- prepare
strategy:
matrix:
node-version: [18.x, 20.x]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
node-version: [18.x, 20.x]
node-version: [18.x, 20.x, 22.x]

@kanthesha kanthesha merged commit 570f6c2 into main Sep 17, 2024
17 checks passed
@kanthesha kanthesha deleted the fix-workflows-for-yarn-v4 branch September 17, 2024 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

module-template publishing (maybe other things as well) is broken.
3 participants