简体   繁体   中英

Github Actions: No such file or Directory error

Background

I am trying to get a Github Action working with Windows and Bakeware because I am trying to create a release using it.

However, I am having an unexpected issue with creating folders.

Code

Following is a github action that is a Minimal Working Example of the issue. Basically, all steps work, except for the creation of a single folder:

name: build

env:
  MIX_ENV: test
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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

jobs:

  build:
    name: Build on Windows
    runs-on: windows-2019
    env: 
        CC: gcc
        MAKE: make

    steps:
    - uses: actions/checkout@v2
    - uses: erlef/setup-beam@v1
      with:
        elixir-version: '1.13.x' # Define the elixir version [required]
        otp-version: '24.2.x' # Define the OTP version [required]
    
    - name: Install choco
      shell: powershell
      run: |
        Set-ExecutionPolicy -ExecutionPolicy Bypass
        Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

    - name: Install bakeware dependencies
      shell: powershell
      run: choco install -y zstandard make 

    - name: Install Dependencies
      shell: powershell
      run: mix deps.get
 
    - name: Run credo code analyser
      shell: powershell
      run: mix credo --strict

I am even using powershell to do it (even though I am not really sure if this is needed).

Problem

However my GitHub Actions code comes back with this error:

==> bakeware

mkdir "d:/a/market_manager/market_manager/_build/test/lib/bakeware/obj"

mkdir "d:/a/market_manager/market_manager/_build/test/lib/bakeware/launcher"

mkdir "d:/a/market_manager/market_manager/_build/test/lib/bakeware/obj/zstd/lib/decompress"

mkdir: cannot create directory 'd:/a/market_manager/market_manager/_build/test/lib/bakeware/obj/zstd/lib/decompress': No such file or directory

make: *** [Makefile:70: d:/a/market_manager/market_manager/_build/test/lib/bakeware/obj/zstd/lib/decompress] Error 1

could not compile dependency :bakeware, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile bakeware", update it with "mix deps.update bakeware" or clean it with "mix deps.clean bakeware"

** (Mix) Could not compile with "make" (exit status: 2).

For the careful reader, you will notice the part saying:

mkdir: cannot create directory 'd:/a/market_manager/market_manager/_build/test/lib/bakeware/obj/zstd/lib/decompress': No such file or directory

Research

By changing the GitHub Action a little and adding an additional step, I was able to inspect some behaviour:


    - name: Compile everything
      shell: powershell
      run: |
        mkdir "d:/a/market_manager/market_manager/_build/test/lib/bakeware/obj" 
        mkdir "d:/a/market_manager/market_manager/_build/test/lib/bakeware/launcher"
        mkdir "d:/a/market_manager/market_manager/_build/test/lib/bakeware/obj/zstd/lib/decompress"
        ls .\_build\test\lib\bakeware\obj\zstd\lib\decompress
        Test-Path -Path "d:/a/market_manager/market_manager/_build/test/lib/bakeware/obj/zstd/lib/decompress"
        mix deps.compile --all
        mix compile
      env: 
        CC: C:\ProgramData\Chocolatey\bin\gcc.exe
        MAKE: C:\ProgramData\Chocolatey\bin\make.exe
  

In this snippet I manually create the needed folders and then I assert on them. The output is as follows:

    Directory: D:\a\market_manager\market_manager\_build\test\lib\bakeware


Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
d-----         2/2/2022  11:06 AM                obj                                                                   
d-----         2/2/2022  11:06 AM                launcher                                                              


    Directory: D:\a\market_manager\market_manager\_build\test\lib\bakeware\obj\zstd\lib


Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
d-----         2/2/2022  11:06 AM                decompress                                                            
True

We can see that:

  • All directories are created
  • Test-Path returns True , which means that 'd:/a/market_manager/market_manager/_build/test/lib/bakeware/obj/zstd/lib/decompress' does exist.

This only makes things more confusing to me as the error has still not changed:

mkdir: cannot create directory 'd:/a/market_manager/market_manager/_build/test/lib/bakeware/obj/zstd/lib/decompress': No such file or directory
make: *** [Makefile:70: d:/a/market_manager/market_manager/_build/test/lib/bakeware/obj/zstd/lib/decompress] Error 1
could not compile dependency :bakeware, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile bakeware", update it with "mix deps.update bakeware" or clean it with "mix deps.clean bakeware"
** (Mix) Could not compile with "C:\ProgramData\Chocolatey\bin\make.exe" (exit status: 2).

I really can't understand the error No such file or directory when every command I used shows beyond reasonable doubt that the folder does exist .

Question

Why do I keep getting this error?

Answer

After smashing my head against a wall for several days, I think I finally figured it out. The command was failing because of how cmd mkdir behaves, in that, it behaves different from the one in poewrshell.

By changing the Makefile to only create folders if they don't exist already, I was able to fix the issue while still mantaining backwards compatibility, which was one of my requirements.

I have submitted a PR with this fix and at the time of this writing, I am happy to announce it was already merged into master:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM