From 9a40041e255a2c42da53a3eb6e3b806ae7770e89 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 12 Jul 2022 16:38:54 +0200 Subject: [PATCH 01/25] Rearrange README.md, add advanced-usage.md --- README.md | 428 +++++---------------------------------- docs/advanced-usage.md | 439 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 484 insertions(+), 383 deletions(-) create mode 100644 docs/advanced-usage.md diff --git a/README.md b/README.md index 6e178e2f6..a164bcc56 100644 --- a/README.md +++ b/README.md @@ -1,277 +1,60 @@ -# setup-python V4 +# setup-python

GitHub Actions status

-This action sets up a Python environment for use in actions by: +This action provides the following functionality for GitHub Actions users: -- optionally installing and adding to PATH a version of Python that is already installed in the tools cache. -- downloading, installing and adding to PATH an available version of Python from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)) if a specific version is not available in the tools cache. -- failing if a specific version of Python is not preinstalled or available for download. -- optionally caching dependencies for pip, pipenv and poetry. -- registering problem matchers for error output. +- Optionally downloading and installing the requested version of Python/PyPy and adding it to the PATH +- Optionally caching dependencies for pip, pipenv and poetry +- Registering problem matchers for error output -# What's new +## Table of contents -- Ability to download, install and set up Python packages from `actions/python-versions` that do not come preinstalled on runners. - - Allows for pinning to a specific patch version of Python without the worry of it ever being removed or changed. -- Automatic setup and download of Python packages if using a self-hosted runner. -- Support for pre-release versions of Python. -- Support for installing any version of PyPy on-flight -- Support for built-in caching of pip, pipenv and poetry dependencies -- Support for `.python-version` file +- [Basic usage](#basic-usage) +- [Supported version syntax](#supported-version-syntax) +- [Supported architectures](#supported-architectures) +- [Caching packages dependencies](#caching-packages-dependencies) +- [Advanced usage](#advanced-usage) +- [License](#license) +- [Contributions](#contributions) -# Usage +## Basic usage See [action.yml](action.yml) -Basic: ```yaml steps: - uses: actions/checkout@v3 -- uses: actions/setup-python@v4 - with: - python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax - architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified -- run: python my_script.py -``` - -Read Python version from file: -```yaml -steps: -- uses: actions/checkout@v3 -- uses: actions/setup-python@v4 - with: - python-version-file: '.python-version' # Read python version from a file -- run: python my_script.py -``` - -Matrix Testing: -```yaml -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [ '2.x', '3.x', 'pypy2.7', 'pypy3.7', 'pypy3.8' ] - name: Python ${{ matrix.python-version }} sample - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - architecture: x64 - - run: python my_script.py -``` - -Exclude a specific Python version: -```yaml -jobs: - build: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ['2.7', '3.7', '3.8', '3.9', '3.10', 'pypy2.7', 'pypy3.8'] - exclude: - - os: macos-latest - python-version: '3.8' - - os: windows-latest - python-version: '3.6' - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Display Python version - run: python --version -``` - -Download and set up a version of Python that does not come preinstalled on an image: -```yaml -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - # in this example, there is a newer version already installed, 3.7.7, so the older version will be downloaded - python-version: ['3.7.4', '3.8', '3.9', '3.10'] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - run: python my_script.py -``` - -Download and set up an accurate pre-release version of Python: -```yaml -steps: -- uses: actions/checkout@v3 -- uses: actions/setup-python@v4 - with: - python-version: '3.11.0-alpha.1' -- run: python my_script.py -``` - -Download and set up the latest available version of Python (includes both pre-release and stable versions): -```yaml -steps: -- uses: actions/checkout@v3 -- uses: actions/setup-python@v4 - with: - python-version: '3.11.0-alpha - 3.11.0' # SemVer's version range syntax -- run: python my_script.py -``` - -Download and set up the latest patch version of Python (for specified major & minor versions): -```yaml -steps: -- uses: actions/checkout@v3 -- uses: actions/setup-python@v4 - with: - python-version: '3.11-dev' -- run: python my_script.py -``` - -Download and set up the latest stable version of Python (for specified major version): -```yaml -steps: -- uses: actions/checkout@v3 -- uses: actions/setup-python@v4 +- uses: actions/setup-python@v4 # <- v4 is a major release tag of the action: https://github.com/actions/setup-python/tags with: - python-version: '3.x' + python-version: '3.10' - run: python my_script.py ``` +The `python-version` input is optional. If not supplied, the Python/PyPy version from the PATH will be used. The default version of Python/PyPy in PATH vary between runners and can be changed unexpectedly so we recommend always use `setup-python`. -Download and set up PyPy: - -```yaml -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: - - 'pypy3.7' # the latest available version of PyPy that supports Python 3.7 - - 'pypy3.7-v7.3.3' # Python 3.7 and PyPy 7.3.3 - - 'pypy3.8' # the latest available version of PyPy that supports Python 3.8 - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - run: python my_script.py -``` -More details on PyPy syntax and examples of using preview / nightly versions of PyPy can be found in the [Available versions of PyPy](#available-versions-of-pypy) section. - -An output is available with the absolute path of the python interpreter executable if you need it: -```yaml -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - id: cp310 - with: - python-version: "3.10" - - run: pipx run --python '${{ steps.cp310.outputs.python-path }}' nox --version -``` - ->The environment variable `pythonLocation` also becomes available after Python or PyPy installation. It contains the absolute path to the folder where the desired version of Python or PyPy is installed. - -# Getting started with Python + Actions - -Check out our detailed guide on using [Python with GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-python-with-github-actions). - -# Available versions of Python - -`setup-python` is able to configure Python from two sources: - -- Preinstalled versions of Python in the tools cache on GitHub-hosted runners. - - For detailed information regarding the available versions of Python that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software). - - For every minor version of Python, expect only the latest patch to be preinstalled. - - If `3.8.1` is installed for example, and `3.8.2` is released, expect `3.8.1` to be removed and replaced by `3.8.2` in the tools cache. - - If the exact patch version doesn't matter to you, specifying just the major and minor version will get you the latest preinstalled patch version. In the previous example, the version spec `3.8` will use the `3.8.2` Python version found in the cache. - - Use `-dev` instead of a patch number (e.g., `3.11-dev`) to install the latest patch version release for a given minor version, *alpha and beta releases included*. -- Downloadable Python versions from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)). - - All available versions are listed in the [version-manifest.json](https://github.com/actions/python-versions/blob/main/versions-manifest.json) file. - - If there is a specific version of Python that is not available, you can open an issue here - -**Note:** Python versions used in this action are generated in the [python-versions](https://github.com/actions/python-versions) repository. For macOS and Ubuntu images python versions are built from the source code. For Windows the python-versions repository uses installation executable. For more information please refer to the [python-versions](https://github.com/actions/python-versions) repository. - - # Available versions of PyPy - - `setup-python` is able to configure PyPy from two sources: - -- Preinstalled versions of PyPy in the tools cache on GitHub-hosted runners - - For detailed information regarding the available versions of PyPy that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software). - - For the latest PyPy release, all versions of Python are cached. - - Cache is updated with a 1-2 week delay. If you specify the PyPy version as `pypy3.7` or `pypy-3.7`, the cached version will be used although a newer version is available. If you need to start using the recently released version right after release, you should specify the exact PyPy version using `pypy3.7-v7.3.3` or `pypy-3.7-v7.3.3`. +The action will first check the local [toolcache](docs/advanced-usage.md#hosted-tool-cache) for a [semver](https://github.com/npm/node-semver#versions) match. If unable to find a specific version in the tool cache, the action will attempt to download a version of Python from [GitHub Releases](https://github.com/actions/python-versions/releases) and for PyPy from the official [PyPy's dist](https://downloads.python.org/pypy/). -- Downloadable PyPy versions from the [official PyPy site](https://downloads.python.org/pypy/). - - All available versions that we can download are listed in [versions.json](https://downloads.python.org/pypy/versions.json) file. - - PyPy < 7.3.3 are not available to install on-flight. - - If some versions are not available, you can open an issue in https://foss.heptapod.net/pypy/pypy/ +For information regarding locally cached versions of Python/PyPy on GitHub hosted runners, check out [GitHub Actions Virtual Environments](https://github.com/actions/virtual-environments). -# Hosted Tool Cache +## Supported version syntax -GitHub hosted runners have a tools cache that comes with a few versions of Python + PyPy already installed. This tools cache helps speed up runs and tool setup by not requiring any new downloads. There is an environment variable called `RUNNER_TOOL_CACHE` on each runner that describes the location of this tools cache and there is where you will find Python and PyPy installed. `setup-python` works by taking a specific version of Python or PyPy in this tools cache and adding it to PATH. +The `python-version` input supports the [Semantic Versioning Specification](https://github.com/npm/node-semver#versions) and some special version notations (e.g. `x.y-dev`), for detailed examples please refer to the section: [Using python-version input](docs/advanced-usage.md#using-python-version-input) of the [Advanced usage](docs/advanced-usage.md) guide. -|| Location | -|------|-------| -|**Tool Cache Directory** |`RUNNER_TOOL_CACHE`| -|**Python Tool Cache**|`RUNNER_TOOL_CACHE/Python/*`| -|**PyPy Tool Cache**|`RUNNER_TOOL_CACHE/PyPy/*`| +## Supported architectures -GitHub virtual environments are setup in [actions/virtual-environments](https://github.com/actions/virtual-environments). During the setup, the available versions of Python and PyPy are automatically downloaded, setup and documented. -- Tools cache setup for Ubuntu: [Install-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/Configure-Toolset.ps1) -- Tools cache setup for Windows: [Install-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Configure-Toolset.ps1) +Using `architecture` input it's possible to specify required python's interpreter architecture: `x86` or `x64`. If input is not specified it defaults to `x64`. -# Specifying a Python version - -If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the exact major, minor, and patch version (such as `3.7.5`) - - The only downside to this is that set up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. - - MSI installers are used on Windows for this, so runs will take a little longer to set up vs Mac and Linux. - -You should specify only a major and minor version if you are okay with the most recent patch version being used. - - There will be a single patch version already installed on each runner for every minor version of Python that is supported. - - The patch version that will be preinstalled, will generally be the latest and every time there is a new patch released, the older version that is preinstalled will be replaced. - - Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version Python on the runner will be used. - -# Specifying a PyPy version -The version of PyPy should be specified in the format `pypy[-v]` or `pypy-[-v]`. -The `` parameter is optional and can be skipped. The latest version will be used in this case. - -``` -pypy3.7 or pypy-3.7 # the latest available version of PyPy that supports Python 3.7 -pypy3.8 or pypy-3.8 # the latest available version of PyPy that supports Python 3.8 -pypy2.7 or pypy-2.7 # the latest available version of PyPy that supports Python 2.7 -pypy3.7-v7.3.3 or pypy-3.7-v7.3.3 # Python 3.7 and PyPy 7.3.3 -pypy3.7-v7.x or pypy-3.7-v7.x # Python 3.7 and the latest available PyPy 7.x -pypy3.7-v7.3.3rc1 or pypy-3.7-v7.3.3rc1 # Python 3.7 and preview version of PyPy -pypy3.7-nightly or pypy-3.7-nightly # Python 3.7 and nightly PyPy -``` - -Note: `pypy2` and `pypy3` have been removed in v3. Use the format above instead. - -# Caching packages dependencies +## Caching packages dependencies The action has built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood for caching dependencies but requires less configuration settings. Supported package managers are `pip`, `pipenv` and `poetry`. The `cache` input is optional, and caching is turned off by default. -The action defaults to searching for a dependency file (`requirements.txt` for pip, `Pipfile.lock` for pipenv or `poetry.lock` for poetry) in the repository, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases where multiple dependency files are used, they are located in different subdirectories or different files for the hash want to be used. - - - For pip, the action will cache global cache directory - - For pipenv, the action will cache virtualenv directory - - For poetry, the action will cache virtualenv directory +The action defaults to searching for a dependency file (`requirements.txt` for pip, `Pipfile.lock` for pipenv or `poetry.lock` for poetry) in the repository, and uses its hash as a part of the cache key. Input `cache-dependency-path` is used for cases when multiple dependency files are used, they are located in different subdirectories or different files for the hash want to be used. -**Please Note:** Restored cache will not be used if the requirements.txt file is not updated for a long time and a newer version of the dependency is available that can lead to an increase in total build time. - -The requirements file format allows to specify dependency versions using logical operators (for example chardet>=3.0.4) or specify dependencies without any versions. In this case the pip install -r requirements.txt command will always try to install the latest available package version. To be sure that the cache will be used, please stick to a specific dependency version and update it manually if necessary. + - For `pip`, the action will cache global cache directory + - For `pipenv`, the action will cache virtualenv directory + - For `poetry`, the action will cache virtualenv directory **Caching pip dependencies:** @@ -281,152 +64,31 @@ steps: - uses: actions/setup-python@v4 with: python-version: '3.9' - cache: 'pip' + cache: 'pip' # caching pip dependencies - run: pip install -r requirements.txt ``` +>**Note:** Restored cache will not be used if the requirements.txt file is not updated for a long time and a newer version of the dependency is available that can lead to an increase in total build time. -**Caching pipenv dependencies:** -```yaml -steps: -- uses: actions/checkout@v3 -- uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pipenv' -- name: Install pipenv - run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python -- run: pipenv install -``` - -**Caching poetry dependencies:** -```yaml -steps: -- uses: actions/checkout@v3 -- name: Install poetry - run: pipx install poetry -- uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'poetry' -- run: poetry install -- run: poetry run pytest -``` - -**Using wildcard patterns to cache dependencies** -```yaml -steps: -- uses: actions/checkout@v3 -- uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pip' - cache-dependency-path: '**/requirements-dev.txt' -- run: pip install -r subdirectory/requirements-dev.txt -``` - -**Using a list of file paths to cache dependencies** -```yaml -steps: -- uses: actions/checkout@v3 -- uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pipenv' - cache-dependency-path: | - server/app/Pipfile.lock - __test__/app/Pipfile.lock -- name: Install pipenv - run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python -- run: pipenv install -``` - -**Using a list of wildcard patterns to cache dependencies** -```yaml -steps: -- uses: actions/checkout@v3 -- uses: actions/setup-python@v4 - with: - python-version: '3.10' - cache: 'pip' - cache-dependency-path: | - **/setup.cfg - **/requirements*.txt -- run: pip install -e . -r subdirectory/requirements-dev.txt -``` - - -# Environment variables - - The `update-environment` flag defaults to `true`. - With this setting, the action will add/update environment variables (e.g. `PATH`, `PKG_CONFIG_PATH`, `pythonLocation`) for `python` to just work out of the box. - - If `update-environment` is set to `false`, the action will not add/update environment variables. - This can prove useful if you want the only side-effect to be to ensure python is installed and rely on the `python-path` output to run python. - Such a requirement on side-effect could be because you don't want your composite action messing with your user's workflows. - - ```yaml - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - id: cp310 - with: - python-version: '3.10' - update-environment: false - - run: ${{ steps.cp310.outputs.python-path }} my_script.py - ``` - -# Using `setup-python` with a self hosted runner - -Python distributions are only available for the same [environments](https://github.com/actions/virtual-environments#available-environments) that GitHub Actions hosted environments are available for. If you are using an unsupported version of Ubuntu such as `19.04` or another Linux distribution such as Fedora, `setup-python` will not work. If you have a supported self-hosted runner and you would like to use `setup-python`, there are a few extra things you need to make sure are set up so that new versions of Python can be downloaded and configured on your runner. - -If you are experiencing problems while configuring Python on your self-hosted runner, turn on [step debugging](https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs) to see addition logs. - -### Windows - -- Your runner needs to be running with administrator privileges so that the appropriate directories and files can be set up when downloading and installing a new version of Python for the first time. -- If your runner is configured as a service, make sure the account that is running the service has the appropriate write permissions so that Python can get installed. The default `NT AUTHORITY\NETWORK SERVICE` should be sufficient. -- You need `7zip` installed and added to your `PATH` so that the downloaded versions of Python files can be extracted properly during first-time setup. -- MSI installers are used when setting up Python on Windows. A word of caution as MSI installers update registry settings. -- The 3.8 MSI installer for Windows will not let you install another 3.8 version of Python. If `setup-python` fails for a 3.8 version of Python, make sure any previously installed versions are removed by going to "Apps & Features" in the Settings app. - -### Linux - -- The Python packages that are downloaded from `actions/python-versions` are originally compiled from source in `/opt/hostedtoolcache/` with the [--enable-shared](https://github.com/actions/python-versions/blob/94f04ae6806c6633c82db94c6406a16e17decd5c/builders/ubuntu-python-builder.psm1#L35) flag, which makes them non-relocatable. -- By default runner downloads and install the tools to `/opt/hostedtoolcache`. The environment variable called `AGENT_TOOLSDIRECTORY` can be set to change this location. - - In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`. - - A more permanent way of setting the environment variable is to create a `.env` file in the same directory as your runner and to add `AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`. This ensures the variable is always set if your runner is configured as a service. -- Create a directory called `hostedtoolcache` inside `/opt`. -- The user starting the runner must have write permission to the `/opt/hostedtoolcache` directory. It is not possible to start the Linux runner with `sudo` and the `/opt` directory usually requires root privileges to write to. Check the current user and group that the runner belongs to by typing `ls -l` inside the runners root directory. -- The runner can be granted write access to the `/opt/hostedtoolcache` directory using a few techniques: - - The user starting the runner is the owner, and the owner has write permission. - - The user starting the runner is in the owning group, and the owning group has write permission. - - All users have write permission. -- One quick way to grant access is to change the user and group of `/opt/hostedtoolcache` to be the same as the runners using `chown`. - - `sudo chown runner-user:runner-group /opt/hostedtoolcache/`. -- If your runner is configured as a service and you run into problems, make sure the user that the service is running as is correct. For more information, you can [check the status of your self-hosted runner](https://help.github.com/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service#checking-the-status-of-the-service). - -### Mac - -- The same setup that applies to `Linux` also applies to `Mac`, just with a different tools cache directory. -- Create a directory called `/Users/runner/hostedtoolcache`. -- Set the `AGENT_TOOLSDIRECTORY` environment variable to `/Users/runner/hostedtoolcache`. -- Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access. - - -# Using Python without `setup-python` - -`setup-python` helps keep your dependencies explicit and ensures consistent behavior between different runners. If you use `python` in a shell on a GitHub hosted runner without `setup-python` it will default to whatever is in PATH. The default version of Python in PATH vary between runners and can change unexpectedly so we recommend you always use `setup-python`. +>The requirements file format allows to specify dependency versions using logical operators (for example chardet>=3.0.4) or specify dependencies without any versions. In this case the pip install -r requirements.txt command will always try to install the latest available package version. To be sure that the cache will be used, please stick to a specific dependency version and update it manually if necessary. -# Using `setup-python` on GHES +See examples of using `cache` and `cache-dependency-path` for `pipenv` and `poetry` in the section: [Caching packages data](docs/advanced-usage.md#caching-packages-data) of the [Advanced usage](docs/advanced-usage.md) guide. -`setup-python` comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading Python distributions, `setup-python` downloads distributions from [`actions/python-versions`](https://github.com/actions/python-versions) on github.com (outside of the appliance). These calls to `actions/python-versions` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting). If more requests are made within the time frame, then you will start to see rate-limit errors during download that read `##[error]API rate limit exceeded for...`. +## Advanced usage -To avoid hitting rate-limit problems, we recommend [setting up your own runner tool cache](https://docs.github.com/en/enterprise-server@2.22/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access#about-the-included-setup-actions-and-the-runner-tool-cache). +- [Using python-version input](docs/advanced-usage.md#using-python-version-input) +- [Using python-version-file input](docs/advanced-usage.md#using-python-version-file-input) +- [Check latest version](docs/advanced-usage.md#check-latest-version) +- [Caching packages data](docs/advanced-usage.md#caching-packages-data) +- [Environment variables and action's outputs](docs/advanced-usage.md#environment-variables-and-actions-outputs) +- [Available versions of Python and PyPy](docs/advanced-usage.md#available-versions-of-python-and-pypy) +- [Hosted Toolcache](docs/advanced-usage.md#hosted-tool-cache) +- [Using `setup-python` with a self hosted runner](docs/advanced-usage.md#using-setup-python-with-a-self-hosted-runner) +- [Using `setup-python` on GHES](docs/advanced-usage.md#using-setup-python-on-ghes) -# License +## License The scripts and documentation in this project are released under the [MIT License](LICENSE). -# Contributions +## Contributions -Contributions are welcome! See our [Contributor's Guide](docs/contributors.md). +Contributions are welcome! See our [Contributor's Guide](docs/contributors.md). \ No newline at end of file diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md new file mode 100644 index 000000000..874f5db01 --- /dev/null +++ b/docs/advanced-usage.md @@ -0,0 +1,439 @@ +# Table of contents +- [Using python-version input](#using-python-version-file-input) + - [Specifying a Python version](#specifying-a-python-version) + - [Specifying a PyPy version](#specifying-a-pypy-version) + - [Matrix Testing](#matrix-testing) +- [Using python-version-file input](#using-python-version-file-input) +- [Check latest version](#check-latest-version) +- [Caching packages data](#caching-packages-data) +- [Environment variables and action's outputs](#environment-variables-and-actions-outputs) +- [Available versions of Python and PyPy](#available-versions-of-python-and-pypy) + - [Python](#python) + - [PyPy](#pypy) +- [Hosted Tool Cache](#hosted-tool-cache) +- [Using `setup-python` with a self hosted runner](#using-setup-python-with-a-self-hosted-runner) + - [Windows](#windows) + - [Linux](#linux) + - [MacOS](#macos) +- [Using `setup-python` on GHES](#using-setup-python-on-ghes) + +# Using python-version input + +The `python-version` input is used to specify the required version of Python or PyPy. + +## Specifying a Python version + +If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the **exact major, minor, and patch version** (such as `3.7.5`): + + ```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 + with: + python-version: '3.7.5' +- run: python my_script.py +``` + - The only downside to this is that set up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. + - MSI installers are used on Windows for this, so runs will take a little longer to set up vs MacOS and Linux. + +You should specify **only a major and minor version** if you are okay with the most recent patch version being used: + + ```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 + with: + python-version: '3.7' +- run: python my_script.py +``` + - There will be a single patch version already installed on each runner for every minor version of Python that is supported. + - The patch version that will be preinstalled, will generally be the latest and every time there is a new patch released, the older version that is preinstalled will be replaced. + - Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version Python on the runner will be used. + +You can specify version with **prerelease tag** to download and set up an accurate pre-release version of Python: + +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 + with: + python-version: '3.11.0-alpha.1' +- run: python my_script.py +``` + +It's also possible to use **x.y-dev syntax** to download and set up the latest patch version of Python, alpha and beta releases included. (for specified major & minor versions): + +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 + with: + python-version: '3.11-dev' +- run: python my_script.py +``` + +You can also use several types of ranges that are specified in [Semantic Versioning Specification](https://github.com/npm/node-semver#ranges), for instance: + +- **[hyphen ranges](https://github.com/npm/node-semver#hyphen-ranges-xyz---abc)** to download and set up the latest available version of Python (includes both pre-release and stable versions): + +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 + with: + python-version: '3.11.0-alpha - 3.11.0' +- run: python my_script.py +``` + +- **[x-ranges](https://github.com/npm/node-semver#x-ranges-12x-1x-12-)** to specify the latest stable version of Python (for specified major version): + +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 + with: + python-version: '3.x' +- run: python my_script.py +``` +Please refer to the [Advanced range syntax section](https://github.com/npm/node-semver#advanced-range-syntax) of the [Semantic Versioning Specification](https://github.com/npm/node-semver) to check other available range syntaxes. + +## Specifying a PyPy version +The version of PyPy should be specified in the format `pypy[-v]` or `pypy-[-v]`. +The `-v` parameter is optional and can be skipped. The latest PyPy version will be used in this case. + +``` +pypy3.7 or pypy-3.7 # the latest available version of PyPy that supports Python 3.7 +pypy3.8 or pypy-3.8 # the latest available version of PyPy that supports Python 3.8 +pypy2.7 or pypy-2.7 # the latest available version of PyPy that supports Python 2.7 +pypy3.7-v7.3.3 or pypy-3.7-v7.3.3 # Python 3.7 and PyPy 7.3.3 +pypy3.7-v7.x or pypy-3.7-v7.x # Python 3.7 and the latest available PyPy 7.x +pypy3.7-v7.3.3rc1 or pypy-3.7-v7.3.3rc1 # Python 3.7 and preview version of PyPy +pypy3.7-nightly or pypy-3.7-nightly # Python 3.7 and nightly PyPy +``` + +Download and set up PyPy: + +```yaml +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: + - 'pypy3.7' # the latest available version of PyPy that supports Python 3.7 + - 'pypy3.7-v7.3.3' # Python 3.7 and PyPy 7.3.3 + - 'pypy3.8' # the latest available version of PyPy that supports Python 3.8 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - run: python my_script.py +``` +More details on PyPy syntax and examples of using preview / nightly versions of PyPy can be found in the [Available versions of PyPy](#pypy) section. + +## Matrix Testing + +Using `setup-python` it's possible to use [matrix syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) to install several versions of Python/PyPy: + +```yaml +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ '2.x', '3.x', 'pypy2.7', 'pypy3.7', 'pypy3.8' ] + name: Python ${{ matrix.python-version }} sample + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + architecture: x64 + - run: python my_script.py +``` + +Exclude a specific Python version: + +```yaml +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + python-version: ['2.7', '3.7', '3.8', '3.9', '3.10', 'pypy2.7', 'pypy3.8'] + exclude: + - os: macos-latest + python-version: '3.8' + - os: windows-latest + python-version: '3.6' + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Display Python version + run: python --version +``` + +# Using python-version-file input + +`setup-python` action has ability to read Python/PyPy version from a version file. `python-version-file` input is used for specifying path to the version file. If version file at the specified path doesn't exist action will try to find `.python-version` file implying that it as a default type of version files. If `.python-version` file doesn't exist also, action will fail with error. + +>In case both `python-version` and `python-version-file` inputs are supplied, `python-version-file` input will be ignored due to its lower priority. + +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 + with: + python-version-file: '.python-version' # Read python version from a file .python-version +- run: python my_script.py +``` +# Check latest version + +The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific `Python/PyPy` version is always used. + +If `check-latest` is set to `true`, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, a `Python/PyPy` version will then be downloaded. Set `check-latest` to `true` if you want the most up-to-date `Python/PyPy` version to always be used. + +```yaml +steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + with: + python-version: '3.7' + check-latest: true + - run: python my_script.py +``` +> Setting `check-latest` to `true` has performance implications as downloading `Python/PyPy` versions is slower than using cached versions. + + +# Caching packages data + +**Caching pipenv dependencies:** +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pipenv' +- name: Install pipenv + run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python +- run: pipenv install +``` + +**Caching poetry dependencies:** +```yaml +steps: +- uses: actions/checkout@v3 +- name: Install poetry + run: pipx install poetry +- uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'poetry' +- run: poetry install +- run: poetry run pytest +``` +**Using wildcard patterns to cache dependencies** +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + cache-dependency-path: '**/requirements-dev.txt' +- run: pip install -r subdirectory/requirements-dev.txt +``` + +**Using a list of file paths to cache dependencies** +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pipenv' + cache-dependency-path: | + server/app/Pipfile.lock + __test__/app/Pipfile.lock +- name: Install pipenv + run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python +- run: pipenv install +``` + +**Using a list of wildcard patterns to cache dependencies** +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 + with: + python-version: '3.10' + cache: 'pip' + cache-dependency-path: | + **/setup.cfg + **/requirements*.txt +- run: pip install -e . -r subdirectory/requirements-dev.txt +``` + +# Environment variables and action's outputs + +## Action's outputs + +### `python-version` + +Using **python-version** output it's possible to get the installed by action python's version. This output is useful when the input `python-version` given as a range (e.g. 3.8.0 - 3.10.0 ), but down in a workflow you need to operate with exact installed version (e.g. 3.10.1). + +```yaml +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + id: cp310 + with: + python-version: "3.8.0 - 3.10.0" + - run: echo '${{ steps.cp310.outputs.python-version }}' +``` + +### `python-path` + +**python-path** output is available with the absolute path of the python interpreter executable if you need it: + +```yaml +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + id: cp310 + with: + python-version: "3.10" + - run: pipx run --python '${{ steps.cp310.outputs.python-path }}' nox --version +``` + +## Evironment variables + +These environment variables become available after setup-python action execution: + +| Env.Variable | Description | +| ----------- | ----------- | +| pythonLocation |Contains the absolute path to the folder where the requested version of Python or PyPy is installed| +| Python_ROOT_DIR | https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython | +| Python2_ROOT_DIR |https://cmake.org/cmake/help/latest/module/FindPython2.html#module:FindPython2| +| Python3_ROOT_DIR |https://cmake.org/cmake/help/latest/module/FindPython2.html#module:FindPython3| + +## Using `update-environment` flag + +The `update-environment` flag defaults to `true`. +With this setting, the action will add/update environment variables (e.g. `PATH`, `PKG_CONFIG_PATH`, `pythonLocation`) for `python` to just work out of the box. + +If `update-environment` is set to `false`, the action will not add/update environment variables. +This can prove useful if you want the only side-effect to be to ensure python is installed and rely on the `python-path` output to run python. +Such a requirement on side-effect could be because you don't want your composite action messing with your user's workflows. + +```yaml + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + id: cp310 + with: + python-version: '3.10' + update-environment: false + - run: ${{ steps.cp310.outputs.python-path }} my_script.py +``` +# Available versions of Python and PyPy +## Python + +`setup-python` is able to configure **Python** from two sources: + +- Preinstalled versions of Python in the toolcache on GitHub-hosted runners. + - For detailed information regarding the available versions of Python that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software). + - For every minor version of Python, expect only the latest patch to be preinstalled. + - If `3.8.1` is installed for example, and `3.8.2` is released, expect `3.8.1` to be removed and replaced by `3.8.2` in the tools cache. + - If the exact patch version doesn't matter to you, specifying just the major and minor version will get you the latest preinstalled patch version. In the previous example, the version spec `3.8` will use the `3.8.2` Python version found in the cache. + - Use `-dev` instead of a patch number (e.g., `3.11-dev`) to install the latest patch version release for a given minor version, *alpha and beta releases included*. +- Downloadable Python versions from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)). + - All available versions are listed in the [version-manifest.json](https://github.com/actions/python-versions/blob/main/versions-manifest.json) file. + - If there is a specific version of Python that is not available, you can open an issue here + +>**Note:** Python versions used in this action are generated in the [python-versions](https://github.com/actions/python-versions) repository. For macOS and Ubuntu images python versions are built from the source code. For Windows the python-versions repository uses installation executable. For more information please refer to the [python-versions](https://github.com/actions/python-versions) repository. + +## PyPy + + `setup-python` is able to configure **PyPy** from two sources: + +- Preinstalled versions of PyPy in the tools cache on GitHub-hosted runners + - For detailed information regarding the available versions of PyPy that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software). + - For the latest PyPy release, all versions of Python are cached. + - Cache is updated with a 1-2 week delay. If you specify the PyPy version as `pypy3.7` or `pypy-3.7`, the cached version will be used although a newer version is available. If you need to start using the recently released version right after release, you should specify the exact PyPy version using `pypy3.7-v7.3.3` or `pypy-3.7-v7.3.3`. + +- Downloadable PyPy versions from the [official PyPy site](https://downloads.python.org/pypy/). + - All available versions that we can download are listed in [versions.json](https://downloads.python.org/pypy/versions.json) file. + - PyPy < 7.3.3 are not available to install on-flight. + - If some versions are not available, you can open an issue in https://foss.heptapod.net/pypy/pypy/ + +# Hosted Tool Cache + +GitHub hosted runners have a tool cache that comes with a few versions of Python + PyPy already installed. This tool cache helps speed up runs and tool setup by not requiring any new downloads. There is an environment variable called `RUNNER_TOOL_CACHE` on each runner that describes the location of this tools cache and there is where you will find Python and PyPy installed. `setup-python` works by taking a specific version of Python or PyPy in this tools cache and adding it to PATH. + +|| Location | +|------|-------| +|**Tool Cache Directory** |`RUNNER_TOOL_CACHE`| +|**Python Tool Cache**|`RUNNER_TOOL_CACHE/Python/*`| +|**PyPy Tool Cache**|`RUNNER_TOOL_CACHE/PyPy/*`| + +GitHub virtual environments are set up in [actions/virtual-environments](https://github.com/actions/virtual-environments). During the setup, the available versions of Python and PyPy are automatically downloaded, set up and documented. +- Tool cache setup for Ubuntu: [Install-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/Configure-Toolset.ps1) +- Tool cache setup for Windows: [Install-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Configure-Toolset.ps1) + + +# Using `setup-python` with a self hosted runner + +Python distributions are only available for the same [environments](https://github.com/actions/virtual-environments#available-environments) that GitHub Actions hosted environments are available for. If you are using an unsupported version of Ubuntu such as `19.04` or another Linux distribution such as Fedora, `setup-python` will not work. If you have a supported self-hosted runner and you would like to use `setup-python`, there are a few extra things you need to make sure are set up so that new versions of Python can be downloaded and configured on your runner. + +If you are experiencing problems while configuring Python on your self-hosted runner, turn on [step debugging](https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs) to see addition logs. + +### Windows + +- Your runner needs to be running with administrator privileges so that the appropriate directories and files can be set up when downloading and installing a new version of Python for the first time. +- If your runner is configured as a service, make sure the account that is running the service has the appropriate write permissions so that Python can get installed. The default `NT AUTHORITY\NETWORK SERVICE` should be sufficient. +- You need `7zip` installed and added to your `PATH` so that the downloaded versions of Python files can be extracted properly during first-time setup. +- MSI installers are used when setting up Python on Windows. A word of caution as MSI installers update registry settings. +- The 3.8 MSI installer for Windows will not let you install another 3.8 version of Python. If `setup-python` fails for a 3.8 version of Python, make sure any previously installed versions are removed by going to "Apps & Features" in the Settings app. + +### Linux + +- The Python packages that are downloaded from `actions/python-versions` are originally compiled from source in `/opt/hostedtoolcache/` with the [--enable-shared](https://github.com/actions/python-versions/blob/94f04ae6806c6633c82db94c6406a16e17decd5c/builders/ubuntu-python-builder.psm1#L35) flag, which makes them non-relocatable. +- By default runner downloads and install the tools to `/opt/hostedtoolcache`. The environment variable called `AGENT_TOOLSDIRECTORY` can be set to change this location. + - In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`. + - A more permanent way of setting the environment variable is to create a `.env` file in the same directory as your runner and to add `AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`. This ensures the variable is always set if your runner is configured as a service. +- Create a directory called `hostedtoolcache` inside `/opt`. +- The user starting the runner must have write permission to the `/opt/hostedtoolcache` directory. It is not possible to start the Linux runner with `sudo` and the `/opt` directory usually requires root privileges to write to. Check the current user and group that the runner belongs to by typing `ls -l` inside the runners root directory. +- The runner can be granted write access to the `/opt/hostedtoolcache` directory using a few techniques: + - The user starting the runner is the owner, and the owner has write permission. + - The user starting the runner is in the owning group, and the owning group has write permission. + - All users have write permission. +- One quick way to grant access is to change the user and group of `/opt/hostedtoolcache` to be the same as the runners using `chown`. + - `sudo chown runner-user:runner-group /opt/hostedtoolcache/`. +- If your runner is configured as a service and you run into problems, make sure the user that the service is running as is correct. For more information, you can [check the status of your self-hosted runner](https://help.github.com/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service#checking-the-status-of-the-service). + +### MacOS + +- The same setup that applies to `Linux` also applies to `MacOS`, just with a different tools cache directory. +- Create a directory called `/Users/runner/hostedtoolcache`. +- Set the `AGENT_TOOLSDIRECTORY` environment variable to `/Users/runner/hostedtoolcache`. +- Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access. + +# Using `setup-python` on GHES + +`setup-python` comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading Python distributions, `setup-python` downloads distributions from [`actions/python-versions`](https://github.com/actions/python-versions) on github.com (outside of the appliance). These calls to `actions/python-versions` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting). If more requests are made within the time frame, then you will start to see rate-limit errors during download that read `##[error]API rate limit exceeded for...`. + +To avoid hitting rate-limit problems, we recommend [setting up your own runner tool cache](https://docs.github.com/en/enterprise-server@2.22/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access#about-the-included-setup-actions-and-the-runner-tool-cache). From 6dd8ff72eb4e4246f636faddcd73bc7773ff8e42 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 12 Jul 2022 17:32:40 +0200 Subject: [PATCH 02/25] Change tool cache wording --- README.md | 4 ++-- docs/advanced-usage.md | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a164bcc56..4d8d55a68 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ steps: ``` The `python-version` input is optional. If not supplied, the Python/PyPy version from the PATH will be used. The default version of Python/PyPy in PATH vary between runners and can be changed unexpectedly so we recommend always use `setup-python`. -The action will first check the local [toolcache](docs/advanced-usage.md#hosted-tool-cache) for a [semver](https://github.com/npm/node-semver#versions) match. If unable to find a specific version in the tool cache, the action will attempt to download a version of Python from [GitHub Releases](https://github.com/actions/python-versions/releases) and for PyPy from the official [PyPy's dist](https://downloads.python.org/pypy/). +The action will first check the local [tool cache](docs/advanced-usage.md#hosted-tool-cache) for a [semver](https://github.com/npm/node-semver#versions) match. If unable to find a specific version in the tool cache, the action will attempt to download a version of Python from [GitHub Releases](https://github.com/actions/python-versions/releases) and for PyPy from the official [PyPy's dist](https://downloads.python.org/pypy/). For information regarding locally cached versions of Python/PyPy on GitHub hosted runners, check out [GitHub Actions Virtual Environments](https://github.com/actions/virtual-environments). @@ -81,7 +81,7 @@ See examples of using `cache` and `cache-dependency-path` for `pipenv` and `poet - [Caching packages data](docs/advanced-usage.md#caching-packages-data) - [Environment variables and action's outputs](docs/advanced-usage.md#environment-variables-and-actions-outputs) - [Available versions of Python and PyPy](docs/advanced-usage.md#available-versions-of-python-and-pypy) -- [Hosted Toolcache](docs/advanced-usage.md#hosted-tool-cache) +- [Hosted tool cache](docs/advanced-usage.md#hosted-tool-cache) - [Using `setup-python` with a self hosted runner](docs/advanced-usage.md#using-setup-python-with-a-self-hosted-runner) - [Using `setup-python` on GHES](docs/advanced-usage.md#using-setup-python-on-ghes) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 874f5db01..9c2d20c24 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -10,7 +10,7 @@ - [Available versions of Python and PyPy](#available-versions-of-python-and-pypy) - [Python](#python) - [PyPy](#pypy) -- [Hosted Tool Cache](#hosted-tool-cache) +- [Hosted tool cache](#hosted-tool-cache) - [Using `setup-python` with a self hosted runner](#using-setup-python-with-a-self-hosted-runner) - [Windows](#windows) - [Linux](#linux) @@ -354,10 +354,10 @@ Such a requirement on side-effect could be because you don't want your composite `setup-python` is able to configure **Python** from two sources: -- Preinstalled versions of Python in the toolcache on GitHub-hosted runners. +- Preinstalled versions of Python in the tool cache on GitHub-hosted runners. - For detailed information regarding the available versions of Python that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software). - For every minor version of Python, expect only the latest patch to be preinstalled. - - If `3.8.1` is installed for example, and `3.8.2` is released, expect `3.8.1` to be removed and replaced by `3.8.2` in the tools cache. + - If `3.8.1` is installed for example, and `3.8.2` is released, expect `3.8.1` to be removed and replaced by `3.8.2` in the tool cache. - If the exact patch version doesn't matter to you, specifying just the major and minor version will get you the latest preinstalled patch version. In the previous example, the version spec `3.8` will use the `3.8.2` Python version found in the cache. - Use `-dev` instead of a patch number (e.g., `3.11-dev`) to install the latest patch version release for a given minor version, *alpha and beta releases included*. - Downloadable Python versions from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)). @@ -370,7 +370,7 @@ Such a requirement on side-effect could be because you don't want your composite `setup-python` is able to configure **PyPy** from two sources: -- Preinstalled versions of PyPy in the tools cache on GitHub-hosted runners +- Preinstalled versions of PyPy in the tool cache on GitHub-hosted runners - For detailed information regarding the available versions of PyPy that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software). - For the latest PyPy release, all versions of Python are cached. - Cache is updated with a 1-2 week delay. If you specify the PyPy version as `pypy3.7` or `pypy-3.7`, the cached version will be used although a newer version is available. If you need to start using the recently released version right after release, you should specify the exact PyPy version using `pypy3.7-v7.3.3` or `pypy-3.7-v7.3.3`. @@ -380,15 +380,15 @@ Such a requirement on side-effect could be because you don't want your composite - PyPy < 7.3.3 are not available to install on-flight. - If some versions are not available, you can open an issue in https://foss.heptapod.net/pypy/pypy/ -# Hosted Tool Cache +# Hosted tool cache -GitHub hosted runners have a tool cache that comes with a few versions of Python + PyPy already installed. This tool cache helps speed up runs and tool setup by not requiring any new downloads. There is an environment variable called `RUNNER_TOOL_CACHE` on each runner that describes the location of this tools cache and there is where you will find Python and PyPy installed. `setup-python` works by taking a specific version of Python or PyPy in this tools cache and adding it to PATH. +GitHub hosted runners have a tool cache that comes with a few versions of Python + PyPy already installed. This tool cache helps speed up runs and tool setup by not requiring any new downloads. There is an environment variable called `RUNNER_TOOL_CACHE` on each runner that describes the location of this tool cache and there is where you will find Python and PyPy installed. `setup-python` works by taking a specific version of Python or PyPy in this tool cache and adding it to PATH. || Location | |------|-------| -|**Tool Cache Directory** |`RUNNER_TOOL_CACHE`| -|**Python Tool Cache**|`RUNNER_TOOL_CACHE/Python/*`| -|**PyPy Tool Cache**|`RUNNER_TOOL_CACHE/PyPy/*`| +|**Tool cache Directory** |`RUNNER_TOOL_CACHE`| +|**Python tool cache**|`RUNNER_TOOL_CACHE/Python/*`| +|**PyPy tool cache**|`RUNNER_TOOL_CACHE/PyPy/*`| GitHub virtual environments are set up in [actions/virtual-environments](https://github.com/actions/virtual-environments). During the setup, the available versions of Python and PyPy are automatically downloaded, set up and documented. - Tool cache setup for Ubuntu: [Install-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/Configure-Toolset.ps1) From 746f28a2d3a31986ee65499d2e8b626b2e14fe29 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Wed, 13 Jul 2022 11:15:35 +0200 Subject: [PATCH 03/25] Update REAMDE.md and advanced-usage.md --- README.md | 15 +++++++++-- docs/advanced-usage.md | 61 ++++++++++++++++++++++++++---------------- 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 4d8d55a68..da0dd304d 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ This action provides the following functionality for GitHub Actions users: See [action.yml](action.yml) +**Python** ```yaml steps: - uses: actions/checkout@v3 @@ -32,6 +33,16 @@ steps: python-version: '3.10' - run: python my_script.py ``` + +**PyPy** +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 + with: + python-version: 'pypy3.7' +- run: python my_script.py +``` The `python-version` input is optional. If not supplied, the Python/PyPy version from the PATH will be used. The default version of Python/PyPy in PATH vary between runners and can be changed unexpectedly so we recommend always use `setup-python`. The action will first check the local [tool cache](docs/advanced-usage.md#hosted-tool-cache) for a [semver](https://github.com/npm/node-semver#versions) match. If unable to find a specific version in the tool cache, the action will attempt to download a version of Python from [GitHub Releases](https://github.com/actions/python-versions/releases) and for PyPy from the official [PyPy's dist](https://downloads.python.org/pypy/). @@ -40,11 +51,11 @@ For information regarding locally cached versions of Python/PyPy on GitHub hoste ## Supported version syntax -The `python-version` input supports the [Semantic Versioning Specification](https://github.com/npm/node-semver#versions) and some special version notations (e.g. `x.y-dev`), for detailed examples please refer to the section: [Using python-version input](docs/advanced-usage.md#using-python-version-input) of the [Advanced usage](docs/advanced-usage.md) guide. +The `python-version` input supports the [Semantic Versioning Specification](https://semver.org/) and some special version notations (e.g. `semver ranges`, `x.y-dev syntax`, etc), for detailed examples please refer to the section: [Using python-version input](docs/advanced-usage.md#using-python-version-input) of the [Advanced usage](docs/advanced-usage.md) guide. ## Supported architectures -Using `architecture` input it's possible to specify required python's interpreter architecture: `x86` or `x64`. If input is not specified it defaults to `x64`. +Using `architecture` input it's possible to specify required python's interpreter architecture: `x86` or `x64`. If input is not specified the architecture defaults to `x64`. ## Caching packages dependencies diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 9c2d20c24..a1944d474 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -36,7 +36,7 @@ steps: - The only downside to this is that set up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. - MSI installers are used on Windows for this, so runs will take a little longer to set up vs MacOS and Linux. -You should specify **only a major and minor version** if you are okay with the most recent patch version being used: +You can specify **only a major and minor version** if you are okay with the most recent patch version being used: ```yaml steps: @@ -72,7 +72,7 @@ steps: - run: python my_script.py ``` -You can also use several types of ranges that are specified in [Semantic Versioning Specification](https://github.com/npm/node-semver#ranges), for instance: +You can also use several types of ranges that are specified in [semver](https://github.com/npm/node-semver#ranges), for instance: - **[hyphen ranges](https://github.com/npm/node-semver#hyphen-ranges-xyz---abc)** to download and set up the latest available version of Python (includes both pre-release and stable versions): @@ -95,14 +95,13 @@ steps: python-version: '3.x' - run: python my_script.py ``` -Please refer to the [Advanced range syntax section](https://github.com/npm/node-semver#advanced-range-syntax) of the [Semantic Versioning Specification](https://github.com/npm/node-semver) to check other available range syntaxes. +Please refer to the [Advanced range syntax section](https://github.com/npm/node-semver#advanced-range-syntax) of the [semver](https://github.com/npm/node-semver) to check other available range syntaxes. ## Specifying a PyPy version The version of PyPy should be specified in the format `pypy[-v]` or `pypy-[-v]`. The `-v` parameter is optional and can be skipped. The latest PyPy version will be used in this case. ``` -pypy3.7 or pypy-3.7 # the latest available version of PyPy that supports Python 3.7 pypy3.8 or pypy-3.8 # the latest available version of PyPy that supports Python 3.8 pypy2.7 or pypy-2.7 # the latest available version of PyPy that supports Python 2.7 pypy3.7-v7.3.3 or pypy-3.7-v7.3.3 # Python 3.7 and PyPy 7.3.3 @@ -122,7 +121,6 @@ jobs: python-version: - 'pypy3.7' # the latest available version of PyPy that supports Python 3.7 - 'pypy3.7-v7.3.3' # Python 3.7 and PyPy 7.3.3 - - 'pypy3.8' # the latest available version of PyPy that supports Python 3.8 steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 @@ -130,7 +128,7 @@ jobs: python-version: ${{ matrix.python-version }} - run: python my_script.py ``` -More details on PyPy syntax and examples of using preview / nightly versions of PyPy can be found in the [Available versions of PyPy](#pypy) section. +More details on PyPy syntax can be found in the [Available versions of PyPy](#pypy) section. ## Matrix Testing @@ -239,17 +237,6 @@ steps: - run: poetry install - run: poetry run pytest ``` -**Using wildcard patterns to cache dependencies** -```yaml -steps: -- uses: actions/checkout@v3 -- uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pip' - cache-dependency-path: '**/requirements-dev.txt' -- run: pip install -r subdirectory/requirements-dev.txt -``` **Using a list of file paths to cache dependencies** ```yaml @@ -266,6 +253,17 @@ steps: run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python - run: pipenv install ``` +**Using wildcard patterns to cache dependencies** +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + cache-dependency-path: '**/requirements-dev.txt' +- run: pip install -r subdirectory/requirements-dev.txt +``` **Using a list of wildcard patterns to cache dependencies** ```yaml @@ -287,7 +285,7 @@ steps: ### `python-version` -Using **python-version** output it's possible to get the installed by action python's version. This output is useful when the input `python-version` given as a range (e.g. 3.8.0 - 3.10.0 ), but down in a workflow you need to operate with exact installed version (e.g. 3.10.1). +Using **python-version** output it's possible to get the installed by action Pytho/PyPy version. This output is useful when the input `python-version` given as a range (e.g. 3.8.0 - 3.10.0 ), but down in a workflow you need to operate with the exact installed version (e.g. 3.10.1). ```yaml jobs: @@ -304,7 +302,7 @@ jobs: ### `python-path` -**python-path** output is available with the absolute path of the python interpreter executable if you need it: +**python-path** output is available with the absolute path of the Python/PyPy interpreter executable if you need it: ```yaml jobs: @@ -318,12 +316,29 @@ jobs: python-version: "3.10" - run: pipx run --python '${{ steps.cp310.outputs.python-path }}' nox --version ``` +### `cache-hit` + +**cache-hit** output is available with a boolean value that indicates whether a cache hit occured on the primary key: + +``` +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + id: cp310 + with: + python-version: "3.8.0" + cache: "poetry" + - run: echo '${{ steps.cp310.outputs.cache-hit }}' # true if cache-hit occured on the primary key +``` ## Evironment variables These environment variables become available after setup-python action execution: -| Env.Variable | Description | +| **Env.variable** | **Description** | | ----------- | ----------- | | pythonLocation |Contains the absolute path to the folder where the requested version of Python or PyPy is installed| | Python_ROOT_DIR | https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython | @@ -333,10 +348,10 @@ These environment variables become available after setup-python action execution ## Using `update-environment` flag The `update-environment` flag defaults to `true`. -With this setting, the action will add/update environment variables (e.g. `PATH`, `PKG_CONFIG_PATH`, `pythonLocation`) for `python` to just work out of the box. +With this setting, the action will add/update environment variables (e.g. `PATH`, `PKG_CONFIG_PATH`, `pythonLocation`) for Python/PyPy to just work out of the box. If `update-environment` is set to `false`, the action will not add/update environment variables. -This can prove useful if you want the only side-effect to be to ensure python is installed and rely on the `python-path` output to run python. +This can prove useful if you want the only side-effect to be to ensure Python/PyPy is installed and rely on the `python-path` output to run executable. Such a requirement on side-effect could be because you don't want your composite action messing with your user's workflows. ```yaml @@ -382,7 +397,7 @@ Such a requirement on side-effect could be because you don't want your composite # Hosted tool cache -GitHub hosted runners have a tool cache that comes with a few versions of Python + PyPy already installed. This tool cache helps speed up runs and tool setup by not requiring any new downloads. There is an environment variable called `RUNNER_TOOL_CACHE` on each runner that describes the location of this tool cache and there is where you will find Python and PyPy installed. `setup-python` works by taking a specific version of Python or PyPy in this tool cache and adding it to PATH. +GitHub hosted runners have a tool cache that comes with a few versions of Python + PyPy already installed. This tool cache helps speed up runs and tool setup by not requiring any new downloads. There is an environment variable called `RUNNER_TOOL_CACHE` on each runner that describes the location of the tool cache with Python and PyPy installed. `setup-python` works by taking a specific version of Python or PyPy from this tool cache and adding it to PATH. || Location | |------|-------| From 09086ccd4627c1947935882314572a89b021ab31 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Wed, 13 Jul 2022 11:27:41 +0200 Subject: [PATCH 04/25] Update action.yml file --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index de2a4febc..9810aeb79 100644 --- a/action.yml +++ b/action.yml @@ -4,7 +4,7 @@ description: 'Set up a specific version of Python and add the command-line tools author: 'GitHub' inputs: python-version: - description: "Version range or exact version of Python to use, using SemVer's version range syntax. Reads from .python-version if unset." + description: "Version range or exact version of Python to use, using SemVer's version range syntax." python-version-file: description: "File containing the Python version to use. Example: .python-version" cache: @@ -22,7 +22,7 @@ inputs: default: true outputs: python-version: - description: "The installed python version. Useful when given a version range as input." + description: "The installed Python version. Useful when given a version range as input." cache-hit: description: 'A boolean value to indicate a cache entry was found' python-path: From 61fb4e42abc1a8d063ecad4c918c01937dd9aa7c Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Wed, 13 Jul 2022 12:17:04 +0200 Subject: [PATCH 05/25] Fix review points --- README.md | 14 ++------------ action.yml | 12 ++++++------ docs/advanced-usage.md | 2 +- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index da0dd304d..44da1fb28 100644 --- a/README.md +++ b/README.md @@ -10,16 +10,6 @@ This action provides the following functionality for GitHub Actions users: - Optionally caching dependencies for pip, pipenv and poetry - Registering problem matchers for error output -## Table of contents - -- [Basic usage](#basic-usage) -- [Supported version syntax](#supported-version-syntax) -- [Supported architectures](#supported-architectures) -- [Caching packages dependencies](#caching-packages-dependencies) -- [Advanced usage](#advanced-usage) -- [License](#license) -- [Contributions](#contributions) - ## Basic usage See [action.yml](action.yml) @@ -40,7 +30,7 @@ steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: 'pypy3.7' + python-version: 'pypy3.9' - run: python my_script.py ``` The `python-version` input is optional. If not supplied, the Python/PyPy version from the PATH will be used. The default version of Python/PyPy in PATH vary between runners and can be changed unexpectedly so we recommend always use `setup-python`. @@ -51,7 +41,7 @@ For information regarding locally cached versions of Python/PyPy on GitHub hoste ## Supported version syntax -The `python-version` input supports the [Semantic Versioning Specification](https://semver.org/) and some special version notations (e.g. `semver ranges`, `x.y-dev syntax`, etc), for detailed examples please refer to the section: [Using python-version input](docs/advanced-usage.md#using-python-version-input) of the [Advanced usage](docs/advanced-usage.md) guide. +The `python-version` input supports the [Semantic Versioning Specification](https://semver.org/) and some special version notations (e.g. `semver ranges`, `x.y-dev syntax`, etc.), for detailed examples please refer to the section: [Using python-version input](docs/advanced-usage.md#using-python-version-input) of the [Advanced usage](docs/advanced-usage.md) guide. ## Supported architectures diff --git a/action.yml b/action.yml index 9810aeb79..e0f2ba1b1 100644 --- a/action.yml +++ b/action.yml @@ -4,16 +4,16 @@ description: 'Set up a specific version of Python and add the command-line tools author: 'GitHub' inputs: python-version: - description: "Version range or exact version of Python to use, using SemVer's version range syntax." + description: 'Version range or exact version of Python/PyPy to use, using SemVer's version range syntax.' 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' cache: description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry.' required: false architecture: - description: 'The target architecture (x86, x64) of the Python interpreter.' + description: 'The target architecture (x86, x64) of the Python/PyPy interpreter.' token: - description: Used to pull python distributions from actions/python-versions. Since there's a default, this is typically not supplied by the user. + description: 'Used to pull python distributions from actions/python-versions. Since there's a default, this is typically not supplied by the user.' default: ${{ github.token }} cache-dependency-path: description: 'Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies.' @@ -22,11 +22,11 @@ inputs: default: true outputs: python-version: - description: "The installed Python version. Useful when given a version range as input." + description: 'The installed Python/PyPy version. Useful when given a version range as input.' cache-hit: description: 'A boolean value to indicate a cache entry was found' python-path: - description: "The absolute path to the Python executable." + description: 'The absolute path to the Python/PyPy executable.' runs: using: 'node16' main: 'dist/setup/index.js' diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index a1944d474..69a303ce4 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -285,7 +285,7 @@ steps: ### `python-version` -Using **python-version** output it's possible to get the installed by action Pytho/PyPy version. This output is useful when the input `python-version` given as a range (e.g. 3.8.0 - 3.10.0 ), but down in a workflow you need to operate with the exact installed version (e.g. 3.10.1). +Using **python-version** output it's possible to get the installed by action Python/PyPy version. This output is useful when the input `python-version` given as a range (e.g. 3.8.0 - 3.10.0 ), but down in a workflow you need to operate with the exact installed version (e.g. 3.10.1). ```yaml jobs: From 386e4eaaedc52f72c24a57219575a72956958c4c Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Wed, 13 Jul 2022 13:34:22 +0200 Subject: [PATCH 06/25] Fix review points --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 44da1fb28..8710b8f67 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ GitHub Actions status

