Skip to content

Commit

Permalink
feat(python): support arm (#168)
Browse files Browse the repository at this point in the history
closes #167
implements workaround for installing python on ubuntu arm
  • Loading branch information
leiicamundi authored Mar 4, 2024
1 parent 0ea667b commit e577a32
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 27 deletions.
47 changes: 41 additions & 6 deletions .github/actionlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,53 @@
self-hosted-runner:
# Labels of self-hosted runner in array of string
labels:
- aws-arm-core-2-default
- aws-arm-core-2-release
- aws-arm-core-2-longrunning
- aws-core-2-default
- aws-core-2-release
- aws-core-2-longrunning
- aws-arm-core-4-default
- aws-arm-core-4-release
- aws-arm-core-4-longrunning
- aws-core-4-default
- aws-core-4-release
- aws-core-4-longrunning
- aws-arm-core-8-default
- aws-arm-core-8-release
- aws-arm-core-8-longrunning
- aws-core-8-default
- aws-core-8-release
- aws-core-8-longrunning
- aws-arm-core-16-default
- aws-arm-core-16-release
- aws-arm-core-16-longrunning
- aws-core-16-default
- aws-core-16-release
- aws-core-16-longrunning
- aws-arm-core-32-default
- aws-arm-core-32-release
- aws-arm-core-32-longrunning
- aws-core-32-default
- aws-core-32-release
- aws-core-32-longrunning
- gcp-core-2-default
- gcp-core-2-release
- gcp-core-4-release
- gcp-core-8-release
- gcp-core-16-release
- gcp-core-32-release
- gcp-core-2-longrunning
- gcp-core-4-default
- gcp-core-4-release
- gcp-core-4-longrunning
- gcp-core-8-default
- gcp-core-8-release
- gcp-core-8-longrunning
- gcp-core-16-default
- gcp-core-16-release
- gcp-core-16-longrunning
- gcp-core-32-default
- gcp-core-32-release
- gcp-core-32-longrunning
- gcp-core-2-default
- gcp-core-4-default
- gcp-core-32-release-big-ssd
- gcp-core-32-longrunning-big-ssd
- n1-standard-32-netssd-preempt
- n1-standard-16-netssd-preempt
- n1-standard-8-netssd-preempt
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/test-common-tooling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
label: ["ubuntu-latest", "gcp-core-2-default"]
label: ["ubuntu-latest", "gcp-core-2-default", "aws-arm-core-2-default"]
runs-on: ${{ matrix.label }}
timeout-minutes: 10
steps:
Expand Down Expand Up @@ -56,6 +56,13 @@ jobs:
else
mvn --version
fi
if ! command -v python3 &> /dev/null
then
echo "python3 could not be found"
exit 1
else
python3 --version
fi
if ! command -v python &> /dev/null
then
echo "python could not be found"
Expand All @@ -82,5 +89,5 @@ jobs:
node-version: 20 # see https://github.com/actions/setup-node#supported-version-syntax for supported syntax
java-version: 20 # see https://github.com/marketplace/actions/setup-java-jdk#supported-version-syntax for supported syntax
java-distribution: adopt # see https://github.com/marketplace/actions/setup-java-jdk#supported-distributions for supported distros
python-version: 3 # see https://github.com/actions/setup-python#supported-version-syntax for supported syntax
python-version: "3.11" # see https://github.com/actions/setup-python#supported-version-syntax for supported syntax
overwrite: 'true'
18 changes: 10 additions & 8 deletions common-tooling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ e.g.
| java-maven-version | The Maven version to set up |
| java-enabled | Whether to install java or not |
| python-version | Version range or exact version of Python or PyPy to use, using SemVer's version range syntax. Reads from .python-version if unset. | 3.11 |
| python-version-file | File containing the Python version to use. Example: .python-version |
| python-cache | Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry. |
| python-architecture | The target architecture (x86, x64) of the Python or PyPy interpreter. |
| python-check-latest | Set this option if you want the action to check for the latest available version that satisfies the version spec. |
| python-token | The token used to authenticate when fetching Python distributions from https://github.com/actions/python-versions. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. |
| python-cache-dependency-path | Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies. |
| python-update-environment | Set this option if you want the action to update environment variables. |
| python-allow-prereleases | When 'true', a version range passed to 'python-version' input will match prerelease versions if no GA versions are found. Only 'x.y' version range is supported for CPython. |
| python-version-file | File containing the Python version to use. Example: .python-version (not supported on arm) |
| python-cache | Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry. (not supported on arm) |
| python-architecture | The target architecture (x86, x64) of the Python or PyPy interpreter. (not supported on arm) |
| python-check-latest | Set this option if you want the action to check for the latest available version that satisfies the version spec. (not supported on arm) |
| python-token | The token used to authenticate when fetching Python distributions from https://github.com/actions/python-versions. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. (not supported on arm) |
| python-cache-dependency-path | Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies. (not supported on arm) |
| python-update-environment | Set this option if you want the action to update environment variables. (not supported on arm) |
| python-allow-prereleases | When 'true', a version range passed to 'python-version' input will match prerelease versions if no GA versions are found. Only 'x.y' version range is supported for CPython. (not supported on arm) |
| python-enabled | Whether to install python or not |
| python-deadsnakes-debug | Whether to use debug version of python (deadnakes arm only) | false |
| python-deadsnakes-nogil | Whether to use free-threaded version of python (deadnakes arm only) | false |
| overwrite | Defines whether on hosted runners the present version should be overwritten | false |

### Workflow Example
Expand Down
53 changes: 42 additions & 11 deletions common-tooling/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,41 @@ inputs:
default: 'true'
# Python
python-version:
description: "Version range or exact version of Python or PyPy to use, using SemVer's version range syntax. Reads from .python-version if unset."
description: "Version range or exact version of Python or PyPy to use, specified using SemVer's version range syntax. If unset, it reads from .python-version. Please note that on ARM, the list of available versions differs, and you can find the list of Python distributions at https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa/+packages."
default: "3.11"
python-version-file:
description: "File containing the Python version to use. Example: .python-version"
description: "File containing the Python version to use. Example: .python-version (not supported on arm)"
python-cache:
description: "Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry."
description: "Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry. (not supported on arm)"
required: false
python-architecture:
description: "The target architecture (x86, x64) of the Python or PyPy interpreter."
description: "The target architecture (x86, x64) of the Python or PyPy interpreter. (not supported on arm)"
python-check-latest:
description: "Set this option if you want the action to check for the latest available version that satisfies the version spec."
description: "Set this option if you want the action to check for the latest available version that satisfies the version spec. (not supported on arm)"
default: "false"
python-token:
description: "The token used to authenticate when fetching Python distributions from https://github.com/actions/python-versions. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting."
description: "The token used to authenticate when fetching Python distributions from https://github.com/actions/python-versions. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. (not supported on arm)"
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
python-cache-dependency-path:
description: "Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies."
description: "Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies. (not supported on arm)"
python-update-environment:
description: "Set this option if you want the action to update environment variables."
description: "Set this option if you want the action to update environment variables. (not supported on arm)"
default: 'true'
python-allow-prereleases:
description: "When 'true', a version range passed to 'python-version' input will match prerelease versions if no GA versions are found. Only 'x.y' version range is supported for CPython."
description: "When 'true', a version range passed to 'python-version' input will match prerelease versions if no GA versions are found. Only 'x.y' version range is supported for CPython. (not supported on arm)"
default: "false"
python-enabled:
description: 'Whether to install python or not'
default: 'true'
python-deadsnakes-debug:
description: 'Whether to use debug version of python (deadnakes arm only)'
required: false
default: false
python-deadsnakes-nogil:
description: 'Whether to use free-threaded version of python (deadnakes arm only)'
required: false
default: false

# misc
overwrite:
description: 'Defines whether on hosted runners the present version should be overwritten'
Expand Down Expand Up @@ -248,10 +257,12 @@ runs:
cache-prefix: ${{ inputs.java-cache-prefix }}
cache-path: ${{ inputs.java-cache-path }}
cache-path-add: ${{ inputs.java-cache-path-add }}

# Install Python, it's absent on self-hosted runners
- name: Install Python3
- name: Install Python3 (std install)
uses: actions/setup-python@v5
if: ${{ inputs.python-enabled == 'true' && ( env.python_missing == 'true' || inputs.overwrite == 'true' ) }}
# actions/setup-python doesn't yet support ARM
if: ${{ !contains(runner.arch, 'arm') && inputs.python-enabled == 'true' && ( env.python_missing == 'true' || inputs.overwrite == 'true' ) }}
with:
python-version: ${{ inputs.python-version }}
python-version-file: ${{ inputs.python-version-file }}
Expand All @@ -262,6 +273,26 @@ runs:
cache-dependency-path: ${{ inputs.python-cache-dependency-path }}
update-environment: ${{ inputs.python-update-environment }}
allow-prereleases: ${{ inputs.python-allow-prereleases }}

- name: Install Python3 (arm install)
uses: deadsnakes/[email protected]
# actions/setup-python doesn't yet support ARM, see https://github.com/actions/setup-python/issues/705#issuecomment-1756948951
if: ${{ contains(runner.arch, 'arm') && inputs.python-enabled == 'true' && ( env.python_missing == 'true' || inputs.overwrite == 'true' ) }}
with:
python-version: ${{ inputs.python-version }}
debug: ${{ inputs.python-deadsnakes-debug }}
nogil: ${{ inputs.python-deadsnakes-nogil }}

- name: Add Python3 Shortcut and add pip (ARM)
if: ${{ contains(runner.arch, 'arm') && inputs.python-enabled == 'true' && ( env.python_missing == 'true' || inputs.overwrite == 'true' ) }}
shell: bash
run: |
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
: # install pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
/usr/bin/python get-pip.py
- name: Unset Environment variables
shell: bash
run: |
Expand Down

0 comments on commit e577a32

Please sign in to comment.