Cache: How to use env vars in path on windows

Created on 18 Nov 2019  路  4Comments  路  Source: actions/cache

Hey,

I'd need some help understanding what I'm doing wrong.

Expectation: path: ${{ env.LOCALAPPDATA }} points to C:\Users\runneradmin\AppData\Local.

    runs-on: windows-latest
    - name: Test print stuff
      run: |
        echo $env:LOCALAPPDATA
        ls $env:LOCALAPPDATA
 Test print stuff7s

Run echo $env:LOCALAPPDATA
C:\Users\runneradmin\AppData\Local


    Directory: C:\Users\runneradmin\AppData\Local

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        11/11/2019  2:16 PM                Google
d-----        11/17/2019 11:28 PM                Microsoft
d-----        11/17/2019  9:44 PM                Packages
d-----        11/17/2019 11:29 PM                Temp
    - name: Cache electron-builder dependencies
      uses: actions/cache@v1
      with:
        path: ${{ env.LOCALAPPDATA }}electron-builder
Post Cache electron-builder dependencies3s
##[warning]The process 'C:\Program Files\Git\usr\bin\tar.exe' failed with exit code 2
Post job cleanup.
"C:\Program Files\Git\usr\bin\tar.exe" -cz --force-local -f d:/a/_temp/0b413849-9e8e-4665-894e-02bf8c693b6e/cache.tgz -C d:/a/my-project/my-project/electron-builder .
/usr/bin/tar: d\:/a/my-project/my-project/electron-builder: Cannot open: No such file or directory
/usr/bin/tar: Error is not recoverable: exiting now
##[warning]The process 'C:\Program Files\Git\usr\bin\tar.exe' failed with exit code 2

Meanwhile, path: C:\Users\runneradmin\AppData\Local\electron-builder works as expected.

question

Most helpful comment

The env context is limited to environment variables set for jobs, steps, and workflows. See context docs

You have a few options:

  1. Set the value for the env context
   - name: Set env 
      run: echo "::set-env name=appdata::$($env:LOCALAPPDATA)"
    - name: Cache electron-builder dependencies
      uses: actions/cache@v1
      with:
        path: ${{ env.appdata }}\electron-builder
  1. Set the value as an output
    - name: Env output
      id: output-env
      run: echo "::set-output name=appdata::$env:LOCALAPPDATA"

    - name: Cache electron-builder dependencies
      uses: actions/cache@v1
      with:
        path: ${{ steps.output-env.outputs.appdata }}\electron-builder
  1. Use ~ to represent the user directory and append Appdata
    - name: Cache electron-builder dependencies
      uses: actions/cache@v1
      with:
        path: ~\AppData\Local\electron-builder

The action will recognize ~ and replace it with the user directory, see https://github.com/actions/cache/blob/master/src/utils/actionUtils.ts#L80

All 4 comments

The env context is limited to environment variables set for jobs, steps, and workflows. See context docs

You have a few options:

  1. Set the value for the env context
   - name: Set env 
      run: echo "::set-env name=appdata::$($env:LOCALAPPDATA)"
    - name: Cache electron-builder dependencies
      uses: actions/cache@v1
      with:
        path: ${{ env.appdata }}\electron-builder
  1. Set the value as an output
    - name: Env output
      id: output-env
      run: echo "::set-output name=appdata::$env:LOCALAPPDATA"

    - name: Cache electron-builder dependencies
      uses: actions/cache@v1
      with:
        path: ${{ steps.output-env.outputs.appdata }}\electron-builder
  1. Use ~ to represent the user directory and append Appdata
    - name: Cache electron-builder dependencies
      uses: actions/cache@v1
      with:
        path: ~\AppData\Local\electron-builder

The action will recognize ~ and replace it with the user directory, see https://github.com/actions/cache/blob/master/src/utils/actionUtils.ts#L80

Thanks! This resolves my issue.

To follow-up though, is there a reason for not having this variable available? It seemed like a commonly used system variable to me, maybe you could consider making it available in its original form. Cheers.

is there a reason for not having this variable available?

I'm not sure, right now the env context doesn't contain any environment variables from the runner itself, it's more of a "workflow" environment instead of the system environment.

Not sure if it warrants a feature request. If you agree that it's useful and you have the resources, perhaps add it to the backlog. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hugovk picture hugovk  路  6Comments

wrightak picture wrightak  路  4Comments

Fatme picture Fatme  路  3Comments

jcornaz picture jcornaz  路  4Comments

s-weigand picture s-weigand  路  5Comments