Fix windows executable name#41
Conversation
|
I am not a windows user nor do I need to run something on a windows machine, so I ask myself if this is really necessary on github actions to suffix it with exe? 🤔 |
|
So if you omit the |
|
Funnily enough windows does have metadata within the file to also say that it is an executable but choses not to use it in cases like this 🤷 |
|
This is an example of running |
|
If you check this build here in the "Confirm download" step, it doesn't actually run the command |
|
Thanks for this reasearch @jeremyvaartjes ! However, how can Here, npm install and npm test will also be executed on windows. |
|
Alright, I tested a bit here and loked what the When we map to this the const pklCacheDir = path.join(process.env['RUNNER_TEMP']!!, 'tmp_pkl')
await io.mkdirP(pklCacheDir)
if (os.platform() === 'win32') {
await io.cp(pklBinaryPath, path.join(pklCacheDir, 'pkl.exe'))
} else {
await io.cp(pklBinaryPath, path.join(pklCacheDir, 'pkl'))
}
const cachedPath = await tc.cacheDir(pklCacheDir, 'pkl', pklVersion)With that, I made it to work running just pkl.movMaybe this is a better idea than using What do you think? |
|
Thanks for the extensive research both, much appreciated!
This makes sense to me, happy to go with the implementation as researched by @StefMa.
This is moderately concerning. I know basically zero about Windows and Powershell, is there a better way to detect a failure of the executable @jeremyvaartjes ? |
|
Powershell would output an error if the file didn't exist or was named differently, its only because the name matches that it decides "I want to open this as a file". |
|
Apparently the start process command allows running without the file extension because it takes in an explicit file path, but then if you start using that method you are again creating a bunch of windows only code to get very little value. It's also a problem for all downstream users since they would need to use the same workarounds. |
|
I think @StefMa's suggested change and my change have probably the same level of windows specific code. I think @StefMa's version might be better for the long run if the pkl team decide to distribute more than a single executable file because his version starts working with directories rather than a singular file. |
|
I've looked at added a test for the output of invoking
In the CI runs of #43, the downloads including Windows are executing properly, so now I'm confused about whether or not the issue in this PR is currently a problem? |
|
Oh, now that I've said that - that must be because I've tried using https://github.com/marketplace/actions/command-output to execute the command (and capture output) and it looks like it's defaulting to bash instead of Powershell |
|
@jasongwartz the action you're using to test it runs on bash. The normal windows runner uses powershell as default (according to @jeremyvaartjes). So still, the error exist.
I don't think this is the only valid case for this 😅 |
eff8d47 to
1b1cf9d
Compare
|
I've made an update to this pr to extract some of the platform logic into it's own file, that will hopefully mean that the main file is kept a bit cleaner. |
bc71622 to
d424626
Compare
d424626 to
900e8d0
Compare
|
@jasongwartz Is there anything you want me to adjust or are we good to merge this PR? |
jasongwartz
left a comment
There was a problem hiding this comment.
I'd like to take another look together at simplifying the implementation. Is this a bugfix that's blocking you on something?
src/platform.ts
Outdated
| enum Platform { | ||
| Linux, | ||
| MacOS, | ||
| Windows | ||
| } | ||
|
|
||
| enum Architecture { | ||
| arm64, | ||
| x64 | ||
| } |
There was a problem hiding this comment.
I generally prefer as const objects or arrays instead of enums - enums are one of the few TypeScript features which are transpiled into entirely different runtime code (whereas most TypeScript type-related syntax is simply erased).
src/platform.ts
Outdated
| plat, | ||
| arch, |
There was a problem hiding this comment.
Doesn't look like these two are used by the caller
src/platform.ts
Outdated
| case 'amd64': | ||
| return 'pkl-linux-amd64' | ||
| default: | ||
| throw new Error('Unsupported architecture') |
There was a problem hiding this comment.
I don't think this can happen here, right? Since arch is of type Architecture, and determineArch() can only return one of the two supported values
src/platform.ts
Outdated
| case 'linux': | ||
| switch (arch) { | ||
| case 'aarch64': | ||
| return 'pkl-linux-aarch64' | ||
| case 'amd64': | ||
| return 'pkl-linux-amd64' | ||
| default: | ||
| throw new Error('Unsupported architecture') |
There was a problem hiding this comment.
| case 'linux': | |
| switch (arch) { | |
| case 'aarch64': | |
| return 'pkl-linux-aarch64' | |
| case 'amd64': | |
| return 'pkl-linux-amd64' | |
| default: | |
| throw new Error('Unsupported architecture') | |
| case 'linux': | |
| return `pkl-linux-${arch}` |
Just looking at the logic, would something like this cover the necessary behaviour?
|
Any movement here? |
jasongwartz
left a comment
There was a problem hiding this comment.
thanks for the improvement, and sorry for the delay!


The windows version of this setup script was copying the executable without the
.exeextension so I'm adding a function that works out what the file name should be for the given os.