How to specify working directory for github actions for monorepo

Viewed 665

Recently I switched from multiple repositories to a monorepo, and I am trying to rewrite my workflows to work with the monorepo. I want to specify path to my subproject for the jobs. For example I have the following job.

- name: Gradle Build
      uses: eskatos/gradle-command-action@v1
      with:
        arguments: build test --stacktrace --info

How do I make this run from a specific subdirectory? (or, if possible, I want to specify a base directory for all jobs in the file)

Thank you in advance.

2 Answers

Nicolas G. answer is correct and would work, but as you explained you wanted to specify a working directory for all jobs in the file, the defaults field is also valid at the workflow level, to avoid repetition.

At the workflow level

defaults:
  run:
    working-directory: ./your_working_dir
jobs:
  job1:
    [...]
  job2:
    [...]

At the job level

jobs:
  job1:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./your_working_dir1
    steps:
    [...]

  job2:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./your_working_dir2
    steps:
    [...]

You can learn more about the defaults field on the Github official documentation.

Related