-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support working_directory
#706
Comments
Hello @fengxia41103 ! steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Install dependencies
run: npm ci
working-directory: ./frontend
- name: Build
run: npm run build
working-directory: ./frontend |
- uses: actions/setup-node@v3
with:
node-version: '18.12.1'
cache: 'npm' is
NVM! I realized |
t looks like the error message is indicating that the lock file for the dependencies is not found in the specified directory. The supported lock file patterns are package-lock.json, npm-shrinkwrap.json, and yarn.lock. However, it seems that you have identified the cause of the issue yourself. The cache: 'npm' parameter in the actions/setup-node step may be causing problems. Removing it may have resolved the issue. If you still encounter issues, you could try running npm install or yarn install in your workflow to generate the lock file. Alternatively, you could specify the path to the lock file using the working-directory parameter in the actions/checkout step. |
I have the same issue and removing cache solves the problem. But this loses caching functionality. |
I've encountered this issue after switching to the integrated caching in
Here's an example with Yarn and a
And here's my working config file. |
I can confirm that the solution proposed by @darekkay works as expected. |
For monorepos, I think Another property that has problems with this is defaults:
run:
working-directory: ./frontend
- uses: actions/setup-node@v3
with:
node-version-file: ./frontend/.nvmrc
cache-dependency-path: ./frontend/yarn.lock
cache: yarn |
@darekkay's solution worked for me - maybe this could be improved by making the docs a bit clearer? I searched for directory, working directory, etc but it wasn't clear to me there was an option to tweak this. Based on my googlin' and this issue, it seems like a lot of people are led down the path of "oh, I'll just do this and set my working-directory" to no avail. |
I also confirm this weird issue with I rely on basic GitHub Actions template for NodeJS build and test, which always works OK. But this time my code was in sub-directory. What can be easier, right? on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./docker-test-containers/
strategy:
matrix:
node-version: [19.x, 20.x, 21.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# cache: 'npm' # commenting SOLVED MY issue and build was OK
- run: |
npm ci
npm test
I know, caching is important. But who would believe that simple matter of changing working directory would cause a build to fail. So how to run this WITH caching then? Adding cache back and ADDITIONALLY cache: 'npm'
cache-dependency-path: './docker-test-containers/' Output from logs: Run actions/setup-node@v3
with:
node-version: 19.x
cache: npm
cache-dependency-path: ./docker-test-containers/
always-auth: false
check-latest: false
token: *** So, cache-dependency-path matters :) Although, still don't get why |
This reverts commit 375b047. I'm going to try this (removing cache: 'npm'): actions/setup-node#706 (comment) It looks like setup-node isn't supposed to need a package.json present at the project root.
at the top level, I guess. actions/setup-node#706 (comment)
Works as expected, Figured out that npm is looking up package.json and the like in the root of my repo where clearly there is nothing there for npm to use. I tried changing the run command working dir but the problem lies as mentioned earlier. In short, this works for me, thank you! |
for pnpm user, check here: https://github.com/tjx666/node-action-test/blob/main/.github/workflows/test.yml name: Test
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./web
steps:
- name: Checkout the project
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
package_json_file: web/package.json
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: web/.nvmrc
cache: pnpm
cache-dependency-path: web/pnpm-lock.yaml
- name: Install deps
run: pnpm install
- name: Test
run: pnpm test |
Description:
Support
working_directory
value.Justification:
I have a mono-repo project whereas folder structure is:
To build
frontend
, I need to setworking_directory
tofrontend
, butuse
is not observing this value.Are you willing to submit a PR?
No
The text was updated successfully, but these errors were encountered: