Skip to content
18 changes: 14 additions & 4 deletions .github/workflows/app-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,27 @@ jobs:
uses: actions/setup-node@v4
Copy link

Choose a reason for hiding this comment

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

(Not in this PR) Above this line we have apt install gettext. I've seen it's common to run apt update && ... first to make sure the package indexes are up to date.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that makes sense as a defensive improvement. It wasn’t related to the Yarn 4 issue addressed by this PR, which is why I didn’t include it in the original change, but I agree that apt update && apt install ... would be more correct. I can include it here if you want, or leave it for a separate small cleanup PR.

Copy link

Choose a reason for hiding this comment

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

Both options are ok by me.

with:
node-version-file: ".nvmrc"
cache: "yarn"

- name: Enable Corepack
run: corepack enable

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "YARN_CACHE_DIR=$(yarn cache dir)" >> $GITHUB_ENV
run: |
YARN_MAJOR=$(yarn --version | cut -d. -f1)
if [ "$YARN_MAJOR" = "1" ]; then
CACHE_DIR=$(yarn cache dir)
else
CACHE_DIR=$(yarn config get cacheFolder)
fi
if [ -z "$CACHE_DIR" ]; then CACHE_DIR="$RUNNER_TEMP/yarn-cache"; fi
echo "ACTIONS_YARN_CACHE_PATH=$CACHE_DIR" >> $GITHUB_ENV
Copy link

Choose a reason for hiding this comment

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

It seems some kind of cache is supported out of the box from v2, maybe this pattern was necessary only for v1? (I am not really familiar with this)

https://github.com/actions/setup-node?tab=readme-ov-file#caching-global-packages-data
https://stackoverflow.com/a/62244232/188031

Copy link
Author

Choose a reason for hiding this comment

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

I tested that approach explicitly to simplify the workflow, but it fails for Yarn 4 projects before we even reach corepack enable.

When actions/setup-node is used with cache: "yarn", it resolves the Yarn cache inside its own step and ends up running yarn cache dir with the runner's global Yarn (1.22.22). In repositories that declare packageManager: yarn@4.x, that aborts before Corepack can be enabled.

So in this case I’m intentionally keeping setup-node without cache: "yarn", enabling Corepack first, and then resolving/caching the path manually. I also simplified that logic so the cache path resolution is now explicit for Yarn 1 and Yarn 4.


- name: Cache yarn dependencies
uses: actions/cache@v3
uses: actions/cache@v5
id: yarn-cache
with:
path: ${{ env.YARN_CACHE_DIR }}
path: ${{ env.ACTIONS_YARN_CACHE_PATH }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
Expand Down
29 changes: 26 additions & 3 deletions .github/workflows/bundlemon-build-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,34 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc' # Use the Node.js version specified in .nvmrc
cache: 'yarn'
node-version-file: '.nvmrc'

- name: Enable Corepack
run: corepack enable

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: |
YARN_MAJOR=$(yarn --version | cut -d. -f1)
if [ "$YARN_MAJOR" = "1" ]; then
CACHE_DIR=$(yarn cache dir)
else
CACHE_DIR=$(yarn config get cacheFolder)
fi
if [ -z "$CACHE_DIR" ]; then CACHE_DIR="$RUNNER_TEMP/yarn-cache"; fi
echo "ACTIONS_YARN_CACHE_PATH=$CACHE_DIR" >> $GITHUB_ENV

- name: Cache yarn dependencies
uses: actions/cache@v5
id: yarn-cache
with:
path: ${{ env.ACTIONS_YARN_CACHE_PATH }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Cache npm for npx-scoped tools
uses: actions/cache@v3
uses: actions/cache@v5
with:
path: ~/.npm
key: ${{ runner.os }}-npm-npx
Expand Down