12

I'm trying to set-up and run a GitHub action in a nested folder of the repo.

I thought I could use working-directory, but if I write this:

jobs:
  test-working-directory:
    runs-on: ubuntu-latest
    name: Test
    defaults:
      run:
        working-directory: my_folder
    steps:
      - run: echo test

I get an error:

Run echo test
echo test
shell: /usr/bin/bash -e {0}
Error: An error occurred trying to start process '/usr/bin/bash' with working directory '/home/runner/work/my_repo/my_repo/my_folder'. No such file or directory

I notice my_repo appears twice in the path of the error.

Here is the run on my repo, where:

  • my_repo = novade_flutter_packages
  • my_folder = packages

What am I missing?

2 Answers 2

9

You didn't check out the repository on the second job.

Each job runs on a different instance, so you have to checkout it separately for each one of them.

Sign up to request clarification or add additional context in comments.

2 Comments

I only see one job "test-working-directory:" unless the OP changed their yaml files after you responded.
in this case the OP forgot to checkout. in my experience, the working-directory value is appended to the current working directory instead of being treated as an absolute path.
2

You have to checkout the repository on the runner in order to use files in the repository.

For example, my repository has a /requirements.txt file which I want to pip install -r requirements.txt from, but I have to checkout my repository to ensure the file exists on the runner first.

jobs:
  my-job:
    name: my job
    runs-on: ubuntu-latest
    steps:
      - name: Setup Python
        uses: actions/[email protected]
        with:
          python-version: 3.11
      # without this step, the pip install step will fail
      - name: Checkout the repo 
        uses: actions/checkout@v3
      - name: Install Python requirements
        run: |
          pip install -r requirements.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.