-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
87 lines (81 loc) · 4.56 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: 'Check that Python is available'
description: 'Verify that the desired Python version is available on the running host.'
inputs:
python-version:
description: "Exact version of Python. Will override any .python-version file provided either by default or in the python-version-file parameter."
default: ''
python-version-file:
description: "Path to the .python-version file to use to select the desired Python version. This does not support the full flexibility of the .python-version specification but instead only supports a single line in the file with only a single version on that line. Anything else is undefined."
default: '.python-version'
is-self-hosted:
description: "Boolean indicating if the runner is self hosted or not, defaults to true."
required: false
default: 'true'
outputs:
python-version:
description: "The actual version of Python selected."
value: ${{ steps.finalize.outputs.python-version }}
python-path:
description: "The path to the expected Python executable."
value: ${{ steps.finalize.outputs.python-path }}
runs:
using: 'composite'
steps:
- name: GHA setup-python for GH hosted runner
id: gha-setup-python
# We want to run this on anything but on self-hosted macs and Windows
# ARM64.
if: (inputs.is-self-hosted == 'false' || runner.os != 'macOS') && !(runner.os == 'Windows' && runner.arch == 'ARM64')
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # 5.0.0
with:
python-version: ${{ inputs.python-version }}
- name: "Python for Windows/arm64"
id: win-arm64-setup
if: runner.os == 'Windows' && runner.arch == 'ARM64'
shell: pwsh
run: |
# Temporary hack until https://github.com/actions/setup-python/issues/715 is
# fixed. python win-arm64 has to be added to
# https://github.com/actions/python-versions/blob/main/versions-manifest.json
if (("${{ inputs.python-version }}" -eq "3.11") -or ((Test-Path "${{ inputs.python-version-file }}") -and ((Get-Content "${{ inputs.python-version-file }}") -eq "3.11"))) {
$Version = "3.11.9"
$Name = "python-${Version}-embed-arm64"
curl -O "https://www.python.org/ftp/python/${Version}/${Name}.zip"
Expand-Archive "${Name}.zip" -Force
echo "${PWD}\${Name}" >> $GITHUB_PATH
# Some xplat code uses `python3` because that is the executable name on Unix/macOS
New-Item -Path "${Name}\python3.exe" -ItemType SymbolicLink -Value "python.exe" -ErrorAction Ignore
# Remove any app execution aliases (redirecting to the Windows Store) which may conflict in the Path
Remove-Item "$Env:LocalAppData\Microsoft\WindowsApps\python.exe" -Force -ErrorAction Ignore | Out-Null
Remove-Item "$Env:LocalAppData\Microsoft\WindowsApps\python3.exe" -Force -ErrorAction Ignore | Out-Null
} else {
Write-Host "Please fix hack for python on Windows/ARM64. Maybe https://github.com/actions/setup-python/issues/715 has been fixed."
Exit 1
}
- name: Check desired Python is available and set outputs
id: finalize
shell: bash
run: |
if [[ "${{ steps.win-arm64-setup.outcome }}" == "success" ]]; then
EXPECTED_VERSION="3"
command -v python$EXPECTED_VERSION > /dev/null 2>&1
EXPECTED_PYTHON_PATH="$(which python${EXPECTED_VERSION})"
elif [[ "${{ steps.gha-setup-python.outcome }}" == "success" ]]; then
# On macOS, we want something like python3.11, not python3.11.8 like
# what setup-python above will output.
# On Windows, we sadly just want python3.
EXPECTED_VERSION="$(python3 -c "import sys;print('.'.join(sys.argv[1].rsplit('.',3)[:1 if sys.platform=='win32' else 2]))" ${{ steps.gha-setup-python.outputs.python-version }})"
EXPECTED_PYTHON_PATH="${{ steps.gha-setup-python.outputs.python-path }}"
else
EXPECTED_VERSION=""
if [[ -n "${{ inputs.python-version }}" ]]; then
EXPECTED_VERSION="${{ inputs.python-version }}"
elif [[ -f "${{ inputs.python-version-file }}" ]]; then
EXPECTED_VERSION="$(cat "${{ inputs.python-version-file }}" | cut -d' ' -f1)"
fi
command -v python$EXPECTED_VERSION > /dev/null 2>&1
EXPECTED_PYTHON_PATH="$(which python${EXPECTED_VERSION})"
fi
echo "python-version=${EXPECTED_VERSION}" >> $GITHUB_OUTPUT
echo "python-path=${EXPECTED_PYTHON_PATH}" >> $GITHUB_OUTPUT
echo "Found python${EXPECTED_VERSION} at ${EXPECTED_PYTHON_PATH}"