简体   繁体   English

Github 操作:没有这样的文件或目录错误

[英]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.我正在尝试获得与 Windows 和Bakeware一起使用的 Github 操作,因为我正在尝试使用它创建一个版本。

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.以下是 github 操作,它是该问题的最小工作示例。 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).我什至正在使用 powershell 来做到这一点(即使我不确定是否需要这样做)。

Problem问题

However my GitHub Actions code comes back with this error:但是我的 GitHub Actions 代码返回此错误:

==> 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:通过稍微更改 GitHub 操作并添加一个额外的步骤,我能够检查一些行为:


    - 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: output如下:

    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. Test-Path返回True ,这意味着'd:/a/market_manager/market_manager/_build/test/lib/bakeware/obj/zstd/lib/decompress'确实存在。

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 .当我使用的每个命令都毫无疑问地表明该文件夹确实存在时,我真的无法理解错误No such file or directory

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.由于 cmd mkdir的行为方式,该命令失败,因为它的行为与 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.通过将Makefile更改为仅在文件夹不存在时创建文件夹,我能够解决问题,同时仍然保持向后兼容性,这是我的要求之一。

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:我已经提交了包含此修复程序的 PR,在撰写本文时,我很高兴地宣布它已经合并到 master 中:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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