-
Notifications
You must be signed in to change notification settings - Fork 224
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 for windows #1812
Closed
Closed
Fix for windows #1812
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b12a4fe
fix: Fix for Windows environment
kono e69d8b3
fix: Remove println for debug
kono 86461b8
fix: Fix document
kono 048948c
fix: Delete duplicate lines
kono 37817be
fix: Add "final" to variable definitions
kono 922b533
fix: More precise confirmation of shell designations
kono d1e7447
fix: Check shell options to be converted more closely
kono File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,28 +128,41 @@ private void runCode(final Config state) | |
} | ||
} | ||
|
||
private List<String> getShell(final Config params, final Boolean winOS){ | ||
// Until digdag ver. 0.9, it was necessary to write ["powershell.exe","-"] to specify shell, | ||
// but since ver. 0.10, jobs are not executed unless ["powershell.exe"] is written. | ||
// To resolve this incompatibility, change the shell specification ["powershell.exe","-"] | ||
// to ["powershell.exe"]. | ||
List<String> temp_shell; | ||
if (params.has("shell")) { | ||
temp_shell = params.getListOrEmpty("shell", String.class); | ||
if (temp_shell.get(0).toLowerCase().contains("powershell") && temp_shell.size() == 2){ | ||
if (temp_shell.get(1).contains("-")){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. It will match like |
||
temp_shell.remove(1); | ||
logger.info("removed \"-\" from shell specification --- from [\"powershell.exe\",\"-\"] to [\"powershell.exe\"] ."); | ||
} | ||
} | ||
} | ||
else { | ||
temp_shell = ImmutableList.of(winOS ? "PowerShell.exe" : "/bin/sh"); | ||
} | ||
return temp_shell; | ||
} | ||
|
||
private CommandStatus runCommand(final Config params, final CommandContext commandContext) | ||
throws IOException, InterruptedException | ||
{ | ||
final Path tempDir = workspace.createTempDir(String.format("digdag-sh-%d-", request.getTaskId())); | ||
final Path workingDirectory = workspace.getPath(); // absolute | ||
final Path runnerPath = tempDir.resolve("runner.sh"); // absolute | ||
final Boolean winOS = isWindowsPlatform(); | ||
final Path runnerPath = tempDir.resolve(winOS ? "runner.ps1" : "runner.sh"); // absolute | ||
|
||
final List<String> shell; | ||
if (params.has("shell")) { | ||
shell = params.getListOrEmpty("shell", String.class); | ||
} | ||
else { | ||
shell = ImmutableList.of("/bin/sh"); | ||
} | ||
final List<String> shell = getShell(params, winOS); | ||
|
||
final ImmutableList.Builder<String> cmdline = ImmutableList.builder(); | ||
if (params.has("shell")) { | ||
cmdline.addAll(shell); | ||
} | ||
else { | ||
cmdline.addAll(shell); | ||
} | ||
|
||
cmdline.addAll(shell); | ||
|
||
cmdline.add(workingDirectory.relativize(runnerPath).toString()); // relative | ||
|
||
final String shScript = UserSecretTemplate.of(params.get("_command", String.class)) | ||
|
@@ -223,5 +236,14 @@ private CommandRequest buildCommandRequest(final CommandContext commandContext, | |
.ioDirectory(ioDirectory) | ||
.build(); | ||
} | ||
|
||
private boolean isWindowsPlatform() | ||
{ | ||
final String os = System.getProperty("os.name").toLowerCase(); | ||
if ( os.startsWith("windows")) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contains("powershell")
will match to strings like 'powershell-batch.bat`. Is it intentional ?