Running actions in another directory

Hope this will help somebody

name: CI

on:
 ...

defaults:
 run:
  working-directory: ./app

jobs:
 ...

Update: It's now possible to set a working-directory default for a job. See this answer.

There is an option to set a working-directory on a step, but not for multiple steps or a whole job. I'm fairly sure this option only works for script steps, not action steps with uses.

https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsrun

Using working-directory, your workflow would look like this. It's still quite verbose but maybe a bit cleaner.

name: CI

on: [push]

jobs:
  phpunit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Setup Symfony
        working-directory: ./app
        run: cp .env.dev .env
      - name: Install Composer Dependencies
        working-directory: ./app
        run: composer install --prefer-dist
      - name: Run Tests
        working-directory: ./app
        run: php bin/phpunit

Alternatively, you can run it all in one step so that you only need to specify working-directory once.

name: CI

on: [push]

jobs:
  phpunit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Setup and run tests
        working-directory: ./app
        run: |
          cp .env.dev .env
          composer install --prefer-dist
          php bin/phpunit

You can now add a default working directory for all steps in a job: docs

For the example here, this would be:

name: CI

on: [push]

jobs:
  phpunit:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./app
    steps:
      - uses: actions/checkout@v1
      - name: Setup Symfony
        run: .env.dev .env
      - name: Install Composer Dependencies
        run: composer install --prefer-dist
      - name: Run Tests
        run: php bin/phpunit

Caveat: this only applies to run steps; eg you'll still need to add the subdirectory to with parameters of uses steps, if required.