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(pipeline): cache yarn deps with corepack #2405

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

vscaiceanu-1a
Copy link
Member

Proposed change

In node-setup GitHub action, passing cache: yarn doesn't work well with corepack (see issues below).

The goal is to do the cache manually for yarn and to let node-setup do it for npm.

Related issues

actions/setup-node#531

actions/setup-node#182

@vscaiceanu-1a vscaiceanu-1a requested a review from a team as a code owner November 5, 2024 14:44
@github-actions github-actions bot added bug Something isn't working project:@o3r/pipeline labels Nov 5, 2024
@vscaiceanu-1a vscaiceanu-1a force-pushed the bugfix/cache-yarn-deps branch from b909057 to 3375620 Compare November 5, 2024 14:52
fpaul-1A
fpaul-1A previously approved these changes Nov 5, 2024
path: |
.yarn/cache
.yarn/unplugged
.pnp.cjs
Copy link
Contributor

Choose a reason for hiding this comment

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

what if yarn1 or yarn with node_modules and not pnp ?

@vscaiceanu-1a vscaiceanu-1a force-pushed the bugfix/cache-yarn-deps branch 2 times, most recently from 07ebae1 to 180663b Compare November 6, 2024 16:11
@vscaiceanu-1a vscaiceanu-1a force-pushed the bugfix/cache-yarn-deps branch from 180663b to 029f331 Compare November 6, 2024 16:22
- name: Cache dependencies
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not missing the following files:

  • .yarn/unplugged
  • .pnp.cjs
  • .pnp.loader.mjs
    ?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure those are needed. I followed the recommendations from https://github.com/actions/cache/blob/main/examples.md#node---yarn

@@ -41,7 +58,7 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
if (!options.npmRegistry) {
return tree;
}
if (packageManager === 'yarn') {
if (yarn2) {
const yarnrcPath = '/.yarnrc.yml';
if (!tree.exists(yarnrcPath)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this if can now be removed

@vscaiceanu-1a vscaiceanu-1a force-pushed the bugfix/cache-yarn-deps branch 2 times, most recently from eea1cd3 to 51f858e Compare November 6, 2024 19:15
tree.overwrite(yarnrcPath, dump(yarnrcContent, {indent: 2}));
}
} else if (packageManager === 'npm') {
const yarnrcContent = load(tree.readText(yarnrcPath)) as any;
Copy link
Contributor

@matthieu-crouzet matthieu-crouzet Nov 7, 2024

Choose a reason for hiding this comment

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

Suggested change
const yarnrcContent = load(tree.readText(yarnrcPath)) as any;
const yarnrcContent = load(tree.readText(yarnrcPath)) as { npmRegistryServer?: string };

Comment on lines 15 to 16
const yarnrcContent = load(tree.readText(yarnrcPath)) as any;
const yarnPath = yarnrcContent?.yarnPath;
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
const yarnrcContent = load(tree.readText(yarnrcPath)) as any;
const yarnPath = yarnrcContent?.yarnPath;
const { yarnPath } = (load(tree.readText(yarnrcPath)) || {}) as { yarnPath?: string };

- name: Get yarn cache directory path
shell: bash
id: yarn-cache-dir-path
run: echo "dir=$(<% if (yarn2) { %>yarn config get cacheFolder<% } else { %>yarn cache dir<% } %>)" >> $GITHUB_OUTPUT
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we update our pipeline as well ?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could but with a feature request so that the setup action support npm, yarn 1, etc.
Definitely not in a fix on an RC branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you open the request then please :)

Copy link
Member Author

Choose a reason for hiding this comment

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

@vscaiceanu-1a vscaiceanu-1a force-pushed the bugfix/cache-yarn-deps branch from 51f858e to 64c749e Compare November 7, 2024 14:15
@vscaiceanu-1a vscaiceanu-1a force-pushed the bugfix/cache-yarn-deps branch from 64c749e to 8be2a93 Compare November 7, 2024 14:20
@vscaiceanu-1a vscaiceanu-1a merged commit ca9d8f4 into release/11.4.0-rc Nov 7, 2024
28 checks passed
@vscaiceanu-1a vscaiceanu-1a deleted the bugfix/cache-yarn-deps branch November 7, 2024 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working project:@o3r/pipeline
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants