Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%TEMP% is broken on Windows #712

Closed
mvdan opened this issue Apr 13, 2020 · 16 comments
Closed

%TEMP% is broken on Windows #712

mvdan opened this issue Apr 13, 2020 · 16 comments
Assignees
Labels
Area: Image administration investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: Windows

Comments

@mvdan
Copy link

mvdan commented Apr 13, 2020

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.

@TingluoHuang
Copy link
Member

@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
Copy link
Author

mvdan commented Apr 13, 2020

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

@TingluoHuang
Copy link
Member

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

@TingluoHuang TingluoHuang transferred this issue from actions/runner Apr 13, 2020
@al-cheb al-cheb added Area: Image administration investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: Windows labels Apr 13, 2020
@mvdan
Copy link
Author

mvdan commented Apr 13, 2020

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

@al-cheb
Copy link
Contributor

al-cheb commented Apr 13, 2020

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
Copy link
Author

mvdan commented Apr 13, 2020

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
Copy link
Author

mvdan commented Apr 13, 2020

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.

@al-cheb
Copy link
Contributor

al-cheb commented Apr 13, 2020

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
Copy link
Author

mvdan commented Apr 13, 2020

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
Copy link
Author

mvdan commented Apr 13, 2020

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.

@al-cheb
Copy link
Contributor

al-cheb commented Apr 13, 2020

@al-cheb
Copy link
Contributor

al-cheb commented Apr 13, 2020

@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"

@al-cheb al-cheb self-assigned this Apr 14, 2020
@al-cheb
Copy link
Contributor

al-cheb commented Apr 20, 2020

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

@al-cheb al-cheb closed this as completed Apr 20, 2020
fhs added a commit to 9fans/acme-lsp that referenced this issue Jun 9, 2020
@campersau
Copy link

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

@dennisvang
Copy link

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

dennisvang added a commit to dennisvang/tufup that referenced this issue Nov 8, 2023
* test Repository.from_config with both relative and absolute paths

* explicitly test path args for Repository.__init__

* extend test for Repository.save_config to ensure relative paths

* save relative paths to config file, if possible

Although using paths that are *not* relative to the current working directory (cwd) is discouraged,
this *should* still be possible. So, if the path is not relative to cwd, we just save the absolute path.

* try to fix github actions for windows/mac

see this issue: actions/runner-images#712

* handle 8.3 filenames in Repository.save_config()

* add _patched_resolve() as workaround for cpython #82852

for python <3.10 on windows

* ruff formatting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Image administration investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: Windows
Projects
None yet
Development

No branches or pull requests

5 participants