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

fix extractTar on Windows #248

Closed
wants to merge 4 commits into from
Closed

Conversation

ericsciple
Copy link
Contributor

@ericsciple ericsciple commented Dec 9, 2019

Fixes #194

// `--force-local` due to the `:` in Windows paths. This presents an incompatibility because
// BSD tar does not support the flag `--force-local` (invalid flag, fails the process).
tarPath = path.join(process.env['windir'] as string, 'System32', 'tar.exe')
fs.statSync(tarPath)
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of fs.StatSync(tarPath)? To throw if tar doesn't exist?

Copy link
Contributor

Choose a reason for hiding this comment

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

should probably use existsSync instead of this mechanism, if that's the case...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, i'll imrpove the error message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually tool runner provides a good error message so i'll just remove this line

@joshmgross
Copy link
Member

Did you verify that BSD tar on Windows doesn't have issues with \ and :?
I plan on switching the cache action to use BSD tar as well, thanks for this!

// Windows-style paths. Whereas GNU tar requires forward slashes and also requires the flag
// `--force-local` due to the `:` in Windows paths. This presents an incompatibility because
// BSD tar does not support the flag `--force-local` (invalid flag, fails the process).
tarPath = path.join(process.env['windir'] as string, 'System32', 'tar.exe')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tar seems to have been added as a part of the initiative to bring more Unix tools to windows in Windows 10. It looks liked our only hosted version of windows is now 2019, and it exists on that machine for hosted builds

However, for self hosted runners do we know if this exists on all the platforms that can run .net core 3.0? Those go back all the way to Windows Server 2012. https://github.com/dotnet/core/blob/master/release-notes/3.0/3.0-supported-os.md

For 7zip, we ship a copy of the binary and and use it if needed, we may need to look into a similar solution here.

Copy link
Collaborator

@thboop thboop Dec 9, 2019

Choose a reason for hiding this comment

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

Should we attempt to detect if the path doesn't exist so we can log a better message in this case if not all windows versions will have it installed. We should let a user know explicitly that we are using the tar version build into windows, your version of windows does not have it please upgrade " or provide a user workaround of some sort and bake that into the error message.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like maybe using existsSync and handling the false case would be the best way to do this. I wouldn't attempt to ship a binary in this case... maybe just fail and explain why.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 regarding the error message, at a glance it looked good to me but looking again we can make it a little bit more clear by try/catch/throw a better error.

one problem with the 7z approach is this function is literally designed as a wrapper over tar (see the flags parameter`)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed on using 7zip isn't the correct solution here. I don't really like shipping an exe of tar with the package like we do with 7zip either.

I'm happy with better error message (this may also affect users using container actions because iirc we support windows containers if the host system is linux)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually tool runner gives a good error already so i'll remove the statSync line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looking into 7z. note we dont package the full 7z (over 1mb) just the decoder exe (40kb)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i talked w/ josh and basically the cache action needs the support

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so will need broad os support.

i still think the current proposal is incrementally better

Copy link
Member

Choose a reason for hiding this comment

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

Re: Hosted Runners vs Self-Hosted Runners
The current behavior is that we use GNU specific tar option on windows (specifically --force-local) since the GNU tar is prepended to the PATH.
This works for hosted runners, but self-hosted runners most likely do not have GNU prepended, so they will either fail with tar not being found or BSD tar not recognizing --force-local), see actions/cache#91

With this solution, at least self-hosted runners that have tar are supported.

Also worth noting the cache action does not consume this package, it just has the same problems with tar.

Copy link
Collaborator

@thboop thboop left a comment

Choose a reason for hiding this comment

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

Some small edge cases we may want to consider,

However this is a great change and a net positive 🎖 LGTM

// `--force-local` due to the `:` in Windows paths. This presents an incompatibility because
// BSD tar does not support the flag `--force-local` (invalid flag, fails the process).
tarPath = path.join(process.env['windir'] as string, 'System32', 'tar.exe')
fs.statSync(tarPath)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this missing .isFile()

@ericsciple
Copy link
Contributor Author

@thboop @hross @joshmgross thoughts?

ok so 7zdec doesnt work for .tar.gz and .tar.xz

other solutions on Windows that come to mind are:

  1. check tar --version and grep the output to determine whether its bsdtar gnutar. I don't like this solution because it puts the burden on the end user (not the actual author) to verify tar is in the PATH

  2. create a totally separate npm package like windowsTar if someone wants tar support on windows.

@ericsciple
Copy link
Contributor Author

ericsciple commented Dec 9, 2019

honestly at this point i think i'm going to close this PR and open an ADR.

I dont feel good anymore about the half solution i proposed with this PR.

I would rather come up with a proposal that allows us to fix it once and for all, and never revisit the problem again.

@ericsciple ericsciple closed this Dec 9, 2019
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.

Extract tar.gz on windows-latest failed.
5 participants