github actions: debugging 'no such file or directory'

2021-09-12

 | 

~1 min read

 | 

183 words

When I was writing a Github action to automatically bump the version of the package on merge, my first attempt had a job that would try to run a Node script:

.github/workflows/bumpVersionOnPushToMain.yml
jobs:
  scripts:
    runs-on: ubuntu-latest
    steps:
      - run: ./scripts/node-script.js

Unfortunately, every time the action fired it threw an error.

/home/runner/work/_temp/eb8554b7-c24c-42a2-b406-ad1796ed6740.sh: line 1: /home/runner/work/github-actions-cra/github-actions-cra/.github/scripts/node-script.js: No such file or directory

The answer, it turns out, is to ensure that the repository itself is checked out. The easiest way I found to do this is with actions/checkout@v2. While it defaults to using the current directory, there are a lot of interesting options available.

In this particular case, the fix is adding the action in the line immediately preceding any step in a job that will need to act on the repository:

.github/workflows/bumpVersionOnPushToMain.yml
jobs:
  scripts:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: ./scripts/node-script.js

With that in place, my script was found by the runner (though to be safe, I added a chmod step to ensure that the script would also be executable).

H/t to sdgluck for the answer on Stack Overflow.


Related Posts
  • 2021 Daily Journal


  • Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!