Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update the PATH in a github action workflow file for a windows-latest hosted runner

I'm currently trying to add GitHub actions workflow to a repo...

To do a C++/CMake/swig/python development (i.e. native python library dev), I need to download and install swigwin and have it available in the PATH...

Unfortunately it seems the $env:Path... command is not take into account during the next subsequent steps

Example

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...

Observed

> 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.
like image 984
Mizux Avatar asked Feb 11 '20 13:02

Mizux


People also ask

How do I add a path to an action in GitHub?

For linux, just run: echo "/usr/path/whatever" >> $GITHUB_PATH in a step, and the path will be updated for all subsequent steps.

How do I edit a workflow action in GitHub?

In your repository, browse to the workflow file you want to edit. In the upper right corner of the file view, to open the workflow editor, click . To the right of the editor, use the GitHub Marketplace sidebar to browse actions.

What directory do GitHub Actions run in?

GitHub Actions uses YAML syntax to define the workflow. Each workflow is stored as a separate YAML file in your code repository, in a directory named .github/workflows .

How do I set an environment variable in GitHub Actions?

To set a custom environment variable, you must define it in the workflow file. The scope of a custom environment variable is limited to the element in which it is defined. You can define environment variables that are scoped for: The entire workflow, by using env at the top level of the workflow file.


1 Answers

The add-path and set-env commands have been deprecated the 1st October 2020 for security reasons: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

The recommended way to add to %PATH% is using environment files as follows:

Assuming you use Powershell, the default shell:

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

or alternatively for bash:

echo "C:\directory\to\add\to\path" >> $GITHUB_PATH
like image 135
Kel Solaar Avatar answered Nov 15 '22 08:11

Kel Solaar