prosource

Windows-최신 호스트 실행자에 대한 github 작업 워크플로우 파일의 PATH 업데이트 방법

probook 2023. 8. 11. 22:24
반응형

Windows-최신 호스트 실행자에 대한 github 작업 워크플로우 파일의 PATH 업데이트 방법

현재 GitHub 작업 워크플로우를 보고서에 추가하려고 합니다...

C++/CMake/swig/python 개발(즉, 네이티브 파이썬 라이브러리 개발)을 수행하려면 swigwin을 다운로드하여 설치하고 swigwin을 에서 사용할 수 있어야 합니다.PATH...

불행하게도 그것은$env:Path...다음 단계에서는 명령이 고려되지 않습니다.

name: Python Windows CI

on: [push, pull_request]

jobs:
  # Building using the GitHub runner environment directly.
  build:
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v2
    - name: Check cmake
      run: cmake --version
    - name: Install swig
      run: |
        (New-Object System.Net.WebClient).DownloadFile("http://prdownloads.sourceforge.net/swig/swigwin-4.0.1.zip","swigwin-4.0.1.zip");
        Expand-Archive .\swigwin-4.0.1.zip .;
        $env:Path += ";.\swigwin-4.0.1";
        swig -version;
    - name: Check swig
      run: swig -version # swig cmdlet not found...

관찰된

> Set up job
> Run actions/checkout@v23s
> Check cmake
v Install swig
...
SWIG Version 4.0.1
...
v Check swig
 swig -version
  shell: C:\Program Files\PowerShell\6\pwsh.EXE -command ". '{0}'"
swig : The term 'swig' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\a\_temp\0a8dc0e1-ec51-429b-abd0-cb3597e983ac.ps1:2 char:1
+ swig -version
+ ~~~~
+ CategoryInfo          : ObjectNotFound: (swig:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException

##[error]Process completed with exit code 1.

add-path그리고.set-env2020년 10월 1일 보안상의 이유로 명령어가 더 이상 사용되지 않습니다. https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

%PATH%에 추가하는 권장 방법은 다음과 같이 환경 파일을 사용하는 것입니다.

사용하는 경우Powershell기본 셸:

echo "C:\directory\to\add\to\path" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

또는 대신에bash:

echo "C:\directory\to\add\to\path" >> $GITHUB_PATH

Powershell에서 이를 달성하는 더 짧은 방법도 있습니다. Powershell은 윈도우즈 호스팅된 러너가 사용하는 기본 셸입니다.

Add-Content $env:GITHUB_PATH "C:\directory\to\add\to\path"

내용 추가 참조

다른 답변은 (@Kel Solar의 답변에 설명된 대로 추가 경로를 사용하지 않는 GitHub Actions로 인해) 약간 구식입니다. 여기 @Mizux 답변을 기반으로 한 전체 예는 다음과 같습니다.

    - name: Install swig
      if: "startsWith(runner.os, 'windows')"
      run: |
        (New-Object System.Net.WebClient).DownloadFile("http://prdownloads.sourceforge.net/swig/swigwin-4.0.1.zip","swigwin-4.0.1.zip");
        Expand-Archive .\swigwin-4.0.1.zip .;
        echo "$((Get-Item .).FullName)/swigwin-4.0.1" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

@Mizus answer의 또 다른 차이점은 swig 디렉토리에 대한 절대 경로가 사용된다는 것입니다. 이는 작업 디렉토리가 변경되더라도 계속 작동하도록 하기 위한 것입니다.

편집: GitHub에서 이 기능을 사용하지 않습니다. 다른 답변을 참조하십시오.
ref: https://github.dll/changelog/2020-10-01-github-vlan-descripting-set-env-and-add-path-messages/

작업 구문을 사용해야 합니다.echo "::add-path::..."당신의 경우:

...
    - name: Install swig
      run: |
        (New-Object System.Net.WebClient).DownloadFile("http://prdownloads.sourceforge.net/swig/swigwin-4.0.1.zip","swigwin-4.0.1.zip");
        Expand-Archive .\swigwin-4.0.1.zip .;
        echo "::add-path::./swigwin-4.0.1"
    - name: Check swig
      run: swig -version

src: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path

언급URL : https://stackoverflow.com/questions/60169752/how-to-update-the-path-in-a-github-action-workflow-file-for-a-windows-latest-hos

반응형