31

I am trying to test out Github Actions for a small web project. I have two projects in the repository, and I want to create a deployment script for only the web client.

The repository looks like this:

root
|
|-src
|  |-API
|  |
|  |-WebClient
|
|-docs

I want to run scripts in the WebClient directory. When I try to cd into ./src/webclient, I get the error no such file or directory

name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Setup Node.js environment
        uses: actions/setup-node@v2.1.2
        
      - name: Open Web Client Directory
        run: |
          ls -la
          cd ./src/webclient
          ls -la
          
      - name: Run a multi-line script
        run: |
          echo Add other actions to build,
          echo test, and deploy your project.
          ls -la

The output for the "Open Web Client Directory" step:

total 28
drwxr-xr-x 5 runner docker 4096 Oct 17 18:05 .
drwxr-xr-x 3 runner docker 4096 Oct 17 18:05 ..
drwxr-xr-x 8 runner docker 4096 Oct 17 18:05 .git
drwxr-xr-x 3 runner docker 4096 Oct 17 18:05 .github
-rw-r--r-- 1 runner docker 6215 Oct 17 18:05 .gitignore
drwxr-xr-x 4 runner docker 4096 Oct 17 18:05 src
/home/runner/work/_temp/43164e53-98ec-41c2-8773-72e94c3453e5.sh: line 2: cd: ./src/webclient: No such file or directory
Error: Process completed with exit code 1.

It looks to be successfully doing the ls -la command, but fails to find the directory ./src/webclient.

Is there something obvious that I am missing? I have tried changing the command to cd src/webclient, and it fails also. This works on two different local machines, one ubuntu and one MacOS.

jlat96
  • 491
  • 1
  • 5
  • 10
  • Is the directory name `WebClient` or `webclient`? The file system is case sensitive, and if it's `WebClient` as you first show, then you have to use `cd src/WebClient` instead of `cd src/webclient`. – Benjamin W. Oct 17 '20 at 20:54

5 Answers5

113

I had an issue where a step was failing with the following, no matter how I configured it:

Error: No such file or directory

Turns out this was because I had not checked out the repository in a previous step!

If you are accessing files from the repo, you need to perform a checkout first:

steps:
  - uses: actions/checkout@v2
sdgluck
  • 24,894
  • 8
  • 75
  • 90
  • 18
    This is something that seems so obvious, it should be clearer in the docs. – Ben Feb 16 '21 at 17:06
  • 1
    is `- uses: actions/checkout@v2` required to access files generated by run: dotnet publish ? – codea Jun 05 '21 at 12:37
  • 1
    This also happens if you try to `echo` on subdirectory, and you do not need your code. You need to add `mkdir {dir}` in your run before the `echo` – nelson6e65 Jan 19 '22 at 23:08
  • The fact this is at ~70 votes suggests that the GitHub Actions should append a `No Such File or Directory` error message when `actions/checkout` has not happened – Ed Smith Jun 15 '22 at 16:51
5

Try this:

- name: Open Web Client Directory
  working-directory: src/webclient
  run: |
    ls -la
3

According to your logs, this seems to be due to case sensitivity: you show the repository to contain src/WebClient (camel cased!), but then you try to cd src/webclient (lowercase).

On macOS, this would work because the filesystem is by default case insensitive; not sure why it works on your Ubuntu system, unless you use something like tab completion, which does the casing for you.

To check what you have in your subdirectories, you can run find src instead of ls -la to see the whole directory tree in src.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
2

A different solution, but it may help someone else.

In my case, I was reading a secret variable with new-lines like this:

echo ${{ secrets.STORE_FILE_BASE64 }} | base64 --decode > ${{ github.workspace }}/android/key.jks

This raised a "Error: No such file or directory". Changing to "${{ secrets.STORE_FILE_BASE64 }}" (note the quotes) solved my problem!

enzo
  • 9,861
  • 3
  • 15
  • 38
0

After reading through many threads I was able to solve a similar problem where my action was failing because my "tmp/" was unable to be found and I was getting the error:

[Errno 2] No such file or directory: 'tmp/video.mp4'

This error appeared while my script was attempting to create a file called "video.mp4" inside the temp directory, but it kept failing because github could not find my tmp folder. However, it worked find locally.

I was able to solve the issue after following these two steps.

  1. The first one was a sanity check and verification to verify which files were seen in my github actions environment. I did this by adding this step to my github actions yml file, after i had checked out:
      - name: Get directory
        run: ls

This command gave the this output:

ETL.py
README.md
google_cloud_functions
requirements.txt
tests.py

As you can see there is no "tmp" directory to be seen. So What I tried to do was to add an empty file to my directory that was not found. I did this by adding a blank text file into the directory tmp.

Then after pushing to github again, and triggering the action. I get this output when running ls inside workflow:

ETL.py
README.md
google_cloud_functions
requirements.txt
tests.py
tmp

Boom my tmp folder shows up.

So in summary, when github was unable to locate my empty directory, I added a new dummy file to that directory, then git add, git commit, and git push, and then git was able to find the directory that it was unable to find before. I suspect that this could work for non empty directories as well as files that cannot be found. For example you could try to modify the file that cannot be found by adding a simple comment to the code.

I am not exactly sure the root cause of this behavior; however, it could have to do with my git history.