2023-05-10 13:35:07 +00:00
|
|
|
# An action for setting up poetry install with caching.
|
|
|
|
# Using a custom action since the default action does not
|
|
|
|
# take poetry install groups into account.
|
|
|
|
# Action code from:
|
|
|
|
# https://github.com/actions/setup-python/issues/505#issuecomment-1273013236
|
|
|
|
name: poetry-install-with-caching
|
|
|
|
description: Poetry install with support for caching of dependency groups.
|
|
|
|
|
|
|
|
inputs:
|
|
|
|
python-version:
|
|
|
|
description: Python version, supporting MAJOR.MINOR only
|
|
|
|
required: true
|
|
|
|
|
|
|
|
poetry-version:
|
|
|
|
description: Poetry version
|
|
|
|
required: true
|
|
|
|
|
|
|
|
cache-key:
|
|
|
|
description: Cache key to use for manual handling of caching
|
|
|
|
required: true
|
|
|
|
|
|
|
|
working-directory:
|
2023-08-22 19:59:22 +00:00
|
|
|
description: Directory whose poetry.lock file should be cached
|
|
|
|
required: true
|
2023-05-10 13:35:07 +00:00
|
|
|
|
|
|
|
runs:
|
|
|
|
using: composite
|
|
|
|
steps:
|
2024-01-01 22:02:43 +00:00
|
|
|
- uses: actions/setup-python@v5
|
2023-09-03 23:08:43 +00:00
|
|
|
name: Setup python ${{ inputs.python-version }}
|
2024-01-10 16:59:43 +00:00
|
|
|
id: setup-python
|
2023-05-10 13:35:07 +00:00
|
|
|
with:
|
|
|
|
python-version: ${{ inputs.python-version }}
|
|
|
|
|
2024-02-06 20:55:01 +00:00
|
|
|
- uses: actions/cache@v4
|
2023-09-05 18:03:03 +00:00
|
|
|
id: cache-bin-poetry
|
|
|
|
name: Cache Poetry binary - Python ${{ inputs.python-version }}
|
|
|
|
env:
|
|
|
|
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "1"
|
|
|
|
with:
|
|
|
|
path: |
|
|
|
|
/opt/pipx/venvs/poetry
|
|
|
|
# This step caches the poetry installation, so make sure it's keyed on the poetry version as well.
|
|
|
|
key: bin-poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.poetry-version }}
|
2023-05-10 13:35:07 +00:00
|
|
|
|
2023-09-05 19:47:58 +00:00
|
|
|
- name: Refresh shell hashtable and fixup softlinks
|
|
|
|
if: steps.cache-bin-poetry.outputs.cache-hit == 'true'
|
2023-05-10 13:35:07 +00:00
|
|
|
shell: bash
|
2023-08-21 21:59:10 +00:00
|
|
|
env:
|
|
|
|
POETRY_VERSION: ${{ inputs.poetry-version }}
|
|
|
|
PYTHON_VERSION: ${{ inputs.python-version }}
|
2023-09-05 18:03:03 +00:00
|
|
|
run: |
|
|
|
|
set -eux
|
2023-09-05 19:47:58 +00:00
|
|
|
|
|
|
|
# Refresh the shell hashtable, to ensure correct `which` output.
|
2023-09-05 18:03:03 +00:00
|
|
|
hash -r
|
2023-09-05 19:47:58 +00:00
|
|
|
|
|
|
|
# `actions/cache@v3` doesn't always seem able to correctly unpack softlinks.
|
|
|
|
# Delete and recreate the softlinks pipx expects to have.
|
|
|
|
rm /opt/pipx/venvs/poetry/bin/python
|
|
|
|
cd /opt/pipx/venvs/poetry/bin
|
|
|
|
ln -s "$(which "python$PYTHON_VERSION")" python
|
|
|
|
chmod +x python
|
|
|
|
cd /opt/pipx_bin/
|
|
|
|
ln -s /opt/pipx/venvs/poetry/bin/poetry poetry
|
|
|
|
chmod +x poetry
|
|
|
|
|
|
|
|
# Ensure everything got set up correctly.
|
2023-09-05 18:03:03 +00:00
|
|
|
/opt/pipx/venvs/poetry/bin/python --version
|
|
|
|
/opt/pipx_bin/poetry --version
|
|
|
|
|
2023-09-05 19:47:58 +00:00
|
|
|
- name: Install poetry
|
|
|
|
if: steps.cache-bin-poetry.outputs.cache-hit != 'true'
|
|
|
|
shell: bash
|
|
|
|
env:
|
|
|
|
POETRY_VERSION: ${{ inputs.poetry-version }}
|
|
|
|
PYTHON_VERSION: ${{ inputs.python-version }}
|
2024-01-10 16:59:43 +00:00
|
|
|
# Install poetry using the python version installed by setup-python step.
|
|
|
|
run: pipx install "poetry==$POETRY_VERSION" --python '${{ steps.setup-python.outputs.python-path }}' --verbose
|
2023-09-05 19:47:58 +00:00
|
|
|
|
2023-08-22 19:59:22 +00:00
|
|
|
- name: Restore pip and poetry cached dependencies
|
2024-02-06 20:55:01 +00:00
|
|
|
uses: actions/cache@v4
|
2023-05-10 13:35:07 +00:00
|
|
|
env:
|
2023-08-22 16:11:38 +00:00
|
|
|
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "4"
|
2023-08-18 16:55:33 +00:00
|
|
|
WORKDIR: ${{ inputs.working-directory == '' && '.' || inputs.working-directory }}
|
2023-05-10 13:35:07 +00:00
|
|
|
with:
|
|
|
|
path: |
|
2023-08-22 19:59:22 +00:00
|
|
|
~/.cache/pip
|
2023-05-10 13:35:07 +00:00
|
|
|
~/.cache/pypoetry/virtualenvs
|
|
|
|
~/.cache/pypoetry/cache
|
|
|
|
~/.cache/pypoetry/artifacts
|
2023-08-18 16:55:33 +00:00
|
|
|
${{ env.WORKDIR }}/.venv
|
2023-08-22 19:59:22 +00:00
|
|
|
key: py-deps-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}-${{ inputs.cache-key }}-${{ hashFiles(format('{0}/**/poetry.lock', env.WORKDIR)) }}
|