kor
91 строка · 3.2 Кб
1# An action for setting up poetry install with caching.
2# Using a custom action since the default action does not
3# take poetry install groups into account.
4# Action code from:
5# https://github.com/actions/setup-python/issues/505#issuecomment-1273013236
6name: poetry-install-with-caching
7description: Poetry install with support for caching of dependency groups.
8
9inputs:
10python-version:
11description: Python version, supporting MAJOR.MINOR only
12required: true
13
14poetry-version:
15description: Poetry version
16required: true
17
18cache-key:
19description: Cache key to use for manual handling of caching
20required: true
21
22working-directory:
23description: Directory whose poetry.lock file should be cached
24required: true
25
26runs:
27using: composite
28steps:
29- uses: actions/setup-python@v4
30name: Setup python ${{ inputs.python-version }}
31with:
32python-version: ${{ inputs.python-version }}
33
34- uses: actions/cache@v3
35id: cache-bin-poetry
36name: Cache Poetry binary - Python ${{ inputs.python-version }}
37env:
38SEGMENT_DOWNLOAD_TIMEOUT_MIN: "1"
39with:
40path: |
41/opt/pipx/venvs/poetry
42# This step caches the poetry installation, so make sure it's keyed on the poetry version as well.
43key: bin-poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.poetry-version }}
44
45- name: Refresh shell hashtable and fixup softlinks
46if: steps.cache-bin-poetry.outputs.cache-hit == 'true'
47shell: bash
48env:
49POETRY_VERSION: ${{ inputs.poetry-version }}
50PYTHON_VERSION: ${{ inputs.python-version }}
51run: |
52set -eux
53
54# Refresh the shell hashtable, to ensure correct `which` output.
55hash -r
56
57# `actions/cache@v3` doesn't always seem able to correctly unpack softlinks.
58# Delete and recreate the softlinks pipx expects to have.
59rm /opt/pipx/venvs/poetry/bin/python
60cd /opt/pipx/venvs/poetry/bin
61ln -s "$(which "python$PYTHON_VERSION")" python
62chmod +x python
63cd /opt/pipx_bin/
64ln -s /opt/pipx/venvs/poetry/bin/poetry poetry
65chmod +x poetry
66
67# Ensure everything got set up correctly.
68/opt/pipx/venvs/poetry/bin/python --version
69/opt/pipx_bin/poetry --version
70
71- name: Install poetry
72if: steps.cache-bin-poetry.outputs.cache-hit != 'true'
73shell: bash
74env:
75POETRY_VERSION: ${{ inputs.poetry-version }}
76PYTHON_VERSION: ${{ inputs.python-version }}
77run: pipx install "poetry==$POETRY_VERSION" --python "python$PYTHON_VERSION" --verbose
78
79- name: Restore pip and poetry cached dependencies
80uses: actions/cache@v3
81env:
82SEGMENT_DOWNLOAD_TIMEOUT_MIN: "4"
83WORKDIR: ${{ inputs.working-directory == '' && '.' || inputs.working-directory }}
84with:
85path: |
86~/.cache/pip
87~/.cache/pypoetry/virtualenvs
88~/.cache/pypoetry/cache
89~/.cache/pypoetry/artifacts
90${{ env.WORKDIR }}/.venv
91key: py-deps-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}-${{ inputs.cache-key }}-${{ hashFiles(format('{0}/**/poetry.lock', env.WORKDIR)) }}
92