Skip to content

Commit

Permalink
action: use the most recent python from tool cache to run the GitHub …
Browse files Browse the repository at this point in the history
…Action
  • Loading branch information
mayeut committed May 23, 2022
1 parent 0b1b47d commit 5f12f8a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ jobs:
name: sample_wheels
path: wheelhouse

- name: Get some sample wheels (GitHub Action)
uses: ./
with:
package-dir: sample_proj
output-dir: wheelhouse_action
env:
CIBW_ARCHS_MACOS: x86_64 universal2 arm64

- uses: actions/upload-artifact@v3
with:
name: sample_wheels_action
path: wheelhouse_action

- name: Test cibuildwheel
run: |
python ./bin/run_tests.py
Expand Down
42 changes: 42 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,52 @@ branding:
runs:
using: composite
steps:
# Set up a non-EOL, cibuildwheel & pipx supported Python version
- name: Find python interpreter
id: python
run: |
from pathlib import Path
import os
import platform
import sys
SUPPORTED_VERSIONS=("3.10", "3.9", "3.8", "3.7", "3.6")
EXT = "${{ runner.os == 'Windows' && '.exe' || '3' }}"
PREFIX = "${{ runner.os != 'Windows' && 'bin/' || '' }}"
ARCH_MAP = {"AMD64": "x64", "x86_64": "x64"}
arch = ARCH_MAP.get(platform.machine(), None)
base_path = Path(os.environ.get("RUNNER_TOOL_CACHE", "not_existing")) / "Python"
if arch and base_path.exists():
for version in SUPPORTED_VERSIONS:
pattern = "{}.*/{}/{}python{}".format(version, arch, PREFIX, EXT)
matches = list(base_path.glob(pattern))
if matches:
exact_version = matches[0].relative_to(base_path).parts[0]
print("Using cached CPython {} at {}".format(exact_version, matches[0]))
print("::set-output name=interpreter-path::{}".format(matches[0]))
exit(0)
# fallback
print("::warning ::Couldn't find a suitable python version in the toolcache, fallback to current interpreter")
current_version = ".".join(map(str, sys.version_info[:2]))
if current_version in SUPPORTED_VERSIONS:
exact_version = ".".join(map(str, sys.version_info[:3]))
print("Using Python {} at {}".format(exact_version, sys.executable))
print("::set-output name=interpreter-path::{}".format(sys.executable))
exit(0)
print(
"::error ::The current interpreter is Python {}, cibuildwheel requires one of {}.".format(
current_version, ", ".join(SUPPORTED_VERSIONS)
),
"You can use actions/setup-python to install a supported version."
)
exit(1)
shell: "python3 {0}"

# Redirecting stderr to stdout to fix interleaving issue in Actions.
- run: >
pipx run
--python '${{ steps.python.outputs.interpreter-path }}'
--spec '${{ github.action_path }}'
cibuildwheel
${{ inputs.package-dir }}
Expand Down

0 comments on commit 5f12f8a

Please sign in to comment.