Skip to content

Commit

Permalink
fix(pipeline): cache yarn deps with corepack
Browse files Browse the repository at this point in the history
  • Loading branch information
vscaiceanu-1a committed Nov 6, 2024
1 parent 78ac431 commit 07ebae1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
8 changes: 6 additions & 2 deletions packages/@o3r/pipeline/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
}
context.logger.info(`Setting up pipeline for package manager: "${packageManager}" `);
const setupCommand = packageManager === 'yarn' ? 'yarn install --immutable' : 'npm ci';
const isYarn2 = packageManager === 'yarn' && tree.exists('/.yarnrc.yml');
const yarnCacheFolder = isYarn2 ? 'yarn config get cacheFolder' : 'yarn cache dir';
const baseTemplateSource = apply(url(`./templates/${options.toolchain}`), [
template({
...options,
packageManager,
setupCommand,
actionVersionString,
yarnCacheFolder,
dot: '.'
}),
move(tree.root.path)
Expand All @@ -41,7 +44,7 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
if (!options.npmRegistry) {
return tree;
}
if (packageManager === 'yarn') {
if (isYarn2) {
const yarnrcPath = '/.yarnrc.yml';
if (!tree.exists(yarnrcPath)) {
tree.create(yarnrcPath, dump({'npmRegistryServer': options.npmRegistry}, {indent: 2}));
Expand All @@ -50,7 +53,8 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
yarnrcContent.npmRegistryServer = options.npmRegistry;
tree.overwrite(yarnrcPath, dump(yarnrcContent, {indent: 2}));
}
} else if (packageManager === 'npm') {
} else {
// both npm and yarn 1 use .npmrc for the registry
const npmrcPath = '/.npmrc';
if (!tree.exists(npmrcPath)) {
tree.create(npmrcPath, `registry=${options.npmRegistry}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@ runs:
steps:
- uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version: 20
cache: <%= packageManager %>
node-version: 20<% if (packageManager !== 'yarn') { %>
cache: <%= packageManager %><% } %>
- name: Enable Corepack
shell: bash
run: corepack enable
- name: Install
<% if (npmRegistry) { %>
run: corepack enable<% if (packageManager === 'yarn') { %>
- name: Get yarn cache directory path
shell: bash
id: yarn-cache-dir-path
run: echo "dir=$(<%= yarnCacheFolder %>)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn
${{ runner.os }}<% } %>
- name: Install<% if (npmRegistry) { %>
env:
COREPACK_NPM_REGISTRY: <%= npmRegistry %>
COREPACK_INTEGRITY_KEYS: ""
<% } %>
COREPACK_INTEGRITY_KEYS: ""<% } %>
shell: bash
run: <%= setupCommand %>

0 comments on commit 07ebae1

Please sign in to comment.