Skip to content

Improve Windows version detection and HOME variable export#883

Merged
eregon merged 3 commits intoruby:masterfrom
eazybi:windows-server-standard-support
Mar 6, 2026
Merged

Improve Windows version detection and HOME variable export#883
eregon merged 3 commits intoruby:masterfrom
eazybi:windows-server-standard-support

Conversation

@jbaiza
Copy link
Contributor

@jbaiza jbaiza commented Mar 6, 2026

This PR fixes the issues mentioned in #882 with installing Ruby on blacksmith.sh runners.

jbaiza added 2 commits March 2, 2026 13:43
blacksmith.sh runners use "Windows Server 2025 Standard Evaluation".
index.js Outdated
core.exportVariable('TMPDIR', ENV['RUNNER_TEMP'])
// bash - sets home to match native windows, normally C:\Users\<user name>
core.exportVariable('HOME', ENV['HOMEDRIVE'] + ENV['HOMEPATH'])
// Use os.homedir() which calls the Windows API (SHGetFolderPath) directly.
Copy link
Member

Choose a reason for hiding this comment

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

This seems to not quite match what the docs say:

On Windows, it uses the USERPROFILE environment variable if defined. Otherwise it uses the path to the profile directory of the current user.

Copy link
Member

Choose a reason for hiding this comment

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

So are the docs wrong or is this comment inaccurate?
Probably the docs are right and we we just want to use a reliable approach vs depending on env vars directly.

Copy link
Collaborator

@ntkme ntkme Mar 6, 2026

Choose a reason for hiding this comment

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

From what I read online, USERPROFILE is the same as HOMEDRIVE/HOMEPATH for majority of the cases, but it’s not guaranteed. If we want to be safe and not potentially breaking anyone, I think we should do a fallback logic, that first try HOMEDRIVE/HOMEPATH and then fallback to USERPFOFILE.

Copy link
Member

Choose a reason for hiding this comment

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

We already use os.homedir() for createGemRC() and it seems to work fine so I think using os.homedir() is good enough and correct, just the comment needs to not be contradicting the docs 😅

Choose a reason for hiding this comment

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

The docs are right, and my library research led me in the wrong direction.
The full comment would be:

    // Env-based approaches (USERPROFILE, HOMEDRIVE+HOMEPATH) are unreliable on some
    // runners (e.g. Blacksmith) where these vars are unset, causing NaN, which
    // JSON.stringify serializes to "null".
    // os.homedir() checks USERPROFILE first, then falls back to the
    // GetUserProfileDirectoryW Windows API when USERPROFILE is unset.

However, the question is whether so long is needed here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool, in that case it’s actually better to have a consistent usage across different places.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I'm also fine to just remove the comment entirely because we then just use the method that node provides. Could you remove it then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the comment to the previous one without the path details.

Copy link
Member

@eregon eregon left a comment

Choose a reason for hiding this comment

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

The changes look good.

Of course since this cannot be tested in this action CI there might be other issues and it's not really an officially supported platform from the POV of setup-ruby maintainers.
But, it should still work because on Windows we use RubyInstaller2 builds which should work on most Windows, and there are hopefully not too many relevant differences between blacksmith.sh runners and GH-hosted Windows runners.

@jbaiza jbaiza force-pushed the windows-server-standard-support branch from a1da11a to 97d485f Compare March 6, 2026 10:50
@jbaiza jbaiza force-pushed the windows-server-standard-support branch from 97d485f to 23fc5fa Compare March 6, 2026 11:11
@eregon eregon merged commit 6ca151f into ruby:master Mar 6, 2026
215 checks passed
@eregon eregon linked an issue Mar 6, 2026 that may be closed by this pull request
2 tasks
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.

Issue with installing Ruby on blacksmith.sh Windows runners

4 participants