Unning GitHub Action setup-node in sub directory

Hi, I have a repository with a npm project in a sub directory. I liked to use actions/setup-node@v2 as described in Publishing Node.js packages - GitHub Docs. But when using working-directory: dirname it says: The workflow is not valid. .github/workflows/experiment.yml (Line: 15, Col: 9): Unexpected value 'working-directory' but there isn’t a propery documented for actions/setup-node@v2 where I can define the directory. Does someone has any ideas?

Git Structure

  • /
    • /.github/workflow/experiment.yml
    • /dirname
      • /dirname/package.json
      • /dirname/index.js


name: Node.js Package
    branches: [main]
    runs-on: ubuntu-latest
      contents: read
      packages: write
      - uses: actions/checkout@v2
      # Setup .npmrc file to publish to GitHub Packages
      - uses: actions/setup-node@v2
        working-directory: dirname
          node-version: '12.x'
          registry-url: 'https://npm.pkg.github.com'
          # Defaults to the user or organization that owns the workflow file
          scope: '@company'
      - run: npm install
        working-directory: dirname
      - run: npm publish
        working-directory: dirname
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Does someone has an idea? It doesn’t feels like an unusual requirement to have a sub directory with a node project. So I expect it should be working somehow.

the working-directory keyword only works with a run command. The setup-node action isn’t designed to use that keyword. Why do you have to target that subfolder? WHy not just use setup-node to setup the version on the runner to be used? Then it will be used by your following run steps.

So the action should created the .npmrc with the given registry-url and scope is in the correct location, not on the root but on the subfolder.

You can set cache-dependency-path Node.js CI Github Action Monorepo modifications

Thanks. It’s not about caching. It’s to set registry url for publication. I’ve solved it now with.

    - name: Configure NPM
      working-directory: dirname
      run: |
        echo "//npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}" >> .npmrc
        echo "always-auth: true" >> .npmrc