From 196b30071c13bcc5b44aee072a79756edb10e259 Mon Sep 17 00:00:00 2001 From: Barak Korren Date: Thu, 8 Dec 2022 13:45:08 +0200 Subject: [PATCH] Refactor workflows for builtin caching It turns out the setup-python can cache Poetry environments on its own --- .github/workflows/pr.yaml | 56 +++++++++++++-------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 0f08bb0..e23cccd 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -9,27 +9,16 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 3 - - name: Set up Python - uses: actions/setup-python@v4 + - name: Install poetry, pre-commit and the dynamic-versioning plugin + run: | + pipx install poetry + poetry self add "poetry-dynamic-versioning[plugin]" + pipx install pre-commit + - uses: actions/setup-python@v4 with: python-version: "3.9" - - name: Install poetry and pre-commit - run: pip install --user poetry pre-commit - - name: cache poetry virtualenv - uses: actions/cache@v1 - id: cache - with: - path: ~/.virtualenvs - key: poetry-${{ hashfiles('**/poetry.lock') }} - restore-keys: | - poetry-${{ hashfiles('**/poetry.lock') }} - - name: set poetry config - run: | - poetry config virtualenvs.in-project false - poetry config virtualenvs.path ~/.virtualenvs - - name: Setup environment - run: poetry install - if: steps.cache.outputs.cache-hit != 'true' + cache: 'poetry' + - run: poetry install - name: Run pre-commit tests run: pre-commit run --from-ref HEAD^ --to-ref HEAD pytest: @@ -38,26 +27,17 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.9" - - name: Install poetry - run: pip install --user poetry - - name: cache poetry virtualenv - uses: actions/cache@v1 - id: cache with: - path: ~/.virtualenvs - key: poetry-${{ hashfiles('**/poetry.lock') }} - restore-keys: | - poetry-${{ hashfiles('**/poetry.lock') }} - - name: set poetry config + fetch-depth: 3 + - name: Install poetry, pre-commit and the dynamic-versioning plugin run: | - poetry config virtualenvs.in-project false - poetry config virtualenvs.path ~/.virtualenvs - - name: Setup environment - run: poetry install - if: steps.cache.outputs.cache-hit != 'true' + pipx install poetry + poetry self add "poetry-dynamic-versioning[plugin]" + pipx install pre-commit + - uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: 'poetry' + - run: poetry install - name: Run PyTest run: poetry run pytest -v