%TEMP% is broken on Windows

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.

6 Likes

TEMP should work, but you might try RUNNER_TEMP, who’s value is d:\a_temp

Note that I’m not using %TEMP% directly. I’m using Go’s https://golang.org/pkg/os/#TempDir, which on Windows uses that variable via a Windows syscall. So I get no say in what variable gets used.

I could of course override %TEMP% in my workflow file, but that feels like working around a bug present on GitHub Actions.

FYI all, I’ve also raised this on the issue tracker: https://github.com/actions/runner/issues/424