Skip to content

Fix other workflows to install Corepack as prereq#246

Merged
kanthesha merged 2 commits intomainfrom
fix-workflows-for-yarn-v4
Sep 17, 2024
Merged

Fix other workflows to install Corepack as prereq#246
kanthesha merged 2 commits intomainfrom
fix-workflows-for-yarn-v4

Conversation

@mcmire
Copy link
Copy Markdown
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 review from a team June 20, 2024 22:41
- name: Use Node.js
- uses: actions/checkout@v4
- name: Install Corepack via Node
uses: actions/setup-node@v4
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
rekmarks added a commit to MetaMask/ocap-kernel that referenced this pull request Jul 12, 2024
Converts this repository to a monorepo per the conventions of
https://github.com/MetaMask/core, with some inspiration from
https://github.com/MetaMask/snaps where applicable. Also replaces `tsup`
with `ts-bridge` per MetaMask/providers#336.

This includes a direct copy of
MetaMask/metamask-module-template#246.

---------

Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
Copy link
Copy Markdown
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.

runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
Copy link
Copy Markdown
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]

- prepare
strategy:
matrix:
node-version: [18.x, 20.x]
Copy link
Copy Markdown
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]

- prepare
strategy:
matrix:
node-version: [18.x, 20.x]
Copy link
Copy Markdown
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
@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