Skip to content

Commit

Permalink
fix: Add support for Powershell and CMD on all supported runners (#18)
Browse files Browse the repository at this point in the history
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`)
  • Loading branch information
LukeSavefrogs authored May 15, 2024
1 parent 205acb2 commit 3a77c8b
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 33 deletions.
119 changes: 93 additions & 26 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,13 @@ jobs:
- "2.1"
- "2.0"

# [GH-1] Jython 2.0 and 2.1 do not work on macOS and Ubuntu
exclude:
- os: ubuntu-latest
jython_version: "2.0"
- os: macos-latest
jython_version: "2.0"
- os: ubuntu-latest
jython_version: "2.1"
- os: macos-latest
jython_version: "2.1"

runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -63,33 +52,49 @@ jobs:
- name: Environment check
shell: bash
run: |
VERTICAL_SEPARATOR="\x1b[0;35m|\x1b[0m";
HORIZONTAL_SEPARATOR="\x1b[0;36m----------------------------------------------------------------------------------------------------\x1b[0m";
printf "\033[0;33mEnvironment variables:\033[0m\n";
env | sed 's/^/ | /'
env | sed "s/^/ $VERTICAL_SEPARATOR /"
printf -- "\033[0;96m--------------------------------------------------\033[0m\n\n";
printf -- "$HORIZONTAL_SEPARATOR\n\n"
printf "\033[0;33mGithub PATH (GITHUB_PATH='%s'):\033[0m\n" "$GITHUB_PATH";
cat "$GITHUB_PATH" | sed 's/^/ | /'
cat "$GITHUB_PATH" | sed "s/^/ $VERTICAL_SEPARATOR /"
printf -- "\033[0;96m--------------------------------------------------\033[0m\n\n";
printf -- "$HORIZONTAL_SEPARATOR\n\n"
printf "\033[0;33mInstallation folder content:\033[0m\n";
ls -la ~/jython/ | sed 's/^/ | /'
ls -la ~/jython/ | sed "s/^/ $VERTICAL_SEPARATOR /"
printf -- "\033[0;96m--------------------------------------------------\033[0m\n\n";
printf -- "$HORIZONTAL_SEPARATOR\n\n"
printf "\033[0;33mBinary files:\033[0m\n";
ls -la ~/.local/bin/ | sed 's/^/ | /'
ls -la ~/.local/bin/ | sed "s/^/ $VERTICAL_SEPARATOR /"
printf -- "\033[0;96m--------------------------------------------------\033[0m\n\n";
printf -- "$HORIZONTAL_SEPARATOR\n\n"
printf "\033[0;33mBash script ('jython'):\033[0m\n";
if [ -f ~/.local/bin/jython ]; then
cat ~/.local/bin/jython | sed 's/^/ | /'
cat ~/.local/bin/jython | sed "s/^/ $VERTICAL_SEPARATOR /"
fi
printf -- "\033[0;96m--------------------------------------------------\033[0m\n\n";
printf -- "$HORIZONTAL_SEPARATOR\n\n"
printf "\033[0;33mBatch script ('jython.bat'):\033[0m\n";
if [ -f ~/.local/bin/jython.bat ]; then
cat ~/.local/bin/jython.bat | sed 's/^/ | /'
cat ~/.local/bin/jython.bat | sed "s/^/ $VERTICAL_SEPARATOR /"
fi
printf -- "$HORIZONTAL_SEPARATOR\n\n"
printf "\033[0;33mPowershell script ('jython.ps1'):\033[0m\n";
if [ -f ~/.local/bin/jython.ps1 ]; then
cat ~/.local/bin/jython.ps1 | sed "s/^/ $VERTICAL_SEPARATOR /"
fi
- name: Run Jython (Bash)
shell: bash
run: |
Expand All @@ -99,13 +104,75 @@ jobs:
echo "$output";
echo "$output" | grep -q "Jython Works!";
- name: Run Jython (Bourne Shell)
shell: sh
run: |
set +e;
output="$(jython -c 'import sys, os; print(os.name, sys.version); print "\n\nJython Works!\n\n"')";
echo "$output";
echo "$output" | grep -q "Jython Works!";
- name: Run Jython (Batch)
if: runner.os == 'Windows'
shell: cmd
run: |
@rem ----------------------------------------------------------------------------------------------------
@rem WARNING: The commands may fail if not quoted with double quotes (") instead of single quotes (')
@rem
@rem The single quotes are not recognized by the Windows Command Prompt (cmd) and are treated
@rem as part of the command itself.
@rem
@rem This means that if there are spaces in the command, each word will be treated as a separate
@rem parameter and will fail.
@rem ----------------------------------------------------------------------------------------------------
SET "search_string=Jython Works!"
ECHO ----------------------------------------------------------------------------------------------------
ECHO The following command is expected to pass because of the double quotes:
CALL jython -c "import sys, os; print(os.name, sys.version); print '\n\nJython Works!\n\n'" > double_quotes.temp.out 2>&1
TYPE double_quotes.temp.out
findstr /C:"%search_string%" double_quotes.temp.out > NUL
if %errorlevel% NEQ 0 (
ECHO The command failed.
EXIT /B 9
)
ECHO ----------------------------------------------------------------------------------------------------
ECHO The following command is expected to fail because of the single quotes:
CALL jython -c 'import sys, os; print(os.name, sys.version); print "\n\nJython Works!\n\n"' > single_quotes.temp.out 2>&1
TYPE single_quotes.temp.out
@rem Exit with error code 10 if the command does NOT fail as expected
findstr /C:"%search_string%" single_quotes.temp.out > NUL
if %errorlevel% EQU 0 (
ECHO The command should have failed but it did not.
EXIT /B 10
)
ECHO ----------------------------------------------------------------------------------------------------
ECHO Tests passed successfully!
EXIT /B 0
- name: Run Jython (Powershell)
shell: pwsh
if: ${{ runner.os == 'Windows' }}
run: |
echo ----------------------------------------------------------------------------------------------------
echo "Command: 'jython'"
jython -c "import sys, os; print(os.name, sys.version); print '\n\nJython Works!\n\n'"
echo ----------------------------------------------------------------------------------------------------
echo "Command: 'jython.ps1'"
jython.ps1 -c "import sys, os; print(os.name, sys.version); print '\n\nJython Works!\n\n'"
echo ----------------------------------------------------------------------------------------------------
Describe JythonTest {
It 'verifies Jython works' {
$output = jython -c "import sys, os; print(os.name, sys.version); print '\n\nJython Works!\n\n'"
$output = jython.ps1 -c "import sys, os; print(os.name, sys.version); print '\n\nJython Works!\n\n'"
$output | Select-String -Quiet -Pattern "Jython Works!" | Should -Be true
}
}
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Now it is possible to use Jython 2.0 and 2.1 on `ubuntu` and `macos` runners
- 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.

**Tests**:
- Add tests for Bourne shell (`sh`), Windows Command Prompt (`cmd`) on Windows runners and Powershell (`pwsh` or `powershell`)

### Changed

- Renamed `jython.bat` to `jython.ps1`. To use Jython on the powershell now you have to specifically call `jython.ps1`

## [v4] - 2024-05-14

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ steps:
with:
jython-version: '2.5.2'

- run: jython -c 'import sys, os; print(os.name, sys.version)';
- name: Run individual commands
run: jython -c 'import sys, os; print(os.name, sys.version)';

- name: Run a specific script
run: jython /path/to/script.py
```
## Inputs
Expand Down
15 changes: 10 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,23 @@ runs:
chmod +x ~/.local/bin/jython;
- name: Setup Jython alias (pwsh)
if: runner.os == 'Windows'
shell: pwsh
run: |
$installation_path = Convert-Path "${{ inputs.installation-path }}"
$jython_path = Convert-Path "$installation_path\jython.jar"
if ("${{ steps.find_installer.outputs.file_type }}" -eq "class") {
$jython_cmd = "java -cp ${installation_path}\jython.jar org.python.util.jython %*"
$jython_cmd = "java -cp $jython_path org.python.util.jython %*"
$jython_pws = "java -cp $jython_path org.python.util.jython @args"
} else {
$jython_cmd = "java -jar $installation_path\jython.jar %*"
$jython_cmd = "java -jar $jython_path %*"
$jython_pws = "java -jar $jython_path @args"
}
mkdir -Force ~\.local\bin
$jython_cmd | Out-File -FilePath ~\.local\bin\jython.bat
Write-Output $jython_cmd | Out-File -FilePath ~\.local\bin\jython.bat -Append
Write-Output "#!/usr/bin/env pwsh" | Out-File -FilePath ~\.local\bin\jython.ps1
Write-Output $jython_pws | Out-File -FilePath ~\.local\bin\jython.ps1 -Append
- name: Add to PATH (Linux and macOS)
if: runner.os != 'Windows'
Expand Down

0 comments on commit 3a77c8b

Please sign in to comment.