Can't specify "working-directory" for actions? Only for commands?

To the best of my knowledge the “working-driectory” argument isn’t supported for the uses keywork, only for runs or something. This means that something as incredibly basic, as running yarn install against a subfolder, is incredibly difficult in github actions!

7 Likes

I tested and tried, if use the working-directory argument to specify a working directory for the action, it will return the warning “ working-directory cannot be used with uses ”, and the workflow will failed with incorrect syntax error. Looks like the working-directory argument indeed is not supported to specify a working directory for action.

However, as a workaround, maybe you can try define a input argument in the action.yaml of the action to specify the working directory of the action execution, and use a command to switch to the specified working directory at the beginning of the action execution.

I’m using this workflow for Angular:

name: Build
on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [12.x]

    steps:
      - uses: actions/checkout@v1

      - name: Cache node modules
        uses: actions/cache@v1
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
      - name: Node ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: npm ci and npm run build
        run: |
          npm ci
          npm run build:ci

And I have the same problem because the project is in a subfolder called client and I can’t use working-directory with uses…

What can I do here ? Sorry I’m completely new.

This doesn’t work. The cd command doesn’t exist. I get the following:

##[error]Unable to locate executable file: cd. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.

Workaround: use defaults. It’s a top-level field, the same as “on” or “jobs”:

defaults:
  run:
    working-directory: ./src

Then running things like yarn install works for me

1 Like