actions/runner-images

%TEMP% is broken on Windows

mvdan opened this issue ยท 16 comments

mvdan commented

This was originally posted on the community forum last year. Since the forum seems to be winding down in activity, and I never got a response, I'm reposting it here.

--

I was running into some test failures when migrating my Windows tests from Travis to GitHub Actions. I ended up narrowing down the breakage to this simple env var:

$ echo %TEMP%
C:\Users\RUNNER~1\AppData\Local\Temp

This was causing me issues because the actual home dir is C:\Users\runneradmin, which I checked via echo %USERPROFILE%. Note that the case sensitivity here doesn't matter for my purposes; it's the short path (the ~1) that's breaking my code.

Is there a reason that the environment is inconsistent like this? I think both %TMP% and %TEMP% should be C:\Users\runneradmin\AppData\Local\Temp. In other words, they should have %USERPROFILE% as a prefix.

@mvdan thanks for reporting this, you might want to report this to https://github.com/actions/virtual-environments since they in charge of setting up the machine and user that is going to execute the runner. :)

mvdan commented

Ah, my bad. Is there a way to move this issue without closing + opening another one?

@mvdan I am trying to get permission so I can just transfer the issue for you. :)

mvdan commented

Thanks! I also forgot to link to the original post on the forum - done.

Hello, @mvdan
It's by design - https://devblogs.microsoft.com/oldnewthing/20041224-00/?p=36893. I don't see any issue with it:

pwsh - Copy

mvdan commented

I see. I'm surprised because other CIs, like Travis and AppVeyor, didn't do this. Hence many repos, like two of mine, suddenly break when moving to Actions.

I also don't quite get if this is truly required for Actions. It doesn't seem like the expanded path contains any spaces :)

mvdan commented

To clarify, the directory works when opened. What breaks is when programs assume that %TEMP% is a canonical location. That is, echo $dir; cd $dir; pwd should print the same path twice, but it doesn't.

You could argue you should fix those programs, but given that it seems like the shortening is unnecessary (no spaces), I'm not sure what's the point.

Disable 8dot3name can break some customers:
Install-VS2019.ps1 - https://github.com/actions/virtual-environments/blob/e01c3fda2643e137606989cfe0fb2f635997d35a/images/win/scripts/Installers/Windows2019/Install-VS2019.ps1 (Write-Host "Enable short name support on Windows needed for Xamarin Android AOT, defaults appear to have been changed in Azure VMs")

mvdan commented

Oh :( fair enough, thanks for the quick replies. I completely understand your position, though I'm a bit frustrated that we're all dealing with backwards compatibility issues from many decades ago.

The issue can be closed as far as I'm concerned, as I don't see another possible suggestion or improvement.

mvdan commented

Just one last question - was this issue raised with Xamarin anywhere? I assume this is a bug they should fix, even if it might take years (or forever) for Actions to be able to remove the workaround.

@mvdan, As a workaround you can redefine variables TMP and TEMP:
Simple app:

package main

import (
    "fmt"
    "os"
)

func main() {
    fmt.Println(os.TempDir())
}
steps:
    - name: Run
      run: |
        set TMP=%USERPROFILE%\AppData\Local\Temp
        set TEMP=%USERPROFILE%\AppData\Local\Temp
        go run temp.go
      shell: cmd

test - Copy

The second variant - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables:

 - name: SetVar
   run: |
         echo "::set-env name=TMP::$env:USERPROFILE\AppData\Local\Temp"
         echo "::set-env name=TEMP::$env:USERPROFILE\AppData\Local\Temp"

@mvdan, Feel free to open the thread if you have any concerns.

After https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/ the new syntax for setting TEMP environment variable via powershell is:

- run: echo "TEMP=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV

Having a similar issue using Python with pathlib.Path and tempfile.TemporaryDirectory.

Encountered the following differences in unittests on GitHub Actions:

  • MacOS: /private/var/folders/... vs /var/folders/...
  • Windows: C:/Users/runneradmin/... vs C:/Users/RUNNER~1/...

Managed to fix this using pathlib.Path.resolve().