-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5dfb3af
Showing
4 changed files
with
187 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: "Test" | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
|
||
jobs: | ||
test: | ||
name: "Test on ${{ matrix.config.os-name }}" | ||
runs-on: "${{ matrix.config.runner }}" | ||
strategy: | ||
matrix: | ||
config: | ||
- os-name: "Linux" | ||
runner: "ubuntu-latest" | ||
test-label: "ci-test-linux" | ||
- os-name: "macOS" | ||
runner: "macos-latest" | ||
test-label: "ci-test-macos" | ||
- os-name: "Windows" | ||
runner: "windows-latest" | ||
test-label: "ci-test-windows" | ||
fail-fast: false | ||
|
||
steps: | ||
- name: "Show environment (pre)" | ||
shell: "bash" | ||
run: env | sort | ||
|
||
- name: "Checkout" | ||
uses: "actions/checkout@v4" | ||
|
||
- name: "Setup Python" | ||
id: "setup-python" | ||
uses: "actions/setup-python@v4" | ||
with: | ||
python-version: | | ||
3.9 | ||
3.10 | ||
3.11 | ||
pypy-3.9 | ||
allow-prereleases: true | ||
|
||
- name: "Show environment (post)" | ||
shell: "bash" | ||
run: env | sort | ||
|
||
- name: "Linux / macOS" | ||
id: linux | ||
if: "runner.os != 'windows'" | ||
shell: "bash" | ||
run: | | ||
bash ./finder.sh | ||
bash ./finder.sh > "$GITHUB_OUTPUT" | ||
- name: "Windows" | ||
id: "windows" | ||
if: "runner.os == 'windows'" | ||
shell: "powershell" | ||
run: | | ||
& .\finder.ps1 | ||
& .\finder.ps1 > "$env:GITHUB_OUTPUT" | ||
- name: "Show results" | ||
shell: "bash" | ||
run: | | ||
echo "${{ steps.linux.outputs.python-paths }}${{ steps.windows.outputs.python-paths }}" |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: 'Detect Python versions' | ||
description: | | ||
Find Python paths and output them as "python-versions". | ||
This can be useful for cache busting of tox and/or virtual environments. | ||
inputs: | ||
search-runner-tool-cache: | ||
description: | | ||
By default, only paths in the PATH environment variable will be searched | ||
because the "actions/setup-python" action typically modifies the PATH | ||
after installing various Python versions. | ||
Because it is possible to prevent "actions/setup-python" from modifying the PATH, | ||
and because some GitHub runner images have multiple Python versions pre-installed, | ||
it may be desirable to find every Python installed on the system, | ||
even if their paths don't appear in the PATH environment variable. | ||
If this input is specified, its value must be the string value "true". | ||
Use quotation marks to ensure the correct value is passed. | ||
required: false | ||
default: "false" | ||
|
||
outputs: | ||
python-paths: | ||
description: "A string of sorted Python executable paths" | ||
value: ${{ steps.final-step.outputs.python-path }} | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: "Find Pythons on Linux / macOS" | ||
id: "linux" | ||
if: "runner.os != 'windows'" | ||
shell: "bash" | ||
run: 'bash ./finder.sh "${{ inputs.search-runner-tool-cache }}" > "$GITHUB_OUTPUT"' | ||
|
||
- name: "Find Pythons on Windows" | ||
id: "windows" | ||
if: "runner.os == 'windows'" | ||
shell: "powershell" | ||
run: '& .\finder.ps1 "${{ inputs.search-runner-tool-cache }}" > "$env:GITHUB_OUTPUT"' | ||
|
||
- name: "Output" | ||
id: "final-step" | ||
shell: "bash" | ||
run: | | ||
echo "${{ steps.linux.outputs.python-paths }}${{ steps.windows.outputs.python-paths }}" > $GITHUB_OUTPUT |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
$search_runner_tool_cache = $args[0] | ||
|
||
if ($search_runner_tool_cache -eq "true") { | ||
# Search paths in $RUNNER_TOOL_CACHE for Python interpreters. | ||
$all_paths = ` | ||
Get-ChildItem ` | ||
-Path ` | ||
"$env:RUNNER_TOOL_CACHE\Python\*\*", ` | ||
"$env:RUNNER_TOOL_CACHE\PyPy\*\*" ` | ||
-Filter "x??" ` | ||
-Directory ` | ||
| Sort-Object -Property FullName ` | ||
| Select-Object -ExpandProperty "FullName" | ||
} else { | ||
# Search paths in $PATH for Python interpreters. | ||
$all_paths = ` | ||
$env:PATH -split ";" ` | ||
| Sort-Object | ||
} | ||
|
||
Write-Output $all_paths | ||
|
||
$paths = @() | ||
foreach ($path in $all_paths) { | ||
Write-Output $path | ||
if (Test-Path $path) { | ||
Get-ChildItem $path | ||
if (Test-Path "$path\python.exe") { | ||
$paths += $path.FullName | ||
} | ||
} | ||
} | ||
|
||
$result = $paths -join ";" | ||
Write-Output "python-paths=$result" |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
search_runner_tool_cache="$1" | ||
|
||
if [ "$search_runner_tool_cache" = "true" ]; then | ||
# Search paths in $RUNNER_TOOL_CACHE for Python interpreters. | ||
read -r -a all_paths <<< "$( | ||
find \ | ||
"$RUNNER_TOOL_CACHE/Python" \ | ||
"$RUNNER_TOOL_CACHE/PyPy" \ | ||
-mindepth 2 \ | ||
-maxdepth 2 \ | ||
-name 'x86' \ | ||
-o \ | ||
-name 'x64' \ | ||
| sort | ||
)" | ||
else | ||
# Search paths in $PATH for Python interpreters. | ||
read -r -a all_paths <<< "$( | ||
echo "$PATH" \ | ||
| tr ':' '\n' \ | ||
| sort | ||
)" | ||
fi | ||
|
||
paths=() | ||
for path in "${all_paths[@]}"; do | ||
echo "${path}" | ||
if [[ -d "${path}" ]]; then | ||
ls "${path}" | ||
if [[ -x "${path}/bin/python" ]]; then | ||
paths+=("${path}/bin") | ||
fi | ||
fi | ||
done | ||
|
||
result="$(echo "${paths[*]}" | tr ' ' ':')" | ||
echo "python-paths=${result}" |