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
Answer from peterevans on Stack Overflow
Top answer
1 of 4
530

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
2 of 4
419

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.

Discussions

How do I change where a GitHub Action runs?
Today I created my first GitHub Action using a template for ASP.NET Core. It performs a build on the main branch, which at this point is all I'm interested in doing. However, it failed with a "MSB1... More on github.com
🌐 github.com
1
3
Use working-directory for entire job
As established doesn't work for step with uses (aka Actions) therefore a hackfix at best. Beta Was this translation helpful? Give feedback. ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... For job level working-directory , I would recommand you to share your scenario and requirement in the Feedback form for GitHub ... More on github.com
🌐 github.com
20
130
November 14, 2019
Why is GitHub Actions 'doubling' my working directory name?
The workspace your repo's action is run in is named the same as your repo. Then you are doing a code checkout of the repo code into a new directory in the workspace that also has the same name. ./TestApp is the workspace, ./TestApp/TestApp is the root dir of the checked out repo. More on reddit.com
🌐 r/devops
19
0
September 7, 2024
GitHub actions - get absolute path to working directory - Stack Overflow
In Maven, I need to provide absolute path to a directory in my project. How can I get absolute path to the directory GitHub action is running in? More on stackoverflow.com
🌐 stackoverflow.com
🌐
DEV Community
dev.to › jajera › understanding-github-actions-working-directory-550o
Understanding GitHub Actions Working Directory - DEV Community
January 7, 2025 - jobs: example-job: runs-on: ubuntu-latest defaults: run: working-directory: ./job-scripts steps: - name: Run job-level script run: ./script.sh · Effect: All run commands in the example-job will execute from the ./job-scripts directory. ... Effect: Only this specific step will execute from the ./step-scripts directory. GitHub Actions runners expose several environment variables that you can use to dynamically reference paths during workflows.
🌐
GitHub
github.com › orgs › community › discussions › 118464
Working directory path · community · Discussion #118464
For example, if you have a directory in your repository called repo, you would set the working directory like this: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Run a multi-line script run: | echo Add your commands here echo Use a new line for each command working-directory: repo
🌐
DEV Community
dev.to › shofol › run-your-github-actions-jobs-from-a-specific-directory-1i9e
Run your Github Actions jobs from a specific directory - DEV Community
December 12, 2024 - jobs: job1: runs-on: ubuntu-latest defaults: run: working-directory: scripts ... Here is a simple Actions for NodeJs build job.
🌐
GitHub
docs.github.com › articles › getting-started-with-github-actions
Understanding GitHub Actions - GitHub Docs
Workflows are defined by a YAML ... manually, or at a defined schedule. Workflows are defined in the .github/workflows directory in a repository....
Find elsewhere
🌐
BioErrorLog
en.bioerrorlog.work › top › github
Get the Absolute Path of the Default Working Directory in GitHub Actions - BioErrorLog Tech Blog
February 28, 2025 - - run: | echo $GITHUB_WORKSPACE # Example output # /home/runner/work/actions-tests/actions-tests · You can also get the same value from the workspace property of the github context. ... The default working directory on the runner for steps, and the default location of your repository when using the checkout action.
🌐
GitHub
docs.github.com › actions › using-workflows › workflow-syntax-for-github-actions
Workflow syntax for GitHub Actions - GitHub Docs
You must store workflow files in the .github/workflows directory of your repository. The name of the workflow. GitHub displays the names of your workflows under your repository's "Actions" tab.
🌐
CICube
cicube.io › blog › github-actions-working-directory
Understanding "working-directory" in GitHub Actions | CICube
October 4, 2024 - This is beneficial for projects ... ... In GitHub Actions, the working-directory option specifies in what directory the shell should run for a given step, job or workflow....
🌐
Reddit
reddit.com › r/devops › why is github actions 'doubling' my working directory name?
r/devops on Reddit: Why is GitHub Actions 'doubling' my working directory name?
September 7, 2024 -

Been pulling my hair out over this for a while, I'm a github actions noob, but everything was working fine on a different project.

in my workflow/depoly.yml I have

- name: Print current working directory
        run: pwd

In the console it prints out

/home/runner/work/TestApp/TestApp

Which makes no sense. because my repository is just

username/TestApp

I even deleted all github files, created a new repo, init push etc. and it does the exact same thing.

I've never had this issue.

This is now apparantly happening in ALL of my github repos - no idea what changed....

🌐
Reddit
reddit.com › r/github › how to pass a folder via re-usable action workflow?
r/github on Reddit: How to pass a folder via re-usable action workflow?
January 15, 2024 -

Greetings! Trying to figure out if this is even possible, but I'm looking to standardize something via a re-usable workflow.

I would like to pass a directory with source code to a re-useable workflow. The re-useable workflow will then use that passed folder as the working directory:

Here is some dummy code to represent what I'm trying to do, see re-useable workflow.yml:

name: My Re-usable Workflow!

on:
  workflow_call:
    inputs:
     dir:
        required: true
        type: string

jobs:
  run-job:
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Test Hello World!
        working-directory: ${{ inputs.dir }}
        run: |
          chmod +x hello-world.sh
          ./hello-world.sh

Below is my original workflow that calls the re-usable one:

name: Original workflow calling re-useable one


jobs:
  call-reusable-workflow:
    uses: org/repo/.github/workflows/function1.yml@dev
    with:
      dir: /my-folder

My workflow above is essentially just passing the string /my-folder, but I would like to pass the entire directory. Inside /my-folder I have a hello world script just so I can test for functionality between passing a directory via workflow.

Would appreciate any guidance and if this is the way to proceed regarding my objective.

🌐
GitHub
github.com › changesets › action › issues › 265
Option to specify working directory in GitHub Actions · Issue #265 · changesets/action
February 22, 2023 - GitHub allows specifying working-directory to run a step in a specific directory. I'm working in a large repo with lots of different directories - one of those directories is my typescript project. .changesets is added in there at
Author   o-az
🌐
Baeldung
baeldung.com › home › git › running github actions in another directory
Running GitHub Actions in Another Directory | Baeldung on Ops
September 4, 2024 - name: working-directory Demo on: push: branches: - main defaults: run: working-directory: directory_3 jobs: job1: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: cat file_1 job2: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: cat file_2 job3: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: cat file_3 job4: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: cat file_4 · In the command above, the jobs used the same working directory. So, instead of defining the working directory for each job, we defined the working directory just once at the job level. In this article, we described how to make Github Actions run in a different directory using the cd command, absolute path, and working-directory keyword.
🌐
GitHub
github.com › actions › checkout › issues › 1430
Support checkout of subdirectory into working directory · Issue #1430 · actions/checkout
August 15, 2023 - GitHub Actions are somewhat limited in what paths can be used in which tasks. With run: steps, it's possible to set a custom working directory with the working-directory option, but this is not sup...
Author   srgoni