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

Update pnpm and use corepack #4628

Merged
merged 3 commits into from
Jul 19, 2024
Merged

Update pnpm and use corepack #4628

merged 3 commits into from
Jul 19, 2024

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Jul 17, 2024

Fixes

Fixes #3807 by @dhruvkb

Description

This PR replaces pnpm/action-setup@v3 with corepack enable for setting up pnpm in the CI and Docker containers.
For the Playwright Docker containers, corepack looks into the closest package.json file to find the pnpm version, so I added it in the frontend/package.json

Since we no longer need to provide the pnpm version to the set up script (it's extracted from package.json's packageManager field), I removed the related env variables.

Testing Instructions

The CI should pass.

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (ov just catalog/generate-docs for catalog
    PRs) or the media properties generator (ov just catalog/generate-docs media-props
    for the catalog or ov just api/generate-docs for the API) where applicable.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@openverse-bot openverse-bot added 🧱 stack: frontend Related to the Nuxt frontend 🧱 stack: mgmt Related to repo management and automations 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work 🟩 priority: low Low priority and doesn't need to be rushed 🧰 goal: internal improvement Improvement that benefits maintainers, not users 💻 aspect: code Concerns the software code in the repository labels Jul 17, 2024
@obulat obulat removed the 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work label Jul 17, 2024
@obulat obulat force-pushed the update/pnpm branch 4 times, most recently from 3bd8050 to 2ce40f2 Compare July 17, 2024 13:48
Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

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

Approving even though it's a draft because it's great. I love Corepack and happy to see it being used more.

@@ -3,6 +3,7 @@
"description": "Openverse frontend",
"private": true,
"version": "2.2.1",
"packageManager": "pnpm@9.5.0",
Copy link
Member

Choose a reason for hiding this comment

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

Please correct me if I'm wrong but I was under the impression that packageManager is only read from the package.json in the repo root.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is necessary for the Playwright Docker setup, not the frontend (I think frontend can use the root package.json). The node corepack docs say "The Corepack proxies will find the closest package.json file in your current directory hierarchy to extract its "packageManager" property."

Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be great to run Playwright from the repo root context instead, if not for this PR (makes sense, might be a big change), then in a separate issue.

It would be really great if Playwright ran inside ov so we didn't have to have a separate docker container for it, but that's a separate story.

frontend/Dockerfile.playwright Show resolved Hide resolved
.github/actions/setup-env/action.yml Show resolved Hide resolved
@@ -3,6 +3,7 @@
"description": "Openverse frontend",
"private": true,
"version": "2.2.1",
"packageManager": "pnpm@9.5.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be great to run Playwright from the repo root context instead, if not for this PR (makes sense, might be a big change), then in a separate issue.

It would be really great if Playwright ran inside ov so we didn't have to have a separate docker container for it, but that's a separate story.

uses: pnpm/action-setup@v3
# Automatically reads `packageManager` field from root `package.json`.
shell: bash
# Corepack automatically reads `packageManager` field from root `package.json`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This kind of comment is sort of just documenting what Corepack is isn't it? Do we need this kind of comment? I'd argue it wasn't necessary for pnpm/action-setup either.

What's the benefit of using corepack here instead of the action, by the way? Just consistency or is there something else? The action does quite a lot of things, including basic clean up steps that are apparently necessary for GitHub actions (store prune at the end of the job, for example).

Is corepack by itself, without any additional support steps or jobs, sufficient to actually replace what pnpm/action-setup does? It's not only installing pnpm, after all: https://github.com/pnpm/action-setup/blob/master/src/index.ts#L8-L17

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The main reason is consistency and the removal of one extra dependency that needs to be updated.

I've seen many large projects use corepack enable instead of pnpm/action-setup. Do you think we really need all of the steps that the action does? Is store pruning important during the CI, if we are discarding the containers at the end anyway?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have no idea what the purpose of store pruning is at the end of the action, all I know is that pnpm/action-setup does it, and lots of other actions have similar clean up type steps. I have not read about why that is or what the advice is for this (I've never written of this nature). To clarify, store pruning is on the host, not inside the docker images, so relevant for when we run pnpm install in the next step after this one.

Based on a quick search, I can't find anything clear or definitive on why clean up steps are necessary, other than suggestions that while runners are intended to be ephemeral, clean up helps prevent any accidental leaks between runners. In our case, the pnpm store shouldn't have an issue in that regard, not that I can think of off the top of my head. We don't download and proprietary packages from private repositories, for example, so it isn't like there is IP that could leak between runners if ephemerality didn't work as expected. It also seems like it might be more relevant for self-hosted runners (perhaps those have different behaviour in this regard).

Signed-off-by: Olga Bulat <obulat@gmail.com>
Signed-off-by: Olga Bulat <obulat@gmail.com>
Signed-off-by: Olga Bulat <obulat@gmail.com>
@obulat obulat self-assigned this Jul 18, 2024
@obulat obulat marked this pull request as ready for review July 18, 2024 10:43
@obulat obulat requested review from a team as code owners July 18, 2024 10:43
Copy link
Collaborator

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

Don't have much to add beyond what others have shared, but I'm glad we can get rid of some of the env vars here! 🙂

@obulat obulat merged commit 9bdc326 into main Jul 19, 2024
60 checks passed
@obulat obulat deleted the update/pnpm branch July 19, 2024 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🟩 priority: low Low priority and doesn't need to be rushed 🧱 stack: frontend Related to the Nuxt frontend 🧱 stack: mgmt Related to repo management and automations
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Replace pnpm/action-setup with Corepack
5 participants