Skip to content

fix: Expand tilde for chdir (issue #389) #390

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

richeney
Copy link

@richeney richeney commented Jul 9, 2025

Pull Request

Issue

Fixes #389

Description

Expands ~ with $env:HOME if found in moduleFolderPath

License

By submitting this pull request, I confirm that my contribution is made under the terms of the projects associated license.

Copy link
Member

@jaredfholgate jaredfholgate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just need to make it work across all operating systems.

@@ -23,6 +23,11 @@ function Invoke-Terraform {
[switch] $silent
)

# Avoid bootstrap Terraform chdir errors if ~ in moduleFolderPath
if ($env:HOME -and $env:HOME -ne "" -and $moduleFolderPath -match '^(~)') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this work for Windows too?

E.g.

$homeDirectoryPath = $env:HOME
if($IsWindows) {
  $homeDirectoryPath = $env:HOMEPATH
}
...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you can just use $HOME for a cross platform solution in PowerShell Core.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better, just use Resolve-Path $moduleFolderPath.

Copy link
Author

@richeney richeney Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So change to (Resolve-Path ~/accelerator/output).Path?

This gives a consistent result (that should work for chdir) for

  • absolute path
  • relative path
  • path including tilde

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Author Feedback 👂 Needs the author to provide feedback label Jul 9, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs: Author Feedback 👂 Needs the author to provide feedback label Jul 9, 2025
Copy link
Author

@richeney richeney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested a re-bootstrap and then rerun CI & CD workflows successfully, again in pwsh on Ubuntu on Win 11 ARM WSL.

@richeney richeney changed the title Expand tilde for chdir fix: Expand tilde for chdir (issue #389) Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: chdir error if tilde (~) is in module path
2 participants