-This action provides the following functionality for GitHub Actions users: +This action provides the following functionalities for GitHub Actions users: - Optionally downloading and installing the requested version of Python/PyPy and adding it to the PATH - Optionally caching dependencies for pip, pipenv and poetry @@ -45,7 +45,7 @@ The `python-version` input supports the [Semantic Versioning Specification](http ## Supported architectures -Using `architecture` input it's possible to specify required python's interpreter architecture: `x86` or `x64`. If input is not specified the architecture defaults to `x64`. +Using `architecture` input it is possible to specify required Python/PyPy interpreter architecture: `x86` or `x64`. If input is not specified the architecture defaults to `x64`. ## Caching packages dependencies From 799afeb7961a4c779201d81d65b3b751b191a021 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Wed, 13 Jul 2022 13:43:28 +0200 Subject: [PATCH 07/25] Fix action.yml file --- action.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index e0f2ba1b1..f767b428e 100644 --- a/action.yml +++ b/action.yml @@ -4,16 +4,19 @@ description: 'Set up a specific version of Python and add the command-line tools author: 'GitHub' inputs: python-version: - description: 'Version range or exact version of Python/PyPy to use, using SemVer's version range syntax.' + description: "Version range or exact version of Python/PyPy to use, using SemVer's version range syntax." 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" cache: description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry.' required: false architecture: - description: 'The target architecture (x86, x64) of the Python/PyPy interpreter.' + description: "The target architecture (x86, x64) of the Python/PyPy interpreter." + check-latest: + description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec.' + default: false token: - description: 'Used to pull python distributions from actions/python-versions. Since there's a default, this is typically not supplied by the user.' + description: "Used to pull python distributions from actions/python-versions. Since there's a default, this is typically not supplied by the user." default: ${{ github.token }} cache-dependency-path: description: 'Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies.' @@ -22,11 +25,11 @@ inputs: default: true outputs: python-version: - description: 'The installed Python/PyPy version. Useful when given a version range as input.' + description: "The installed Python/PyPy version. Useful when given a version range as input." cache-hit: description: 'A boolean value to indicate a cache entry was found' python-path: - description: 'The absolute path to the Python/PyPy executable.' + description: "The absolute path to the Python/PyPy executable." runs: using: 'node16' main: 'dist/setup/index.js' From 5517d5f7b547a5c566879ca95b0f57267f3641a3 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Mon, 18 Jul 2022 14:33:42 +0200 Subject: [PATCH 08/25] Fix documentation Docs were updated to incorporate changes regarding tool cache folder on the self-hosted runner and changes in resolveVersionInput() --- README.md | 2 +- docs/advanced-usage.md | 29 +++-------------------------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 8710b8f67..56cfaa0cf 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ steps: python-version: 'pypy3.9' - run: python my_script.py ``` -The `python-version` input is optional. If not supplied, the Python/PyPy version from the PATH will be used. The default version of Python/PyPy in PATH vary between runners and can be changed unexpectedly so we recommend always use `setup-python`. +The `python-version` input is optional. If not supplied, the action will try to resolve version from the default `.python-version` file. If `.python-version` file doesn't exist Python/PyPy version from the PATH will be used. The default version of Python/PyPy in PATH vary between runners and can be changed unexpectedly so we recommend always use `setup-python`. The action will first check the local [tool cache](docs/advanced-usage.md#hosted-tool-cache) for a [semver](https://github.com/npm/node-semver#versions) match. If unable to find a specific version in the tool cache, the action will attempt to download a version of Python from [GitHub Releases](https://github.com/actions/python-versions/releases) and for PyPy from the official [PyPy's dist](https://downloads.python.org/pypy/). diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 69a303ce4..407d02545 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -179,7 +179,7 @@ jobs: # Using python-version-file input -`setup-python` action has ability to read Python/PyPy version from a version file. `python-version-file` input is used for specifying path to the version file. If version file at the specified path doesn't exist action will try to find `.python-version` file implying that it as a default type of version files. If `.python-version` file doesn't exist also, action will fail with error. +`setup-python` action has ability to read Python/PyPy version from a version file. `python-version-file` input is used for specifying path to the version file. If `.python-version` file doesn't exist, action will fail with error. >In case both `python-version` and `python-version-file` inputs are supplied, `python-version-file` input will be ignored due to its lower priority. @@ -414,9 +414,7 @@ GitHub virtual environments are set up in [actions/virtual-environments](https:/ Python distributions are only available for the same [environments](https://github.com/actions/virtual-environments#available-environments) that GitHub Actions hosted environments are available for. If you are using an unsupported version of Ubuntu such as `19.04` or another Linux distribution such as Fedora, `setup-python` will not work. If you have a supported self-hosted runner and you would like to use `setup-python`, there are a few extra things you need to make sure are set up so that new versions of Python can be downloaded and configured on your runner. -If you are experiencing problems while configuring Python on your self-hosted runner, turn on [step debugging](https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs) to see addition logs. - -### Windows +## Windows requirements - Your runner needs to be running with administrator privileges so that the appropriate directories and files can be set up when downloading and installing a new version of Python for the first time. - If your runner is configured as a service, make sure the account that is running the service has the appropriate write permissions so that Python can get installed. The default `NT AUTHORITY\NETWORK SERVICE` should be sufficient. @@ -424,28 +422,7 @@ If you are experiencing problems while configuring Python on your self-hosted ru - MSI installers are used when setting up Python on Windows. A word of caution as MSI installers update registry settings. - The 3.8 MSI installer for Windows will not let you install another 3.8 version of Python. If `setup-python` fails for a 3.8 version of Python, make sure any previously installed versions are removed by going to "Apps & Features" in the Settings app. -### Linux - -- The Python packages that are downloaded from `actions/python-versions` are originally compiled from source in `/opt/hostedtoolcache/` with the [--enable-shared](https://github.com/actions/python-versions/blob/94f04ae6806c6633c82db94c6406a16e17decd5c/builders/ubuntu-python-builder.psm1#L35) flag, which makes them non-relocatable. -- By default runner downloads and install the tools to `/opt/hostedtoolcache`. The environment variable called `AGENT_TOOLSDIRECTORY` can be set to change this location. - - In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`. - - A more permanent way of setting the environment variable is to create a `.env` file in the same directory as your runner and to add `AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`. This ensures the variable is always set if your runner is configured as a service. -- Create a directory called `hostedtoolcache` inside `/opt`. -- The user starting the runner must have write permission to the `/opt/hostedtoolcache` directory. It is not possible to start the Linux runner with `sudo` and the `/opt` directory usually requires root privileges to write to. Check the current user and group that the runner belongs to by typing `ls -l` inside the runners root directory. -- The runner can be granted write access to the `/opt/hostedtoolcache` directory using a few techniques: - - The user starting the runner is the owner, and the owner has write permission. - - The user starting the runner is in the owning group, and the owning group has write permission. - - All users have write permission. -- One quick way to grant access is to change the user and group of `/opt/hostedtoolcache` to be the same as the runners using `chown`. - - `sudo chown runner-user:runner-group /opt/hostedtoolcache/`. -- If your runner is configured as a service and you run into problems, make sure the user that the service is running as is correct. For more information, you can [check the status of your self-hosted runner](https://help.github.com/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service#checking-the-status-of-the-service). - -### MacOS - -- The same setup that applies to `Linux` also applies to `MacOS`, just with a different tools cache directory. -- Create a directory called `/Users/runner/hostedtoolcache`. -- Set the `AGENT_TOOLSDIRECTORY` environment variable to `/Users/runner/hostedtoolcache`. -- Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access. +>If you are experiencing problems while configuring Python on your self-hosted runner, turn on [step debugging](https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs) to see addition logs. # Using `setup-python` on GHES From 00d9c42868d28c68834181199e779da29bb4f198 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Mon, 25 Jul 2022 19:42:15 +0200 Subject: [PATCH 09/25] Change part with realted to self-hosted runners --- docs/advanced-usage.md | 47 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 407d02545..88761e7bd 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -412,9 +412,12 @@ GitHub virtual environments are set up in [actions/virtual-environments](https:/ # Using `setup-python` with a self hosted runner -Python distributions are only available for the same [environments](https://github.com/actions/virtual-environments#available-environments) that GitHub Actions hosted environments are available for. If you are using an unsupported version of Ubuntu such as `19.04` or another Linux distribution such as Fedora, `setup-python` will not work. If you have a supported self-hosted runner and you would like to use `setup-python`, there are a few extra things you need to make sure are set up so that new versions of Python can be downloaded and configured on your runner. +Python distributions are only available for the same [environments](https://github.com/actions/virtual-environments#available-environments) that GitHub Actions hosted environments are available for. If you are using an unsupported version of Ubuntu such as `19.04` or another Linux distribution such as Fedora, `setup-python` may not work. -## Windows requirements +If you have a supported self-hosted runner and you would like to use `setup-python`, there are a few extra things you need to make sure are set up so that new versions of Python can be downloaded and configured on your runner. + + +## Windows - Your runner needs to be running with administrator privileges so that the appropriate directories and files can be set up when downloading and installing a new version of Python for the first time. - If your runner is configured as a service, make sure the account that is running the service has the appropriate write permissions so that Python can get installed. The default `NT AUTHORITY\NETWORK SERVICE` should be sufficient. @@ -422,8 +425,48 @@ Python distributions are only available for the same [environments](https://gith - MSI installers are used when setting up Python on Windows. A word of caution as MSI installers update registry settings. - The 3.8 MSI installer for Windows will not let you install another 3.8 version of Python. If `setup-python` fails for a 3.8 version of Python, make sure any previously installed versions are removed by going to "Apps & Features" in the Settings app. +> By default runner downloads and installs tools into the folder set up by `RUNNER_TOOL_CACHE` environment variable. The environment variable called `AGENT_TOOLSDIRECTORY` can be set to change this location for Windows self-hosted runners. + >If you are experiencing problems while configuring Python on your self-hosted runner, turn on [step debugging](https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs) to see addition logs. +## Linux + +By default runner downloads and installs tools into the folder set up by `RUNNER_TOOL_CACHE` environment variable. The environment variable called `AGENT_TOOLSDIRECTORY` can be set to change this location for Linux self-hosted runners: +- In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/path/to/folder`. +- More permanent way of setting the environment variable is to create an `.env` file in the same directory as your runner and to add `AGENT_TOOLSDIRECTORY=/path/to/folder`. This ensures the variable is always set if your runner is configured as a service. + +If you're using non-default tool cache directory be sure that the user starting the runner have write permission to the new tool cache directory folder. To check the current user and group that the runner belongs type `ls -l` inside the runners root directory. + +The runner can be granted write access to any directory using a few techniques: +- The user starting the runner is the owner, and the owner has write permission. +- The user starting the runner is in the owning group, and the owning group has write permission. +- All users have write permission. +One quick way to grant access is to change the user and group of the non-default tool cache folder to be the same as the runners using `chown`: +`sudo chown runner-user:runner-group /path/to/folder`. + + +> If your runner is configured as a service and you run into problems, make sure the user that the service is running as is correct. For more information, you can [check the status of your self-hosted runner](https://docs.github.com/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service#checking-the-status-of-the-service). + + +## MacOS + + The Python packages for MacOS that are downloaded from `actions/python-versions` are originally compiled from source in `/Users/runner/hostedtoolcache`. Due to the fixed shared library path, these Python packages are non-relocatable and require to be installed only in `/Users/runner/hostedtoolcache`. Before use of `setup-python` on the MacOS self-hosted runner: + + - Create a directory called `/Users/runner/hostedtoolcache` + - Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access. + +You can check the current user and group that the runner belongs to by typing `ls -l` inside the runners root directory. +The runner can be granted write access to the `/Users/runner/hostedtoolcache` directory using a few techniques: + - The user starting the runner is the owner, and the owner has write permission. + - The user starting the runner is in the owning group, and the owning group has write permission. + - All users have write permission. +One quick way to grant access is to change the user and group of `/Users/runner/hostedtoolcache` to be the same as the runners using `chown`: +`sudo chown runner-user:runner-group /Users/runner/hostedtoolcache` + +> If your runner is configured as a service and you run into problems, make sure the user that the service is running as is correct. For more information, you can [check the status of your self-hosted runner](https://docs.github.com/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service#checking-the-status-of-the-service). + + + # Using `setup-python` on GHES `setup-python` comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading Python distributions, `setup-python` downloads distributions from [`actions/python-versions`](https://github.com/actions/python-versions) on github.com (outside of the appliance). These calls to `actions/python-versions` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting). If more requests are made within the time frame, then you will start to see rate-limit errors during download that read `##[error]API rate limit exceeded for...`. From 889226ae9a8f3aff0dbe4fc78e012072257c3363 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Mon, 25 Jul 2022 19:44:22 +0200 Subject: [PATCH 10/25] Fix typo --- docs/advanced-usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 88761e7bd..0a1a2ac86 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -435,7 +435,7 @@ By default runner downloads and installs tools into the folder set up by `RUNNER - In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/path/to/folder`. - More permanent way of setting the environment variable is to create an `.env` file in the same directory as your runner and to add `AGENT_TOOLSDIRECTORY=/path/to/folder`. This ensures the variable is always set if your runner is configured as a service. -If you're using non-default tool cache directory be sure that the user starting the runner have write permission to the new tool cache directory folder. To check the current user and group that the runner belongs type `ls -l` inside the runners root directory. +If you're using non-default tool cache directory be sure that the user starting the runner have write permission to the new tool cache directory. To check the current user and group that the runner belongs type `ls -l` inside the runners root directory. The runner can be granted write access to any directory using a few techniques: - The user starting the runner is the owner, and the owner has write permission. From 0d94a5d71eff739dcec5c2cfed04f676b65f98a3 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 26 Jul 2022 10:47:51 +0200 Subject: [PATCH 11/25] Fix typo --- docs/advanced-usage.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 0a1a2ac86..e3f654375 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -453,12 +453,12 @@ One quick way to grant access is to change the user and group of the non-default The Python packages for MacOS that are downloaded from `actions/python-versions` are originally compiled from source in `/Users/runner/hostedtoolcache`. Due to the fixed shared library path, these Python packages are non-relocatable and require to be installed only in `/Users/runner/hostedtoolcache`. Before use of `setup-python` on the MacOS self-hosted runner: - Create a directory called `/Users/runner/hostedtoolcache` - - Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access. + - Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access You can check the current user and group that the runner belongs to by typing `ls -l` inside the runners root directory. The runner can be granted write access to the `/Users/runner/hostedtoolcache` directory using a few techniques: - - The user starting the runner is the owner, and the owner has write permission. - - The user starting the runner is in the owning group, and the owning group has write permission. + - The user starting the runner is the owner, and the owner has write permission + - The user starting the runner is in the owning group, and the owning group has write permission - All users have write permission. One quick way to grant access is to change the user and group of `/Users/runner/hostedtoolcache` to be the same as the runners using `chown`: `sudo chown runner-user:runner-group /Users/runner/hostedtoolcache` From b2241a475486883b8fbe47e9d23b0b1d6d7ad13b Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 26 Jul 2022 11:01:07 +0200 Subject: [PATCH 12/25] Change yml and rebuild action --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f767b428e..f6ff15c43 100644 --- a/action.yml +++ b/action.yml @@ -4,7 +4,7 @@ description: 'Set up a specific version of Python and add the command-line tools author: 'GitHub' inputs: python-version: - description: "Version range or exact version of Python/PyPy to use, using SemVer's version range syntax." + description: "Version range or exact version of Python/PyPy to use, using SemVer's version range syntax. Reads from .python-version if unset." python-version-file: description: "File containing the Python version to use. Example: .python-version" cache: From dd40245e5b4588f5f14a3cebdf97bdc02489ed4d Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 26 Jul 2022 11:06:43 +0200 Subject: [PATCH 13/25] Fix merge artifacts --- README.md | 144 ----------------------------------------------------- action.yml | 4 -- 2 files changed, 148 deletions(-) diff --git a/README.md b/README.md index 43ba10aa4..56cfaa0cf 100644 --- a/README.md +++ b/README.md @@ -47,151 +47,7 @@ The `python-version` input supports the [Semantic Versioning Specification](http Using `architecture` input it is possible to specify required Python/PyPy interpreter architecture: `x86` or `x64`. If input is not specified the architecture defaults to `x64`. -<<<<<<< HEAD ## Caching packages dependencies -======= -Download and set up the latest stable version of Python (for specified major version): -```yaml -steps: -- uses: actions/checkout@v3 -- uses: actions/setup-python@v4 - with: - python-version: '3.x' -- run: python my_script.py -``` - -Download and set up PyPy: - -```yaml -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: - - 'pypy3.7' # the latest available version of PyPy that supports Python 3.7 - - 'pypy3.7-v7.3.3' # Python 3.7 and PyPy 7.3.3 - - 'pypy3.8' # the latest available version of PyPy that supports Python 3.8 - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - run: python my_script.py -``` -More details on PyPy syntax and examples of using preview / nightly versions of PyPy can be found in the [Available versions of PyPy](#available-versions-of-pypy) section. - -An output is available with the absolute path of the python interpreter executable if you need it: -```yaml -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - id: cp310 - with: - python-version: "3.10" - - run: pipx run --python '${{ steps.cp310.outputs.python-path }}' nox --version -``` - ->The environment variable `pythonLocation` also becomes available after Python or PyPy installation. It contains the absolute path to the folder where the desired version of Python or PyPy is installed. - -# Getting started with Python + Actions - -Check out our detailed guide on using [Python with GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-python-with-github-actions). - -# Available versions of Python - -`setup-python` is able to configure Python from two sources: - -- Preinstalled versions of Python in the tools cache on GitHub-hosted runners. - - For detailed information regarding the available versions of Python that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software). - - For every minor version of Python, expect only the latest patch to be preinstalled. - - If `3.8.1` is installed for example, and `3.8.2` is released, expect `3.8.1` to be removed and replaced by `3.8.2` in the tools cache. - - If the exact patch version doesn't matter to you, specifying just the major and minor version will get you the latest preinstalled patch version. In the previous example, the version spec `3.8` will use the `3.8.2` Python version found in the cache. - - Use `-dev` instead of a patch number (e.g., `3.11-dev`) to install the latest patch version release for a given minor version, *alpha and beta releases included*. -- Downloadable Python versions from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)). - - All available versions are listed in the [version-manifest.json](https://github.com/actions/python-versions/blob/main/versions-manifest.json) file. - - If there is a specific version of Python that is not available, you can open an issue here - -**Note:** Python versions used in this action are generated in the [python-versions](https://github.com/actions/python-versions) repository. For macOS and Ubuntu images python versions are built from the source code. For Windows the python-versions repository uses installation executable. For more information please refer to the [python-versions](https://github.com/actions/python-versions) repository. - - # Available versions of PyPy - - `setup-python` is able to configure PyPy from two sources: - -- Preinstalled versions of PyPy in the tools cache on GitHub-hosted runners - - For detailed information regarding the available versions of PyPy that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software). - - For the latest PyPy release, all versions of Python are cached. - - Cache is updated with a 1-2 week delay. If you specify the PyPy version as `pypy3.7` or `pypy-3.7`, the cached version will be used although a newer version is available. If you need to start using the recently released version right after release, you should specify the exact PyPy version using `pypy3.7-v7.3.3` or `pypy-3.7-v7.3.3`. - -- Downloadable PyPy versions from the [official PyPy site](https://downloads.python.org/pypy/). - - All available versions that we can download are listed in [versions.json](https://downloads.python.org/pypy/versions.json) file. - - PyPy < 7.3.3 are not available to install on-flight. - - If some versions are not available, you can open an issue in https://foss.heptapod.net/pypy/pypy/ - -# Hosted Tool Cache - -GitHub hosted runners have a tools cache that comes with a few versions of Python + PyPy already installed. This tools cache helps speed up runs and tool setup by not requiring any new downloads. There is an environment variable called `RUNNER_TOOL_CACHE` on each runner that describes the location of this tools cache and there is where you will find Python and PyPy installed. `setup-python` works by taking a specific version of Python or PyPy in this tools cache and adding it to PATH. - -|| Location | -|------|-------| -|**Tool Cache Directory** |`RUNNER_TOOL_CACHE`| -|**Python Tool Cache**|`RUNNER_TOOL_CACHE/Python/*`| -|**PyPy Tool Cache**|`RUNNER_TOOL_CACHE/PyPy/*`| - -GitHub virtual environments are setup in [actions/virtual-environments](https://github.com/actions/virtual-environments). During the setup, the available versions of Python and PyPy are automatically downloaded, setup and documented. -- Tools cache setup for Ubuntu: [Install-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/Configure-Toolset.ps1) -- Tools cache setup for Windows: [Install-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Configure-Toolset.ps1) - -# Specifying a Python version - -If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the exact major, minor, and patch version (such as `3.7.5`) - - The only downside to this is that set up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. - - MSI installers are used on Windows for this, so runs will take a little longer to set up vs Mac and Linux. - -You should specify only a major and minor version if you are okay with the most recent patch version being used. - - There will be a single patch version already installed on each runner for every minor version of Python that is supported. - - The patch version that will be preinstalled, will generally be the latest and every time there is a new patch released, the older version that is preinstalled will be replaced. - - Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version Python on the runner will be used. - -# Specifying a PyPy version -The version of PyPy should be specified in the format `pypy[-v]` or `pypy-[-v]`. -The `` parameter is optional and can be skipped. The latest version will be used in this case. - -``` -pypy3.7 or pypy-3.7 # the latest available version of PyPy that supports Python 3.7 -pypy3.8 or pypy-3.8 # the latest available version of PyPy that supports Python 3.8 -pypy2.7 or pypy-2.7 # the latest available version of PyPy that supports Python 2.7 -pypy3.7-v7.3.3 or pypy-3.7-v7.3.3 # Python 3.7 and PyPy 7.3.3 -pypy3.7-v7.x or pypy-3.7-v7.x # Python 3.7 and the latest available PyPy 7.x -pypy3.7-v7.3.3rc1 or pypy-3.7-v7.3.3rc1 # Python 3.7 and preview version of PyPy -pypy3.7-nightly or pypy-3.7-nightly # Python 3.7 and nightly PyPy -``` - -Note: `pypy2` and `pypy3` have been removed in v3. Use the format above instead. - -# Check latest version - -The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific `Python/PyPy` version is always used. - -If `check-latest` is set to `true`, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, a `Python/PyPy` version will then be downloaded. Set `check-latest` to `true` if you want the most up-to-date `Python/PyPy` version to always be used. - -> Setting `check-latest` to `true` has performance implications as downloading `Python/PyPy` versions is slower than using cached versions. - -```yaml -steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 - with: - python-version: '3.7' - check-latest: true - - run: python my_script.py -``` - -# Caching packages dependencies ->>>>>>> main The action has built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood for caching dependencies but requires less configuration settings. Supported package managers are `pip`, `pipenv` and `poetry`. The `cache` input is optional, and caching is turned off by default. diff --git a/action.yml b/action.yml index fa687c314..f6ff15c43 100644 --- a/action.yml +++ b/action.yml @@ -11,11 +11,7 @@ inputs: description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry.' required: false architecture: -<<<<<<< HEAD description: "The target architecture (x86, x64) of the Python/PyPy interpreter." -======= - description: 'The target architecture (x86, x64) of the Python interpreter.' ->>>>>>> main check-latest: description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec.' default: false From a624f1f4bc2c35cc36a7efb4177fd0fd795b71b9 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 26 Jul 2022 11:32:45 +0200 Subject: [PATCH 14/25] Fix grammar in both documents --- README.md | 14 ++++----- docs/advanced-usage.md | 68 +++++++++++++++++++++--------------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 56cfaa0cf..841d82a70 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ steps: python-version: 'pypy3.9' - run: python my_script.py ``` -The `python-version` input is optional. If not supplied, the action will try to resolve version from the default `.python-version` file. If `.python-version` file doesn't exist Python/PyPy version from the PATH will be used. The default version of Python/PyPy in PATH vary between runners and can be changed unexpectedly so we recommend always use `setup-python`. +The `python-version` input is optional. If not supplied, the action will try to resolve the version from the default `.python-version` file. If the `.python-version` file doesn't exist Python/PyPy version from the PATH will be used. The default version of Python/PyPy in PATH varies between runners and can be changed unexpectedly so we recommend always using `setup-python`. The action will first check the local [tool cache](docs/advanced-usage.md#hosted-tool-cache) for a [semver](https://github.com/npm/node-semver#versions) match. If unable to find a specific version in the tool cache, the action will attempt to download a version of Python from [GitHub Releases](https://github.com/actions/python-versions/releases) and for PyPy from the official [PyPy's dist](https://downloads.python.org/pypy/). @@ -45,15 +45,15 @@ The `python-version` input supports the [Semantic Versioning Specification](http ## Supported architectures -Using `architecture` input it is possible to specify required Python/PyPy interpreter architecture: `x86` or `x64`. If input is not specified the architecture defaults to `x64`. +Using `architecture` input it is possible to specify the required Python/PyPy interpreter architecture: `x86` or `x64`. If the input is not specified the architecture defaults to `x64`. ## Caching packages dependencies The action has built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood for caching dependencies but requires less configuration settings. Supported package managers are `pip`, `pipenv` and `poetry`. The `cache` input is optional, and caching is turned off by default. -The action defaults to searching for a dependency file (`requirements.txt` for pip, `Pipfile.lock` for pipenv or `poetry.lock` for poetry) in the repository, and uses its hash as a part of the cache key. Input `cache-dependency-path` is used for cases when multiple dependency files are used, they are located in different subdirectories or different files for the hash want to be used. +The action defaults to searching for a dependency file (`requirements.txt` for pip, `Pipfile.lock` for pipenv or `poetry.lock` for poetry) in the repository, and uses its hash as a part of the cache key. Input `cache-dependency-path` is used for cases when multiple dependency files are used, they are located in different subdirectories or different files for the hash that want to be used. - - For `pip`, the action will cache global cache directory + - For `pip`, the action will cache the global cache directory - For `pipenv`, the action will cache virtualenv directory - For `poetry`, the action will cache virtualenv directory @@ -68,9 +68,9 @@ steps: cache: 'pip' # caching pip dependencies - run: pip install -r requirements.txt ``` ->**Note:** Restored cache will not be used if the requirements.txt file is not updated for a long time and a newer version of the dependency is available that can lead to an increase in total build time. +>**Note:** Restored cache will not be used if the requirements.txt file is not updated for a long time and a newer version of the dependency is available which can lead to an increase in total build time. ->The requirements file format allows to specify dependency versions using logical operators (for example chardet>=3.0.4) or specify dependencies without any versions. In this case the pip install -r requirements.txt command will always try to install the latest available package version. To be sure that the cache will be used, please stick to a specific dependency version and update it manually if necessary. +>The requirements file format allows for specifying dependency versions using logical operators (for example chardet>=3.0.4) or specifying dependencies without any versions. In this case the pip install -r requirements.txt command will always try to install the latest available package version. To be sure that the cache will be used, please stick to a specific dependency version and update it manually if necessary. See examples of using `cache` and `cache-dependency-path` for `pipenv` and `poetry` in the section: [Caching packages data](docs/advanced-usage.md#caching-packages-data) of the [Advanced usage](docs/advanced-usage.md) guide. @@ -83,7 +83,7 @@ See examples of using `cache` and `cache-dependency-path` for `pipenv` and `poet - [Environment variables and action's outputs](docs/advanced-usage.md#environment-variables-and-actions-outputs) - [Available versions of Python and PyPy](docs/advanced-usage.md#available-versions-of-python-and-pypy) - [Hosted tool cache](docs/advanced-usage.md#hosted-tool-cache) -- [Using `setup-python` with a self hosted runner](docs/advanced-usage.md#using-setup-python-with-a-self-hosted-runner) +- [Using `setup-python` with a self-hosted runner](docs/advanced-usage.md#using-setup-python-with-a-self-hosted-runner) - [Using `setup-python` on GHES](docs/advanced-usage.md#using-setup-python-on-ghes) ## License diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index e3f654375..4edb54953 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -1,21 +1,21 @@ # Table of contents -- [Using python-version input](#using-python-version-file-input) - - [Specifying a Python version](#specifying-a-python-version) - - [Specifying a PyPy version](#specifying-a-pypy-version) - - [Matrix Testing](#matrix-testing) -- [Using python-version-file input](#using-python-version-file-input) -- [Check latest version](#check-latest-version) -- [Caching packages data](#caching-packages-data) -- [Environment variables and action's outputs](#environment-variables-and-actions-outputs) -- [Available versions of Python and PyPy](#available-versions-of-python-and-pypy) - - [Python](#python) - - [PyPy](#pypy) -- [Hosted tool cache](#hosted-tool-cache) -- [Using `setup-python` with a self hosted runner](#using-setup-python-with-a-self-hosted-runner) - - [Windows](#windows) - - [Linux](#linux) - - [MacOS](#macos) -- [Using `setup-python` on GHES](#using-setup-python-on-ghes) +- [Using python-version input](advanced-usage.md#using-python-version-file-input) + - [Specifying a Python version](advanced-usage.md#specifying-a-python-version) + - [Specifying a PyPy version](advanced-usage.md#specifying-a-pypy-version) + - [Matrix Testing](advanced-usage.md#matrix-testing) +- [Using python-version-file input](advanced-usage.md#using-python-version-file-input) +- [Check latest version](advanced-usage.md#check-latest-version) +- [Caching packages data](advanced-usage.md#caching-packages-data) +- [Environment variables and action's outputs](advanced-usage.md#environment-variables-and-actions-outputs) +- [Available versions of Python and PyPy](advanced-usage.md#available-versions-of-python-and-pypy) + - [Python](advanced-usage.md#python) + - [PyPy](advanced-usage.md#pypy) +- [Hosted tool cache](advanced-usage.md#hosted-tool-cache) +- [Using `setup-python` with a self-hosted runner](advanced-usage.md#using-setup-python-with-a-self-hosted-runner) + - [Windows](advanced-usage.md#windows) + - [Linux](advanced-usage.md#linux) + - [MacOS](advanced-usage.md#macos) +- [Using `setup-python` on GHES](advanced-usage.md#using-setup-python-on-ghes) # Using python-version input @@ -33,7 +33,7 @@ steps: python-version: '3.7.5' - run: python my_script.py ``` - - The only downside to this is that set up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. + - The only downside to this is that set-up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. - MSI installers are used on Windows for this, so runs will take a little longer to set up vs MacOS and Linux. You can specify **only a major and minor version** if you are okay with the most recent patch version being used: @@ -48,9 +48,9 @@ steps: ``` - There will be a single patch version already installed on each runner for every minor version of Python that is supported. - The patch version that will be preinstalled, will generally be the latest and every time there is a new patch released, the older version that is preinstalled will be replaced. - - Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version Python on the runner will be used. + - Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version of Python on the runner will be used. -You can specify version with **prerelease tag** to download and set up an accurate pre-release version of Python: +You can specify the version with **prerelease tag** to download and set up an accurate pre-release version of Python: ```yaml steps: @@ -179,9 +179,9 @@ jobs: # Using python-version-file input -`setup-python` action has ability to read Python/PyPy version from a version file. `python-version-file` input is used for specifying path to the version file. If `.python-version` file doesn't exist, action will fail with error. +`setup-python` action can read Python/PyPy version from a version file. `python-version-file` input is used for specifying the path to the version file. If the `.python-version` file doesn't exist, the action will fail with an error. ->In case both `python-version` and `python-version-file` inputs are supplied, `python-version-file` input will be ignored due to its lower priority. +>In case both `python-version` and `python-version-file` inputs are supplied, the `python-version-file` input will be ignored due to its lower priority. ```yaml steps: @@ -285,7 +285,7 @@ steps: ### `python-version` -Using **python-version** output it's possible to get the installed by action Python/PyPy version. This output is useful when the input `python-version` given as a range (e.g. 3.8.0 - 3.10.0 ), but down in a workflow you need to operate with the exact installed version (e.g. 3.10.1). +Using **python-version** output it's possible to get the installed by action Python/PyPy version. This output is useful when the input `python-version` is given as a range (e.g. 3.8.0 - 3.10.0 ), but down in a workflow you need to operate with the exact installed version (e.g. 3.10.1). ```yaml jobs: @@ -318,7 +318,7 @@ jobs: ``` ### `cache-hit` -**cache-hit** output is available with a boolean value that indicates whether a cache hit occured on the primary key: +**cache-hit** output is available with a boolean value that indicates whether a cache hit occurred on the primary key: ``` jobs: @@ -334,7 +334,7 @@ jobs: - run: echo '${{ steps.cp310.outputs.cache-hit }}' # true if cache-hit occured on the primary key ``` -## Evironment variables +## Environment variables These environment variables become available after setup-python action execution: @@ -373,13 +373,13 @@ Such a requirement on side-effect could be because you don't want your composite - For detailed information regarding the available versions of Python that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software). - For every minor version of Python, expect only the latest patch to be preinstalled. - If `3.8.1` is installed for example, and `3.8.2` is released, expect `3.8.1` to be removed and replaced by `3.8.2` in the tool cache. - - If the exact patch version doesn't matter to you, specifying just the major and minor version will get you the latest preinstalled patch version. In the previous example, the version spec `3.8` will use the `3.8.2` Python version found in the cache. + - If the exact patch version doesn't matter to you, specifying just the major and minor versions will get you the latest preinstalled patch version. In the previous example, the version spec `3.8` will use the `3.8.2` Python version found in the cache. - Use `-dev` instead of a patch number (e.g., `3.11-dev`) to install the latest patch version release for a given minor version, *alpha and beta releases included*. - Downloadable Python versions from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)). - All available versions are listed in the [version-manifest.json](https://github.com/actions/python-versions/blob/main/versions-manifest.json) file. - If there is a specific version of Python that is not available, you can open an issue here ->**Note:** Python versions used in this action are generated in the [python-versions](https://github.com/actions/python-versions) repository. For macOS and Ubuntu images python versions are built from the source code. For Windows the python-versions repository uses installation executable. For more information please refer to the [python-versions](https://github.com/actions/python-versions) repository. +>**Note:** Python versions used in this action are generated in the [python-versions](https://github.com/actions/python-versions) repository. For MacOS and Ubuntu images, python versions are built from the source code. For Windows, the python-versions repository uses installation executable. For more information please refer to the [python-versions](https://github.com/actions/python-versions) repository. ## PyPy @@ -410,7 +410,7 @@ GitHub virtual environments are set up in [actions/virtual-environments](https:/ - Tool cache setup for Windows: [Install-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Configure-Toolset.ps1) -# Using `setup-python` with a self hosted runner +# Using `setup-python` with a self-hosted runner Python distributions are only available for the same [environments](https://github.com/actions/virtual-environments#available-environments) that GitHub Actions hosted environments are available for. If you are using an unsupported version of Ubuntu such as `19.04` or another Linux distribution such as Fedora, `setup-python` may not work. @@ -421,13 +421,13 @@ If you have a supported self-hosted runner and you would like to use `setup-pyth - Your runner needs to be running with administrator privileges so that the appropriate directories and files can be set up when downloading and installing a new version of Python for the first time. - If your runner is configured as a service, make sure the account that is running the service has the appropriate write permissions so that Python can get installed. The default `NT AUTHORITY\NETWORK SERVICE` should be sufficient. -- You need `7zip` installed and added to your `PATH` so that the downloaded versions of Python files can be extracted properly during first-time setup. +- You need `7zip` installed and added to your `PATH` so that the downloaded versions of Python files can be extracted properly during the first-time setup. - MSI installers are used when setting up Python on Windows. A word of caution as MSI installers update registry settings. - The 3.8 MSI installer for Windows will not let you install another 3.8 version of Python. If `setup-python` fails for a 3.8 version of Python, make sure any previously installed versions are removed by going to "Apps & Features" in the Settings app. > By default runner downloads and installs tools into the folder set up by `RUNNER_TOOL_CACHE` environment variable. The environment variable called `AGENT_TOOLSDIRECTORY` can be set to change this location for Windows self-hosted runners. ->If you are experiencing problems while configuring Python on your self-hosted runner, turn on [step debugging](https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs) to see addition logs. +>If you are experiencing problems while configuring Python on your self-hosted runner, turn on [step debugging](https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs) to see additional logs. ## Linux @@ -435,7 +435,7 @@ By default runner downloads and installs tools into the folder set up by `RUNNER - In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/path/to/folder`. - More permanent way of setting the environment variable is to create an `.env` file in the same directory as your runner and to add `AGENT_TOOLSDIRECTORY=/path/to/folder`. This ensures the variable is always set if your runner is configured as a service. -If you're using non-default tool cache directory be sure that the user starting the runner have write permission to the new tool cache directory. To check the current user and group that the runner belongs type `ls -l` inside the runners root directory. +If you're using a non-default tool cache directory be sure that the user starting the runner has write permission to the new tool cache directory. To check the current user and group that the runner belongs type `ls -l` inside the runner's root directory. The runner can be granted write access to any directory using a few techniques: - The user starting the runner is the owner, and the owner has write permission. @@ -450,12 +450,12 @@ One quick way to grant access is to change the user and group of the non-default ## MacOS - The Python packages for MacOS that are downloaded from `actions/python-versions` are originally compiled from source in `/Users/runner/hostedtoolcache`. Due to the fixed shared library path, these Python packages are non-relocatable and require to be installed only in `/Users/runner/hostedtoolcache`. Before use of `setup-python` on the MacOS self-hosted runner: + The Python packages for MacOS that are downloaded from `actions/python-versions` are originally compiled from the source in `/Users/runner/hostedtoolcache`. Due to the fixed shared library path, these Python packages are non-relocatable and require to be installed only in `/Users/runner/hostedtoolcache`. Before the use of `setup-python` on the MacOS self-hosted runner: - Create a directory called `/Users/runner/hostedtoolcache` - Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access -You can check the current user and group that the runner belongs to by typing `ls -l` inside the runners root directory. +You can check the current user and group that the runner belongs to by typing `ls -l` inside the runner's root directory. The runner can be granted write access to the `/Users/runner/hostedtoolcache` directory using a few techniques: - The user starting the runner is the owner, and the owner has write permission - The user starting the runner is in the owning group, and the owning group has write permission @@ -469,6 +469,6 @@ One quick way to grant access is to change the user and group of `/Users/runner/ # Using `setup-python` on GHES -`setup-python` comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading Python distributions, `setup-python` downloads distributions from [`actions/python-versions`](https://github.com/actions/python-versions) on github.com (outside of the appliance). These calls to `actions/python-versions` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting). If more requests are made within the time frame, then you will start to see rate-limit errors during download that read `##[error]API rate limit exceeded for...`. +`setup-python` comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading Python distributions, `setup-python` downloads distributions from [`actions/python-versions`](https://github.com/actions/python-versions) on github.com (outside of the appliance). These calls to `actions/python-versions` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting). If more requests are made within the time frame, then you will start to see rate-limit errors during downloading that looks like: `##[error]API rate limit exceeded for...`. To avoid hitting rate-limit problems, we recommend [setting up your own runner tool cache](https://docs.github.com/en/enterprise-server@2.22/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access#about-the-included-setup-actions-and-the-runner-tool-cache). From b152b04c287bcfebd9fcbe310fd85da74c513089 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 26 Jul 2022 11:49:26 +0200 Subject: [PATCH 15/25] Fix typo in advanced-usage.md --- docs/advanced-usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 4edb54953..85d91835f 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -179,7 +179,7 @@ jobs: # Using python-version-file input -`setup-python` action can read Python/PyPy version from a version file. `python-version-file` input is used for specifying the path to the version file. If the `.python-version` file doesn't exist, the action will fail with an error. +`setup-python` action can read Python/PyPy version from a version file. `python-version-file` input is used for specifying the path to the version file. If the file that was supplied to `python-version-file` input doesn't exist, the action will fail with error. >In case both `python-version` and `python-version-file` inputs are supplied, the `python-version-file` input will be ignored due to its lower priority. From 81cda82fb03d2b1baeed930115043541a7632672 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 26 Jul 2022 14:47:59 +0200 Subject: [PATCH 16/25] Fix review points --- README.md | 8 +++++--- action.yml | 16 ++++++++-------- docs/advanced-usage.md | 16 +++++++--------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 841d82a70..282def295 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ This action provides the following functionalities for GitHub Actions users: -- Optionally downloading and installing the requested version of Python/PyPy and adding it to the PATH +- Optionally installing and adding to PATH a version of Python that is already installed in the runner's tool cache. +- Downloading, installing and adding to PATH an available version of Python from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)) if a specific version is not available in the runner's tool cache. +- Failing if a specific version of Python is not preinstalled or available for download. - Optionally caching dependencies for pip, pipenv and poetry - Registering problem matchers for error output @@ -18,7 +20,7 @@ See [action.yml](action.yml) ```yaml steps: - uses: actions/checkout@v3 -- uses: actions/setup-python@v4 # <- v4 is a major release tag of the action: https://github.com/actions/setup-python/tags +- uses: actions/setup-python@v4 with: python-version: '3.10' - run: python my_script.py @@ -49,7 +51,7 @@ Using `architecture` input it is possible to specify the required Python/PyPy in ## Caching packages dependencies -The action has built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood for caching dependencies but requires less configuration settings. Supported package managers are `pip`, `pipenv` and `poetry`. The `cache` input is optional, and caching is turned off by default. +The action has built-in functionality for caching and restoring dependencies. It uses [toolkit/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood for caching dependencies but requires less configuration settings. Supported package managers are `pip`, `pipenv` and `poetry`. The `cache` input is optional, and caching is turned off by default. The action defaults to searching for a dependency file (`requirements.txt` for pip, `Pipfile.lock` for pipenv or `poetry.lock` for poetry) in the repository, and uses its hash as a part of the cache key. Input `cache-dependency-path` is used for cases when multiple dependency files are used, they are located in different subdirectories or different files for the hash that want to be used. diff --git a/action.yml b/action.yml index f6ff15c43..b812444ae 100644 --- a/action.yml +++ b/action.yml @@ -1,33 +1,33 @@ --- -name: 'Setup Python' -description: 'Set up a specific version of Python and add the command-line tools to the PATH.' -author: 'GitHub' +name: "Setup Python" +description: "Set up a specific version of Python and add the command-line tools to the PATH." +author: "GitHub" inputs: python-version: description: "Version range or exact version of Python/PyPy to use, using SemVer's version range syntax. Reads from .python-version if unset." python-version-file: description: "File containing the Python version to use. Example: .python-version" 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." required: false architecture: description: "The target architecture (x86, x64) of the Python/PyPy interpreter." 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." default: false token: description: "Used to pull python distributions from actions/python-versions. Since there's a default, this is typically not supplied by the user." default: ${{ github.token }} 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." 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." default: true outputs: python-version: description: "The installed Python/PyPy version. Useful when given a version range as input." cache-hit: - description: 'A boolean value to indicate a cache entry was found' + description: "A boolean value to indicate a cache entry was found" python-path: description: "The absolute path to the Python/PyPy executable." runs: diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 85d91835f..c7a3a353f 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -1,4 +1,4 @@ -# Table of contents +# Contents - [Using python-version input](advanced-usage.md#using-python-version-file-input) - [Specifying a Python version](advanced-usage.md#specifying-a-python-version) - [Specifying a PyPy version](advanced-usage.md#specifying-a-pypy-version) @@ -19,11 +19,9 @@ # Using python-version input -The `python-version` input is used to specify the required version of Python or PyPy. - ## Specifying a Python version -If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the **exact major, minor, and patch version** (such as `3.7.5`): +If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the ***exact major, minor, and patch version*** (such as `3.7.5`): ```yaml steps: @@ -36,7 +34,7 @@ steps: - The only downside to this is that set-up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. - MSI installers are used on Windows for this, so runs will take a little longer to set up vs MacOS and Linux. -You can specify **only a major and minor version** if you are okay with the most recent patch version being used: +You can specify ***only a major and minor version*** if you are okay with the most recent patch version being used: ```yaml steps: @@ -50,7 +48,7 @@ steps: - The patch version that will be preinstalled, will generally be the latest and every time there is a new patch released, the older version that is preinstalled will be replaced. - Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version of Python on the runner will be used. -You can specify the version with **prerelease tag** to download and set up an accurate pre-release version of Python: +You can specify the version with ***prerelease tag*** to download and set up an accurate pre-release version of Python: ```yaml steps: @@ -61,7 +59,7 @@ steps: - run: python my_script.py ``` -It's also possible to use **x.y-dev syntax** to download and set up the latest patch version of Python, alpha and beta releases included. (for specified major & minor versions): +It's also possible to use ***x.y-dev syntax*** to download and set up the latest patch version of Python, alpha and beta releases included. (for specified major & minor versions): ```yaml steps: @@ -74,7 +72,7 @@ steps: You can also use several types of ranges that are specified in [semver](https://github.com/npm/node-semver#ranges), for instance: -- **[hyphen ranges](https://github.com/npm/node-semver#hyphen-ranges-xyz---abc)** to download and set up the latest available version of Python (includes both pre-release and stable versions): +- ***[hyphen ranges](https://github.com/npm/node-semver#hyphen-ranges-xyz---abc)*** to download and set up the latest available version of Python (includes both pre-release and stable versions): ```yaml steps: @@ -85,7 +83,7 @@ steps: - run: python my_script.py ``` -- **[x-ranges](https://github.com/npm/node-semver#x-ranges-12x-1x-12-)** to specify the latest stable version of Python (for specified major version): +- ***[x-ranges](https://github.com/npm/node-semver#x-ranges-12x-1x-12-)*** to specify the latest stable version of Python (for specified major version): ```yaml steps: From c6e66a7681a75159e346622594ace087b0be263a Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 26 Jul 2022 14:51:59 +0200 Subject: [PATCH 17/25] Fix typo --- docs/advanced-usage.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index c7a3a353f..878e29cfd 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -1,5 +1,5 @@ # Contents -- [Using python-version input](advanced-usage.md#using-python-version-file-input) +- [Using python-version input](advanced-usage.md#using-python-version-input) - [Specifying a Python version](advanced-usage.md#specifying-a-python-version) - [Specifying a PyPy version](advanced-usage.md#specifying-a-pypy-version) - [Matrix Testing](advanced-usage.md#matrix-testing) @@ -21,7 +21,7 @@ ## Specifying a Python version -If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the ***exact major, minor, and patch version*** (such as `3.7.5`): +If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the **exact major, minor, and patch version** (such as `3.7.5`): ```yaml steps: @@ -34,7 +34,7 @@ steps: - The only downside to this is that set-up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. - MSI installers are used on Windows for this, so runs will take a little longer to set up vs MacOS and Linux. -You can specify ***only a major and minor version*** if you are okay with the most recent patch version being used: +You can specify **only a major and minor version** if you are okay with the most recent patch version being used: ```yaml steps: @@ -48,7 +48,7 @@ steps: - The patch version that will be preinstalled, will generally be the latest and every time there is a new patch released, the older version that is preinstalled will be replaced. - Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version of Python on the runner will be used. -You can specify the version with ***prerelease tag*** to download and set up an accurate pre-release version of Python: +You can specify the version with **prerelease tag** to download and set up an accurate pre-release version of Python: ```yaml steps: @@ -59,7 +59,7 @@ steps: - run: python my_script.py ``` -It's also possible to use ***x.y-dev syntax*** to download and set up the latest patch version of Python, alpha and beta releases included. (for specified major & minor versions): +It's also possible to use **x.y-dev syntax** to download and set up the latest patch version of Python, alpha and beta releases included. (for specified major & minor versions): ```yaml steps: @@ -72,7 +72,7 @@ steps: You can also use several types of ranges that are specified in [semver](https://github.com/npm/node-semver#ranges), for instance: -- ***[hyphen ranges](https://github.com/npm/node-semver#hyphen-ranges-xyz---abc)*** to download and set up the latest available version of Python (includes both pre-release and stable versions): +- **[hyphen ranges](https://github.com/npm/node-semver#hyphen-ranges-xyz---abc)** to download and set up the latest available version of Python (includes both pre-release and stable versions): ```yaml steps: @@ -83,7 +83,7 @@ steps: - run: python my_script.py ``` -- ***[x-ranges](https://github.com/npm/node-semver#x-ranges-12x-1x-12-)*** to specify the latest stable version of Python (for specified major version): +- **[x-ranges](https://github.com/npm/node-semver#x-ranges-12x-1x-12-)** to specify the latest stable version of Python (for specified major version): ```yaml steps: From fd6f59db224e14d6818f88d8e85f1343a2760d72 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 26 Jul 2022 14:56:14 +0200 Subject: [PATCH 18/25] Change contents to make them more readable --- docs/advanced-usage.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 878e29cfd..de930e126 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -21,7 +21,7 @@ ## Specifying a Python version -If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the **exact major, minor, and patch version** (such as `3.7.5`): +- If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the **exact major, minor, and patch version** (such as `3.7.5`): ```yaml steps: @@ -34,7 +34,7 @@ steps: - The only downside to this is that set-up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. - MSI installers are used on Windows for this, so runs will take a little longer to set up vs MacOS and Linux. -You can specify **only a major and minor version** if you are okay with the most recent patch version being used: +- You can specify **only a major and minor version** if you are okay with the most recent patch version being used: ```yaml steps: @@ -48,7 +48,7 @@ steps: - The patch version that will be preinstalled, will generally be the latest and every time there is a new patch released, the older version that is preinstalled will be replaced. - Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version of Python on the runner will be used. -You can specify the version with **prerelease tag** to download and set up an accurate pre-release version of Python: +- You can specify the version with **prerelease tag** to download and set up an accurate pre-release version of Python: ```yaml steps: @@ -59,7 +59,7 @@ steps: - run: python my_script.py ``` -It's also possible to use **x.y-dev syntax** to download and set up the latest patch version of Python, alpha and beta releases included. (for specified major & minor versions): +- It's also possible to use **x.y-dev syntax** to download and set up the latest patch version of Python, alpha and beta releases included. (for specified major & minor versions): ```yaml steps: @@ -70,9 +70,9 @@ steps: - run: python my_script.py ``` -You can also use several types of ranges that are specified in [semver](https://github.com/npm/node-semver#ranges), for instance: +- You can also use several types of ranges that are specified in [semver](https://github.com/npm/node-semver#ranges), for instance: -- **[hyphen ranges](https://github.com/npm/node-semver#hyphen-ranges-xyz---abc)** to download and set up the latest available version of Python (includes both pre-release and stable versions): + - **[hyphen ranges](https://github.com/npm/node-semver#hyphen-ranges-xyz---abc)** to download and set up the latest available version of Python (includes both pre-release and stable versions): ```yaml steps: @@ -83,7 +83,7 @@ steps: - run: python my_script.py ``` -- **[x-ranges](https://github.com/npm/node-semver#x-ranges-12x-1x-12-)** to specify the latest stable version of Python (for specified major version): + - **[x-ranges](https://github.com/npm/node-semver#x-ranges-12x-1x-12-)** to specify the latest stable version of Python (for specified major version): ```yaml steps: From 853c012a3c7e40881435c8a92898c46539e11860 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 26 Jul 2022 14:59:35 +0200 Subject: [PATCH 19/25] Change advanced-usage.md --- docs/advanced-usage.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index de930e126..8ddbc8e4d 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -23,7 +23,7 @@ - If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the **exact major, minor, and patch version** (such as `3.7.5`): - ```yaml +```yaml steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 @@ -31,12 +31,12 @@ steps: python-version: '3.7.5' - run: python my_script.py ``` - - The only downside to this is that set-up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. - - MSI installers are used on Windows for this, so runs will take a little longer to set up vs MacOS and Linux. + - The only downside to this is that set-up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. + - MSI installers are used on Windows for this, so runs will take a little longer to set up vs MacOS and Linux. - You can specify **only a major and minor version** if you are okay with the most recent patch version being used: - ```yaml +```yaml steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 @@ -44,9 +44,9 @@ steps: python-version: '3.7' - run: python my_script.py ``` - - There will be a single patch version already installed on each runner for every minor version of Python that is supported. - - The patch version that will be preinstalled, will generally be the latest and every time there is a new patch released, the older version that is preinstalled will be replaced. - - Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version of Python on the runner will be used. + - There will be a single patch version already installed on each runner for every minor version of Python that is supported. + - The patch version that will be preinstalled, will generally be the latest and every time there is a new patch released, the older version that is preinstalled will be replaced. + - Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version of Python on the runner will be used. - You can specify the version with **prerelease tag** to download and set up an accurate pre-release version of Python: From fe396d3941d5b4e765fc2fd32ca503e501536e03 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 26 Jul 2022 15:03:33 +0200 Subject: [PATCH 20/25] Revert changes --- docs/advanced-usage.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 8ddbc8e4d..85c4bdb50 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -21,7 +21,7 @@ ## Specifying a Python version -- If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the **exact major, minor, and patch version** (such as `3.7.5`): +If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the **exact major, minor, and patch version** (such as `3.7.5`): ```yaml steps: @@ -31,10 +31,11 @@ steps: python-version: '3.7.5' - run: python my_script.py ``` - - The only downside to this is that set-up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. - - MSI installers are used on Windows for this, so runs will take a little longer to set up vs MacOS and Linux. -- You can specify **only a major and minor version** if you are okay with the most recent patch version being used: +- The only downside to this is that set-up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. +- MSI installers are used on Windows for this, so runs will take a little longer to set up vs MacOS and Linux. + +You can specify **only a major and minor version** if you are okay with the most recent patch version being used: ```yaml steps: @@ -44,11 +45,11 @@ steps: python-version: '3.7' - run: python my_script.py ``` - - There will be a single patch version already installed on each runner for every minor version of Python that is supported. - - The patch version that will be preinstalled, will generally be the latest and every time there is a new patch released, the older version that is preinstalled will be replaced. - - Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version of Python on the runner will be used. +- There will be a single patch version already installed on each runner for every minor version of Python that is supported. +- The patch version that will be preinstalled, will generally be the latest and every time there is a new patch released, the older version that is preinstalled will be replaced. +- Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version of Python on the runner will be used. -- You can specify the version with **prerelease tag** to download and set up an accurate pre-release version of Python: +You can specify the version with **prerelease tag** to download and set up an accurate pre-release version of Python: ```yaml steps: @@ -59,7 +60,7 @@ steps: - run: python my_script.py ``` -- It's also possible to use **x.y-dev syntax** to download and set up the latest patch version of Python, alpha and beta releases included. (for specified major & minor versions): +It's also possible to use **x.y-dev syntax** to download and set up the latest patch version of Python, alpha and beta releases included. (for specified major & minor versions): ```yaml steps: @@ -70,7 +71,7 @@ steps: - run: python my_script.py ``` -- You can also use several types of ranges that are specified in [semver](https://github.com/npm/node-semver#ranges), for instance: +You can also use several types of ranges that are specified in [semver](https://github.com/npm/node-semver#ranges), for instance: - **[hyphen ranges](https://github.com/npm/node-semver#hyphen-ranges-xyz---abc)** to download and set up the latest available version of Python (includes both pre-release and stable versions): @@ -83,7 +84,7 @@ steps: - run: python my_script.py ``` - - **[x-ranges](https://github.com/npm/node-semver#x-ranges-12x-1x-12-)** to specify the latest stable version of Python (for specified major version): +**[x-ranges](https://github.com/npm/node-semver#x-ranges-12x-1x-12-)** to specify the latest stable version of Python (for specified major version): ```yaml steps: From 72394d1a3e63e9ea594929a21d057324696cad57 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 26 Jul 2022 15:04:50 +0200 Subject: [PATCH 21/25] Fix typo --- docs/advanced-usage.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 85c4bdb50..43e86bcb8 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -73,7 +73,7 @@ steps: You can also use several types of ranges that are specified in [semver](https://github.com/npm/node-semver#ranges), for instance: - - **[hyphen ranges](https://github.com/npm/node-semver#hyphen-ranges-xyz---abc)** to download and set up the latest available version of Python (includes both pre-release and stable versions): +- **[hyphen ranges](https://github.com/npm/node-semver#hyphen-ranges-xyz---abc)** to download and set up the latest available version of Python (includes both pre-release and stable versions): ```yaml steps: @@ -84,7 +84,7 @@ steps: - run: python my_script.py ``` -**[x-ranges](https://github.com/npm/node-semver#x-ranges-12x-1x-12-)** to specify the latest stable version of Python (for specified major version): +- **[x-ranges](https://github.com/npm/node-semver#x-ranges-12x-1x-12-)** to specify the latest stable version of Python (for specified major version): ```yaml steps: From c318b92fd627ecea2e1c2efcd2fd8df4a972d849 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Thu, 28 Jul 2022 09:38:24 +0200 Subject: [PATCH 22/25] Fix review points --- README.md | 8 ++++---- action.yml | 8 ++++---- docs/advanced-usage.md | 30 +++++++++++++++--------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 282def295..2e2a11933 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ GitHub Actions status

-This action provides the following functionalities for GitHub Actions users: +This action provides the following functionality for GitHub Actions users: - Optionally installing and adding to PATH a version of Python that is already installed in the runner's tool cache. - Downloading, installing and adding to PATH an available version of Python from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)) if a specific version is not available in the runner's tool cache. @@ -35,11 +35,11 @@ steps: python-version: 'pypy3.9' - run: python my_script.py ``` -The `python-version` input is optional. If not supplied, the action will try to resolve the version from the default `.python-version` file. If the `.python-version` file doesn't exist Python/PyPy version from the PATH will be used. The default version of Python/PyPy in PATH varies between runners and can be changed unexpectedly so we recommend always using `setup-python`. +The `python-version` input is optional. If not supplied, the action will try to resolve the version from the default `.python-version` file. If the `.python-version` file doesn't exist Python or PyPy version from the PATH will be used. The default version of Python or PyPy in PATH varies between runners and can be changed unexpectedly so we recommend always using `setup-python`. The action will first check the local [tool cache](docs/advanced-usage.md#hosted-tool-cache) for a [semver](https://github.com/npm/node-semver#versions) match. If unable to find a specific version in the tool cache, the action will attempt to download a version of Python from [GitHub Releases](https://github.com/actions/python-versions/releases) and for PyPy from the official [PyPy's dist](https://downloads.python.org/pypy/). -For information regarding locally cached versions of Python/PyPy on GitHub hosted runners, check out [GitHub Actions Virtual Environments](https://github.com/actions/virtual-environments). +For information regarding locally cached versions of Python or PyPy on GitHub hosted runners, check out [GitHub Actions Virtual Environments](https://github.com/actions/virtual-environments). ## Supported version syntax @@ -47,7 +47,7 @@ The `python-version` input supports the [Semantic Versioning Specification](http ## Supported architectures -Using `architecture` input it is possible to specify the required Python/PyPy interpreter architecture: `x86` or `x64`. If the input is not specified the architecture defaults to `x64`. +Using `architecture` input it is possible to specify the required Python or PyPy interpreter architecture: `x86` or `x64`. If the input is not specified the architecture defaults to `x64`. ## Caching packages dependencies diff --git a/action.yml b/action.yml index b812444ae..c0fd1d122 100644 --- a/action.yml +++ b/action.yml @@ -4,14 +4,14 @@ description: "Set up a specific version of Python and add the command-line tools author: "GitHub" inputs: python-version: - description: "Version range or exact version of Python/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, using SemVer's version range syntax. Reads from .python-version if unset." python-version-file: description: "File containing the Python version to use. Example: .python-version" cache: description: "Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry." required: false architecture: - description: "The target architecture (x86, x64) of the Python/PyPy interpreter." + description: "The target architecture (x86, x64) of the Python or PyPy interpreter." check-latest: description: "Set this option if you want the action to check for the latest available version that satisfies the version spec." default: false @@ -25,11 +25,11 @@ inputs: default: true outputs: python-version: - description: "The installed Python/PyPy version. Useful when given a version range as input." + description: "The installed Python or PyPy version. Useful when given a version range as input." cache-hit: description: "A boolean value to indicate a cache entry was found" python-path: - description: "The absolute path to the Python/PyPy executable." + description: "The absolute path to the Python or PyPy executable." runs: using: 'node16' main: 'dist/setup/index.js' diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 43e86bcb8..d6365252c 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -14,7 +14,7 @@ - [Using `setup-python` with a self-hosted runner](advanced-usage.md#using-setup-python-with-a-self-hosted-runner) - [Windows](advanced-usage.md#windows) - [Linux](advanced-usage.md#linux) - - [MacOS](advanced-usage.md#macos) + - [macOS](advanced-usage.md#macos) - [Using `setup-python` on GHES](advanced-usage.md#using-setup-python-on-ghes) # Using python-version input @@ -32,8 +32,8 @@ steps: - run: python my_script.py ``` -- The only downside to this is that set-up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions. -- MSI installers are used on Windows for this, so runs will take a little longer to set up vs MacOS and Linux. +- The only downside to this is that setup may take a little longer. If the exact version is not already installed on the runner due to more recent versions, the exact version will have to be downloaded. +- MSI installers are used on Windows for this, so runs will take a little longer to set up vs macOS and Linux. You can specify **only a major and minor version** if you are okay with the most recent patch version being used: @@ -131,7 +131,7 @@ More details on PyPy syntax can be found in the [Available versions of PyPy](#py ## Matrix Testing -Using `setup-python` it's possible to use [matrix syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) to install several versions of Python/PyPy: +Using `setup-python` it's possible to use [matrix syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) to install several versions of Python or PyPy: ```yaml jobs: @@ -178,7 +178,7 @@ jobs: # Using python-version-file input -`setup-python` action can read Python/PyPy version from a version file. `python-version-file` input is used for specifying the path to the version file. If the file that was supplied to `python-version-file` input doesn't exist, the action will fail with error. +`setup-python` action can read Python or PyPy version from a version file. `python-version-file` input is used for specifying the path to the version file. If the file that was supplied to `python-version-file` input doesn't exist, the action will fail with error. >In case both `python-version` and `python-version-file` inputs are supplied, the `python-version-file` input will be ignored due to its lower priority. @@ -192,9 +192,9 @@ steps: ``` # Check latest version -The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific `Python/PyPy` version is always used. +The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific `Python or PyPy` version is always used. -If `check-latest` is set to `true`, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, a `Python/PyPy` version will then be downloaded. Set `check-latest` to `true` if you want the most up-to-date `Python/PyPy` version to always be used. +If `check-latest` is set to `true`, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, a `Python or PyPy` version will then be downloaded. Set `check-latest` to `true` if you want the most up-to-date `Python or PyPy` version to always be used. ```yaml steps: @@ -205,7 +205,7 @@ steps: check-latest: true - run: python my_script.py ``` -> Setting `check-latest` to `true` has performance implications as downloading `Python/PyPy` versions is slower than using cached versions. +> Setting `check-latest` to `true` has performance implications as downloading `Python or PyPy` versions is slower than using cached versions. # Caching packages data @@ -284,7 +284,7 @@ steps: ### `python-version` -Using **python-version** output it's possible to get the installed by action Python/PyPy version. This output is useful when the input `python-version` is given as a range (e.g. 3.8.0 - 3.10.0 ), but down in a workflow you need to operate with the exact installed version (e.g. 3.10.1). +Using **python-version** output it's possible to get the installed by action Python or PyPy version. This output is useful when the input `python-version` is given as a range (e.g. 3.8.0 - 3.10.0 ), but down in a workflow you need to operate with the exact installed version (e.g. 3.10.1). ```yaml jobs: @@ -301,7 +301,7 @@ jobs: ### `python-path` -**python-path** output is available with the absolute path of the Python/PyPy interpreter executable if you need it: +**python-path** output is available with the absolute path of the Python or PyPy interpreter executable if you need it: ```yaml jobs: @@ -347,10 +347,10 @@ These environment variables become available after setup-python action execution ## Using `update-environment` flag The `update-environment` flag defaults to `true`. -With this setting, the action will add/update environment variables (e.g. `PATH`, `PKG_CONFIG_PATH`, `pythonLocation`) for Python/PyPy to just work out of the box. +With this setting, the action will add/update environment variables (e.g. `PATH`, `PKG_CONFIG_PATH`, `pythonLocation`) for Python or PyPy to just work out of the box. If `update-environment` is set to `false`, the action will not add/update environment variables. -This can prove useful if you want the only side-effect to be to ensure Python/PyPy is installed and rely on the `python-path` output to run executable. +This can prove useful if you want the only side-effect to be to ensure Python or PyPy is installed and rely on the `python-path` output to run executable. Such a requirement on side-effect could be because you don't want your composite action messing with your user's workflows. ```yaml @@ -378,7 +378,7 @@ Such a requirement on side-effect could be because you don't want your composite - All available versions are listed in the [version-manifest.json](https://github.com/actions/python-versions/blob/main/versions-manifest.json) file. - If there is a specific version of Python that is not available, you can open an issue here ->**Note:** Python versions used in this action are generated in the [python-versions](https://github.com/actions/python-versions) repository. For MacOS and Ubuntu images, python versions are built from the source code. For Windows, the python-versions repository uses installation executable. For more information please refer to the [python-versions](https://github.com/actions/python-versions) repository. +>**Note:** Python versions used in this action are generated in the [python-versions](https://github.com/actions/python-versions) repository. For macOS and Ubuntu images, python versions are built from the source code. For Windows, the python-versions repository uses installation executable. For more information please refer to the [python-versions](https://github.com/actions/python-versions) repository. ## PyPy @@ -447,9 +447,9 @@ One quick way to grant access is to change the user and group of the non-default > If your runner is configured as a service and you run into problems, make sure the user that the service is running as is correct. For more information, you can [check the status of your self-hosted runner](https://docs.github.com/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service#checking-the-status-of-the-service). -## MacOS +## macOS - The Python packages for MacOS that are downloaded from `actions/python-versions` are originally compiled from the source in `/Users/runner/hostedtoolcache`. Due to the fixed shared library path, these Python packages are non-relocatable and require to be installed only in `/Users/runner/hostedtoolcache`. Before the use of `setup-python` on the MacOS self-hosted runner: + The Python packages for macOS that are downloaded from `actions/python-versions` are originally compiled from the source in `/Users/runner/hostedtoolcache`. Due to the fixed shared library path, these Python packages are non-relocatable and require to be installed only in `/Users/runner/hostedtoolcache`. Before the use of `setup-python` on the macOS self-hosted runner: - Create a directory called `/Users/runner/hostedtoolcache` - Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access From cfcafa57ec3e74dcd563b5a8ea4a0a330d4ccc33 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Mon, 1 Aug 2022 16:23:57 +0200 Subject: [PATCH 23/25] Fix review points --- README.md | 4 +--- docs/advanced-usage.md | 40 ++++++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 2e2a11933..5155ac0dd 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,7 @@ This action provides the following functionality for GitHub Actions users: -- Optionally installing and adding to PATH a version of Python that is already installed in the runner's tool cache. -- Downloading, installing and adding to PATH an available version of Python from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)) if a specific version is not available in the runner's tool cache. -- Failing if a specific version of Python is not preinstalled or available for download. +- Installing a version of Python or PyPy and (by default) adding it to the PATH - Optionally caching dependencies for pip, pipenv and poetry - Registering problem matchers for error output diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index d6365252c..7138ba9cd 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -1,4 +1,4 @@ -# Contents +# Advanced Usage - [Using python-version input](advanced-usage.md#using-python-version-input) - [Specifying a Python version](advanced-usage.md#specifying-a-python-version) - [Specifying a PyPy version](advanced-usage.md#specifying-a-pypy-version) @@ -17,9 +17,9 @@ - [macOS](advanced-usage.md#macos) - [Using `setup-python` on GHES](advanced-usage.md#using-setup-python-on-ghes) -# Using python-version input +## Using the `python-version` input -## Specifying a Python version +### Specifying a Python version If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the **exact major, minor, and patch version** (such as `3.7.5`): @@ -96,7 +96,7 @@ steps: ``` Please refer to the [Advanced range syntax section](https://github.com/npm/node-semver#advanced-range-syntax) of the [semver](https://github.com/npm/node-semver) to check other available range syntaxes. -## Specifying a PyPy version +### Specifying a PyPy version The version of PyPy should be specified in the format `pypy[-v]` or `pypy-[-v]`. The `-v` parameter is optional and can be skipped. The latest PyPy version will be used in this case. @@ -129,7 +129,7 @@ jobs: ``` More details on PyPy syntax can be found in the [Available versions of PyPy](#pypy) section. -## Matrix Testing +### Matrix Testing Using `setup-python` it's possible to use [matrix syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) to install several versions of Python or PyPy: @@ -176,7 +176,7 @@ jobs: run: python --version ``` -# Using python-version-file input +## Using the `python-version-file` input `setup-python` action can read Python or PyPy version from a version file. `python-version-file` input is used for specifying the path to the version file. If the file that was supplied to `python-version-file` input doesn't exist, the action will fail with error. @@ -190,7 +190,7 @@ steps: python-version-file: '.python-version' # Read python version from a file .python-version - run: python my_script.py ``` -# Check latest version +## Check latest version The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific `Python or PyPy` version is always used. @@ -208,7 +208,7 @@ steps: > Setting `check-latest` to `true` has performance implications as downloading `Python or PyPy` versions is slower than using cached versions. -# Caching packages data +## Caching packages **Caching pipenv dependencies:** ```yaml @@ -278,9 +278,9 @@ steps: - run: pip install -e . -r subdirectory/requirements-dev.txt ``` -# Environment variables and action's outputs +# Outputs and environment variables -## Action's outputs +## Outputs ### `python-version` @@ -363,8 +363,8 @@ Such a requirement on side-effect could be because you don't want your composite update-environment: false - run: ${{ steps.cp310.outputs.python-path }} my_script.py ``` -# Available versions of Python and PyPy -## Python +## Available versions of Python and PyPy +### Python `setup-python` is able to configure **Python** from two sources: @@ -380,7 +380,7 @@ Such a requirement on side-effect could be because you don't want your composite >**Note:** Python versions used in this action are generated in the [python-versions](https://github.com/actions/python-versions) repository. For macOS and Ubuntu images, python versions are built from the source code. For Windows, the python-versions repository uses installation executable. For more information please refer to the [python-versions](https://github.com/actions/python-versions) repository. -## PyPy +### PyPy `setup-python` is able to configure **PyPy** from two sources: @@ -394,7 +394,7 @@ Such a requirement on side-effect could be because you don't want your composite - PyPy < 7.3.3 are not available to install on-flight. - If some versions are not available, you can open an issue in https://foss.heptapod.net/pypy/pypy/ -# Hosted tool cache +## Hosted tool cache GitHub hosted runners have a tool cache that comes with a few versions of Python + PyPy already installed. This tool cache helps speed up runs and tool setup by not requiring any new downloads. There is an environment variable called `RUNNER_TOOL_CACHE` on each runner that describes the location of the tool cache with Python and PyPy installed. `setup-python` works by taking a specific version of Python or PyPy from this tool cache and adding it to PATH. @@ -409,14 +409,14 @@ GitHub virtual environments are set up in [actions/virtual-environments](https:/ - Tool cache setup for Windows: [Install-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Configure-Toolset.ps1) -# Using `setup-python` with a self-hosted runner +## Using `setup-python` with a self-hosted runner Python distributions are only available for the same [environments](https://github.com/actions/virtual-environments#available-environments) that GitHub Actions hosted environments are available for. If you are using an unsupported version of Ubuntu such as `19.04` or another Linux distribution such as Fedora, `setup-python` may not work. If you have a supported self-hosted runner and you would like to use `setup-python`, there are a few extra things you need to make sure are set up so that new versions of Python can be downloaded and configured on your runner. -## Windows +### Windows - Your runner needs to be running with administrator privileges so that the appropriate directories and files can be set up when downloading and installing a new version of Python for the first time. - If your runner is configured as a service, make sure the account that is running the service has the appropriate write permissions so that Python can get installed. The default `NT AUTHORITY\NETWORK SERVICE` should be sufficient. @@ -428,7 +428,7 @@ If you have a supported self-hosted runner and you would like to use `setup-pyth >If you are experiencing problems while configuring Python on your self-hosted runner, turn on [step debugging](https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs) to see additional logs. -## Linux +### Linux By default runner downloads and installs tools into the folder set up by `RUNNER_TOOL_CACHE` environment variable. The environment variable called `AGENT_TOOLSDIRECTORY` can be set to change this location for Linux self-hosted runners: - In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/path/to/folder`. @@ -447,7 +447,7 @@ One quick way to grant access is to change the user and group of the non-default > If your runner is configured as a service and you run into problems, make sure the user that the service is running as is correct. For more information, you can [check the status of your self-hosted runner](https://docs.github.com/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service#checking-the-status-of-the-service). -## macOS +### macOS The Python packages for macOS that are downloaded from `actions/python-versions` are originally compiled from the source in `/Users/runner/hostedtoolcache`. Due to the fixed shared library path, these Python packages are non-relocatable and require to be installed only in `/Users/runner/hostedtoolcache`. Before the use of `setup-python` on the macOS self-hosted runner: @@ -466,8 +466,8 @@ One quick way to grant access is to change the user and group of `/Users/runner/ -# Using `setup-python` on GHES +## Using `setup-python` on GHES `setup-python` comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading Python distributions, `setup-python` downloads distributions from [`actions/python-versions`](https://github.com/actions/python-versions) on github.com (outside of the appliance). These calls to `actions/python-versions` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting). If more requests are made within the time frame, then you will start to see rate-limit errors during downloading that looks like: `##[error]API rate limit exceeded for...`. -To avoid hitting rate-limit problems, we recommend [setting up your own runner tool cache](https://docs.github.com/en/enterprise-server@2.22/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access#about-the-included-setup-actions-and-the-runner-tool-cache). +To avoid hitting rate-limit problems, we recommend [setting up your own runner tool cache](https://docs.github.com/en/enterprise-server@2.22/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access#about-the-included-setup-actions-and-the-runner-tool-cache). \ No newline at end of file From c4e98b741b9d2b91a44c958390134fdcb0429533 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Mon, 1 Aug 2022 16:33:59 +0200 Subject: [PATCH 24/25] Fix broken links --- README.md | 8 ++++---- docs/advanced-usage.md | 11 +++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5155ac0dd..e60f1923b 100644 --- a/README.md +++ b/README.md @@ -76,11 +76,11 @@ See examples of using `cache` and `cache-dependency-path` for `pipenv` and `poet ## Advanced usage -- [Using python-version input](docs/advanced-usage.md#using-python-version-input) -- [Using python-version-file input](docs/advanced-usage.md#using-python-version-file-input) +- [Using the python-version input](docs/advanced-usage.md#using-the-python-version-input) +- [Using the python-version-file input](docs/advanced-usage.md#using-the-python-version-file-input) - [Check latest version](docs/advanced-usage.md#check-latest-version) -- [Caching packages data](docs/advanced-usage.md#caching-packages-data) -- [Environment variables and action's outputs](docs/advanced-usage.md#environment-variables-and-actions-outputs) +- [Caching packages](docs/advanced-usage.md#caching-packages) +- [Outputs and environment variables](docs/advanced-usage.md#outputs-and-environment-variables) - [Available versions of Python and PyPy](docs/advanced-usage.md#available-versions-of-python-and-pypy) - [Hosted tool cache](docs/advanced-usage.md#hosted-tool-cache) - [Using `setup-python` with a self-hosted runner](docs/advanced-usage.md#using-setup-python-with-a-self-hosted-runner) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 7138ba9cd..024e8b1ec 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -1,12 +1,15 @@ # Advanced Usage -- [Using python-version input](advanced-usage.md#using-python-version-input) +- [Using the python-version input](advanced-usage.md#using-the-python-version-input) - [Specifying a Python version](advanced-usage.md#specifying-a-python-version) - [Specifying a PyPy version](advanced-usage.md#specifying-a-pypy-version) - [Matrix Testing](advanced-usage.md#matrix-testing) -- [Using python-version-file input](advanced-usage.md#using-python-version-file-input) +- [Using the python-version-file input](advanced-usage.md#using-the-python-version-file-input) - [Check latest version](advanced-usage.md#check-latest-version) -- [Caching packages data](advanced-usage.md#caching-packages-data) -- [Environment variables and action's outputs](advanced-usage.md#environment-variables-and-actions-outputs) +- [Caching packages](advanced-usage.md#caching-packages) +- [Outputs and environment variables](advanced-usage.md#outputs-and-environment-variables) + - [Outputs](advanced-usage.md#outputs) + - [Environment variables](advanced-usage.md#environment-variables) + - [Using update-environment flag](advanced-usage.md#using-update-environment-flag) - [Available versions of Python and PyPy](advanced-usage.md#available-versions-of-python-and-pypy) - [Python](advanced-usage.md#python) - [PyPy](advanced-usage.md#pypy) From 789730b666521111ca6f8cac30ef7f8953d953cb Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Mon, 1 Aug 2022 16:44:50 +0200 Subject: [PATCH 25/25] Fix broken links in the text body --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e60f1923b..bc637ed87 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ For information regarding locally cached versions of Python or PyPy on GitHub ho ## Supported version syntax -The `python-version` input supports the [Semantic Versioning Specification](https://semver.org/) and some special version notations (e.g. `semver ranges`, `x.y-dev syntax`, etc.), for detailed examples please refer to the section: [Using python-version input](docs/advanced-usage.md#using-python-version-input) of the [Advanced usage](docs/advanced-usage.md) guide. +The `python-version` input supports the [Semantic Versioning Specification](https://semver.org/) and some special version notations (e.g. `semver ranges`, `x.y-dev syntax`, etc.), for detailed examples please refer to the section: [Using python-version input](docs/advanced-usage.md#using-the-python-version-input) of the [Advanced usage](docs/advanced-usage.md) guide. ## Supported architectures @@ -72,7 +72,7 @@ steps: >The requirements file format allows for specifying dependency versions using logical operators (for example chardet>=3.0.4) or specifying dependencies without any versions. In this case the pip install -r requirements.txt command will always try to install the latest available package version. To be sure that the cache will be used, please stick to a specific dependency version and update it manually if necessary. -See examples of using `cache` and `cache-dependency-path` for `pipenv` and `poetry` in the section: [Caching packages data](docs/advanced-usage.md#caching-packages-data) of the [Advanced usage](docs/advanced-usage.md) guide. +See examples of using `cache` and `cache-dependency-path` for `pipenv` and `poetry` in the section: [Caching packages](docs/advanced-usage.md#caching-packages) of the [Advanced usage](docs/advanced-usage.md) guide. ## Advanced usage