Skip to content

Commit 3a77c8b

Browse files
fix: Add support for Powershell and CMD on all supported runners (#18)
Closes #17. This PR brings the following changes: - Now it is possible to use Jython 2.0 and 2.1 on `ubuntu` and `macos` runners! - Added support for Powershell on all runners (previously only on `windows` runners) - Added support for Windows Command Prompt (`cmd`) on windows runners. Notice that because of how the `cmd` handles single quotes it only works if no single quotes are used to enclose parameters: `jython.bat -c "print 'Hello world'"` will work, while `jython.bat -c 'print "Hello world"'` will not. - Renamed `jython.bat` to `jython.ps1`. To use Jython on the powershell now you have to specifically call `jython.ps1` - Add tests for Bourne shell (`sh`), Windows Command Prompt (`cmd`) on Windows runners and Powershell (`pwsh` or `powershell`)
1 parent 205acb2 commit 3a77c8b

File tree

4 files changed

+118
-33
lines changed

4 files changed

+118
-33
lines changed

.github/workflows/test-action.yml

Lines changed: 93 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,13 @@ jobs:
3434
- "2.1"
3535
- "2.0"
3636

37-
# [GH-1] Jython 2.0 and 2.1 do not work on macOS and Ubuntu
38-
exclude:
39-
- os: ubuntu-latest
40-
jython_version: "2.0"
41-
- os: macos-latest
42-
jython_version: "2.0"
43-
- os: ubuntu-latest
44-
jython_version: "2.1"
45-
- os: macos-latest
46-
jython_version: "2.1"
47-
4837
runs-on: ${{ matrix.os }}
4938
defaults:
5039
run:
5140
shell: bash
5241
steps:
5342
- name: Checkout
54-
uses: actions/checkout@v3
43+
uses: actions/checkout@v4
5544
with:
5645
fetch-depth: 0
5746

@@ -63,33 +52,49 @@ jobs:
6352
- name: Environment check
6453
shell: bash
6554
run: |
55+
VERTICAL_SEPARATOR="\x1b[0;35m|\x1b[0m";
56+
HORIZONTAL_SEPARATOR="\x1b[0;36m----------------------------------------------------------------------------------------------------\x1b[0m";
57+
58+
6659
printf "\033[0;33mEnvironment variables:\033[0m\n";
67-
env | sed 's/^/ | /'
60+
env | sed "s/^/ $VERTICAL_SEPARATOR /"
6861
69-
printf -- "\033[0;96m--------------------------------------------------\033[0m\n\n";
62+
63+
printf -- "$HORIZONTAL_SEPARATOR\n\n"
7064
printf "\033[0;33mGithub PATH (GITHUB_PATH='%s'):\033[0m\n" "$GITHUB_PATH";
71-
cat "$GITHUB_PATH" | sed 's/^/ | /'
65+
cat "$GITHUB_PATH" | sed "s/^/ $VERTICAL_SEPARATOR /"
66+
7267
73-
printf -- "\033[0;96m--------------------------------------------------\033[0m\n\n";
68+
printf -- "$HORIZONTAL_SEPARATOR\n\n"
7469
printf "\033[0;33mInstallation folder content:\033[0m\n";
75-
ls -la ~/jython/ | sed 's/^/ | /'
70+
ls -la ~/jython/ | sed "s/^/ $VERTICAL_SEPARATOR /"
7671
77-
printf -- "\033[0;96m--------------------------------------------------\033[0m\n\n";
72+
73+
printf -- "$HORIZONTAL_SEPARATOR\n\n"
7874
printf "\033[0;33mBinary files:\033[0m\n";
79-
ls -la ~/.local/bin/ | sed 's/^/ | /'
75+
ls -la ~/.local/bin/ | sed "s/^/ $VERTICAL_SEPARATOR /"
76+
8077
81-
printf -- "\033[0;96m--------------------------------------------------\033[0m\n\n";
78+
printf -- "$HORIZONTAL_SEPARATOR\n\n"
8279
printf "\033[0;33mBash script ('jython'):\033[0m\n";
8380
if [ -f ~/.local/bin/jython ]; then
84-
cat ~/.local/bin/jython | sed 's/^/ | /'
81+
cat ~/.local/bin/jython | sed "s/^/ $VERTICAL_SEPARATOR /"
8582
fi
8683
87-
printf -- "\033[0;96m--------------------------------------------------\033[0m\n\n";
84+
85+
printf -- "$HORIZONTAL_SEPARATOR\n\n"
8886
printf "\033[0;33mBatch script ('jython.bat'):\033[0m\n";
8987
if [ -f ~/.local/bin/jython.bat ]; then
90-
cat ~/.local/bin/jython.bat | sed 's/^/ | /'
88+
cat ~/.local/bin/jython.bat | sed "s/^/ $VERTICAL_SEPARATOR /"
9189
fi
92-
90+
91+
92+
printf -- "$HORIZONTAL_SEPARATOR\n\n"
93+
printf "\033[0;33mPowershell script ('jython.ps1'):\033[0m\n";
94+
if [ -f ~/.local/bin/jython.ps1 ]; then
95+
cat ~/.local/bin/jython.ps1 | sed "s/^/ $VERTICAL_SEPARATOR /"
96+
fi
97+
9398
- name: Run Jython (Bash)
9499
shell: bash
95100
run: |
@@ -99,13 +104,75 @@ jobs:
99104
echo "$output";
100105
echo "$output" | grep -q "Jython Works!";
101106
107+
- name: Run Jython (Bourne Shell)
108+
shell: sh
109+
run: |
110+
set +e;
111+
112+
output="$(jython -c 'import sys, os; print(os.name, sys.version); print "\n\nJython Works!\n\n"')";
113+
echo "$output";
114+
echo "$output" | grep -q "Jython Works!";
115+
116+
- name: Run Jython (Batch)
117+
if: runner.os == 'Windows'
118+
shell: cmd
119+
run: |
120+
@rem ----------------------------------------------------------------------------------------------------
121+
@rem WARNING: The commands may fail if not quoted with double quotes (") instead of single quotes (')
122+
@rem
123+
@rem The single quotes are not recognized by the Windows Command Prompt (cmd) and are treated
124+
@rem as part of the command itself.
125+
@rem
126+
@rem This means that if there are spaces in the command, each word will be treated as a separate
127+
@rem parameter and will fail.
128+
@rem ----------------------------------------------------------------------------------------------------
129+
SET "search_string=Jython Works!"
130+
131+
ECHO ----------------------------------------------------------------------------------------------------
132+
ECHO The following command is expected to pass because of the double quotes:
133+
134+
CALL jython -c "import sys, os; print(os.name, sys.version); print '\n\nJython Works!\n\n'" > double_quotes.temp.out 2>&1
135+
TYPE double_quotes.temp.out
136+
137+
findstr /C:"%search_string%" double_quotes.temp.out > NUL
138+
if %errorlevel% NEQ 0 (
139+
ECHO The command failed.
140+
EXIT /B 9
141+
)
142+
143+
144+
ECHO ----------------------------------------------------------------------------------------------------
145+
ECHO The following command is expected to fail because of the single quotes:
146+
147+
CALL jython -c 'import sys, os; print(os.name, sys.version); print "\n\nJython Works!\n\n"' > single_quotes.temp.out 2>&1
148+
TYPE single_quotes.temp.out
149+
150+
@rem Exit with error code 10 if the command does NOT fail as expected
151+
findstr /C:"%search_string%" single_quotes.temp.out > NUL
152+
if %errorlevel% EQU 0 (
153+
ECHO The command should have failed but it did not.
154+
EXIT /B 10
155+
)
156+
157+
ECHO ----------------------------------------------------------------------------------------------------
158+
ECHO Tests passed successfully!
159+
EXIT /B 0
160+
102161
- name: Run Jython (Powershell)
103162
shell: pwsh
104-
if: ${{ runner.os == 'Windows' }}
105163
run: |
164+
echo ----------------------------------------------------------------------------------------------------
165+
echo "Command: 'jython'"
166+
jython -c "import sys, os; print(os.name, sys.version); print '\n\nJython Works!\n\n'"
167+
168+
echo ----------------------------------------------------------------------------------------------------
169+
echo "Command: 'jython.ps1'"
170+
jython.ps1 -c "import sys, os; print(os.name, sys.version); print '\n\nJython Works!\n\n'"
171+
172+
echo ----------------------------------------------------------------------------------------------------
106173
Describe JythonTest {
107174
It 'verifies Jython works' {
108-
$output = jython -c "import sys, os; print(os.name, sys.version); print '\n\nJython Works!\n\n'"
175+
$output = jython.ps1 -c "import sys, os; print(os.name, sys.version); print '\n\nJython Works!\n\n'"
109176
$output | Select-String -Quiet -Pattern "Jython Works!" | Should -Be true
110177
}
111178
}

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- Now it is possible to use Jython 2.0 and 2.1 on `ubuntu` and `macos` runners
12+
- Now it is possible to use Jython 2.0 and 2.1 on `ubuntu` and `macos` runners!
13+
- Added support for Powershell on all runners (previously only on `windows` runners)
14+
- Added support for Windows Command Prompt (`cmd`) on windows runners. Notice that because of how the `cmd` handles single quotes it only works if no single quotes are used to enclose parameters: `jython.bat -c "print 'Hello world'"` will work, while `jython.bat -c 'print "Hello world"'` will not.
15+
16+
**Tests**:
17+
- Add tests for Bourne shell (`sh`), Windows Command Prompt (`cmd`) on Windows runners and Powershell (`pwsh` or `powershell`)
18+
19+
### Changed
20+
21+
- Renamed `jython.bat` to `jython.ps1`. To use Jython on the powershell now you have to specifically call `jython.ps1`
1322

1423
## [v4] - 2024-05-14
1524

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ steps:
1717
with:
1818
jython-version: '2.5.2'
1919

20-
- run: jython -c 'import sys, os; print(os.name, sys.version)';
20+
- name: Run individual commands
21+
run: jython -c 'import sys, os; print(os.name, sys.version)';
22+
23+
- name: Run a specific script
24+
run: jython /path/to/script.py
2125
```
2226
2327
## Inputs

action.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,23 @@ runs:
166166
chmod +x ~/.local/bin/jython;
167167
168168
- name: Setup Jython alias (pwsh)
169-
if: runner.os == 'Windows'
170169
shell: pwsh
171170
run: |
172171
$installation_path = Convert-Path "${{ inputs.installation-path }}"
172+
$jython_path = Convert-Path "$installation_path\jython.jar"
173+
173174
if ("${{ steps.find_installer.outputs.file_type }}" -eq "class") {
174-
$jython_cmd = "java -cp ${installation_path}\jython.jar org.python.util.jython %*"
175+
$jython_cmd = "java -cp $jython_path org.python.util.jython %*"
176+
$jython_pws = "java -cp $jython_path org.python.util.jython @args"
175177
} else {
176-
$jython_cmd = "java -jar $installation_path\jython.jar %*"
178+
$jython_cmd = "java -jar $jython_path %*"
179+
$jython_pws = "java -jar $jython_path @args"
177180
}
178181
179-
mkdir -Force ~\.local\bin
180-
$jython_cmd | Out-File -FilePath ~\.local\bin\jython.bat
182+
Write-Output $jython_cmd | Out-File -FilePath ~\.local\bin\jython.bat -Append
183+
184+
Write-Output "#!/usr/bin/env pwsh" | Out-File -FilePath ~\.local\bin\jython.ps1
185+
Write-Output $jython_pws | Out-File -FilePath ~\.local\bin\jython.ps1 -Append
181186
182187
- name: Add to PATH (Linux and macOS)
183188
if: runner.os != 'Windows'

0 commit comments

Comments
 (0)