|
| 1 | +name: Setup Python and Poetry |
| 2 | +description: Setup Python and Poetry. Cribbed from snok/install-poetry. |
| 3 | +inputs: |
| 4 | + python-version: |
| 5 | + description: Python version to pass to actions/setup-python@v2. |
| 6 | + required: false |
| 7 | + default: "3.x" |
| 8 | + poetry-version: |
| 9 | + description: Poetry version to install via pip. |
| 10 | + required: false |
| 11 | + default: "1.1.12" |
| 12 | +runs: |
| 13 | + using: composite |
| 14 | + steps: |
| 15 | + - name: Setup Python |
| 16 | + id: setup-python |
| 17 | + uses: actions/setup-python@v2 |
| 18 | + with: |
| 19 | + python-version: ${{ inputs.python-version }} |
| 20 | + |
| 21 | + - name: Check for poetry lock |
| 22 | + run: "test -f poetry.lock || (echo No lock file! && false)" |
| 23 | + shell: bash |
| 24 | + |
| 25 | + # Install poetry. It takes ~10seconds for a clean pip install, most of which is |
| 26 | + # the installation rather than the downloading. So instead, we cache the user-base |
| 27 | + # directory (~/.local). For this to be safe: |
| 28 | + # - we must not write to `.local` as part of the CI |
| 29 | + # - we must not install anything with the system `pip` other than poetry. |
| 30 | + # Based on the writeup at: |
| 31 | + # https://github.com/snok/install-poetry/blob/main/README.md#caching-the-poetry-installation |
| 32 | + - name: Locate user site |
| 33 | + id: site-user-base |
| 34 | + run: echo "::set-output name=dir::$(python -m site --user-base)" |
| 35 | + shell: bash |
| 36 | + |
| 37 | + - name: Restore/cache poetry installation |
| 38 | + id: poetry-install-cache |
| 39 | + uses: actions/cache@v2 |
| 40 | + with: |
| 41 | + path: ${{ steps.site-user-base.outputs.dir }} |
| 42 | + key: poetry-install-cache-${{ steps.setup-python.outputs.python-version }}-${{ inputs.poetry-version }} |
| 43 | + |
| 44 | + - name: Install poetry from scratch |
| 45 | + if: "${{ steps.poetry-install-cache.outputs.cache-hit != 'true' }}" |
| 46 | + run: python -m pip install --user poetry==${{ inputs.poetry-version }} |
| 47 | + shell: bash |
| 48 | + |
| 49 | + # Poetry manages a virtualenv for us. We're going to cache that too. |
| 50 | + # Again, we're following snok/install-poetry's README. |
| 51 | + - name: Locate poetry venv |
| 52 | + id: poetry-venvs |
| 53 | + run: echo "::set-output name=dir::$(python -m poetry config virtualenvs.path)" |
| 54 | + shell: bash |
| 55 | + |
| 56 | + - name: Restore/cache poetry venv |
| 57 | + id: poetry-venv-cache |
| 58 | + uses: actions/cache@v2 |
| 59 | + with: |
| 60 | + path: ${{ steps.poetry-venvs.outputs.dir }} |
| 61 | + key: poetry-venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} |
| 62 | + |
| 63 | + - name: Install dependencies |
| 64 | + if: "${{ steps.poetry-venv-cache.outputs.cache-hit != 'true' }}" |
| 65 | + run: poetry install --no-interaction --no-root |
| 66 | + shell: bash |
| 67 | + |
| 68 | + # (Not sure if this is needed if there's a cache hit?) |
| 69 | + - name: Install project |
| 70 | + run: poetry install --no-interaction |
| 71 | + shell: bash |
| 72 | + |
| 73 | + # For debugging---let's just check what we're working with. |
| 74 | + - name: Dump virtual environment |
| 75 | + run: | |
| 76 | + poetry env info |
| 77 | + poetry show |
| 78 | + shell: bash |
0 commit comments