kor

Форк
0
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
6
name: poetry-install-with-caching
7
description: Poetry install with support for caching of dependency groups.
8

9
inputs:
10
  python-version:
11
    description: Python version, supporting MAJOR.MINOR only
12
    required: true
13

14
  poetry-version:
15
    description: Poetry version
16
    required: true
17

18
  cache-key:
19
    description: Cache key to use for manual handling of caching
20
    required: true
21

22
  working-directory:
23
    description: Directory whose poetry.lock file should be cached
24
    required: true
25

26
runs:
27
  using: composite
28
  steps:
29
    - uses: actions/setup-python@v4
30
      name: Setup python ${{ inputs.python-version }}
31
      with:
32
        python-version: ${{ inputs.python-version }}
33

34
    - uses: actions/cache@v3
35
      id: cache-bin-poetry
36
      name: Cache Poetry binary - Python ${{ inputs.python-version }}
37
      env:
38
        SEGMENT_DOWNLOAD_TIMEOUT_MIN: "1"
39
      with:
40
        path: |
41
          /opt/pipx/venvs/poetry
42
        # This step caches the poetry installation, so make sure it's keyed on the poetry version as well.
43
        key: bin-poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.poetry-version }}
44

45
    - name: Refresh shell hashtable and fixup softlinks
46
      if: steps.cache-bin-poetry.outputs.cache-hit == 'true'
47
      shell: bash
48
      env:
49
        POETRY_VERSION: ${{ inputs.poetry-version }}
50
        PYTHON_VERSION: ${{ inputs.python-version }}
51
      run: |
52
        set -eux
53

54
        # Refresh the shell hashtable, to ensure correct `which` output.
55
        hash -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.
59
        rm /opt/pipx/venvs/poetry/bin/python
60
        cd /opt/pipx/venvs/poetry/bin
61
        ln -s "$(which "python$PYTHON_VERSION")" python
62
        chmod +x python
63
        cd /opt/pipx_bin/
64
        ln -s /opt/pipx/venvs/poetry/bin/poetry poetry
65
        chmod +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
72
      if: steps.cache-bin-poetry.outputs.cache-hit != 'true'
73
      shell: bash
74
      env:
75
        POETRY_VERSION: ${{ inputs.poetry-version }}
76
        PYTHON_VERSION: ${{ inputs.python-version }}
77
      run: pipx install "poetry==$POETRY_VERSION" --python "python$PYTHON_VERSION" --verbose
78

79
    - name: Restore pip and poetry cached dependencies
80
      uses: actions/cache@v3
81
      env:
82
        SEGMENT_DOWNLOAD_TIMEOUT_MIN: "4"
83
        WORKDIR: ${{ inputs.working-directory == '' && '.' || inputs.working-directory }}
84
      with:
85
        path: |
86
          ~/.cache/pip
87
          ~/.cache/pypoetry/virtualenvs
88
          ~/.cache/pypoetry/cache
89
          ~/.cache/pypoetry/artifacts
90
          ${{ env.WORKDIR }}/.venv
91
        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)) }}
92

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.