Skip to content

Commit

Permalink
Merge pull request #672 from NatLibFi/fix-gh-actions-cache-for-py3.10
Browse files Browse the repository at this point in the history
Fix slow CI/CD runs for Python 3.10
  • Loading branch information
juhoinkinen authored Feb 13, 2023
2 parents d8dd8db + c10792c commit 3e8f42f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 52 deletions.
32 changes: 32 additions & 0 deletions .github/actions/prepare/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Prepare
description:
inputs:
python-version:
required: true
poetry-version:
required: true
outputs:
cache-matched-key:
value: ${{ steps.restore-cache.outputs.cache-matched-key }}
runs:
using: "composite"
steps:
- name: Restore cached Poetry installation and its cache
id: restore-cache
uses: actions/cache/restore@v3
with:
path: |
~/.cache/pipx/venvs
~/.local/bin
~/.cache/pypoetry/
key: ignore-me
restore-keys: |
poetry-installation-and-cache-${{ inputs.python-version }}-${{ inputs.poetry-version }}-
- name: Install Poetry
shell: bash
run: |
pipx install poetry==${{ inputs.poetry-version }}
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@5ccb29d8773c3f3f653e1705f474dfaa8a06a912 # v4.4.0
with:
python-version: ${{ inputs.python-version }}
73 changes: 21 additions & 52 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,13 @@ jobs:
lint:
runs-on: ubuntu-latest
name: lint with isort, Black & flake8
env:
PYTHON_VERSION: "3.10"
steps:

- uses: actions/checkout@v3
- name: Load cached Poetry installation and repositories info
uses: actions/cache@v3
with:
path: |
~/.cache/pipx/venvs
~/.local/bin
~/.cache/pypoetry/cache/repositories
key: poetry-installation-and-repos-${{ env.PYTHON_VERSION }}-${{ env.POETRY_VERSION }}
- name: Install Poetry
run: |
pipx install poetry==$POETRY_VERSION
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@5ccb29d8773c3f3f653e1705f474dfaa8a06a912 # v4.4.0
- name: "Prepare: restore caches, install Poetry, set up Python"
uses: ./.github/actions/prepare
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'poetry'
cache-dependency-path: 'pyproject.toml'
python-version: "3.10"
poetry-version: ${{ env.POETRY_VERSION }}
- name: Install Python dev dependencies
run: |
poetry install --only dev
Expand All @@ -58,32 +43,19 @@ jobs:
matrix:
python-version: ["3.8", "3.9", "3.10"]
name: test on Python ${{ matrix.python-version }}

steps:
- uses: actions/checkout@v3
- name: Install system packages

run: |
sudo apt-get install \
libvoikko1 \
voikko-fi
- name: Load cached Poetry installation and repositories info
uses: actions/cache@v3
with:
path: |
~/.cache/pipx/venvs
~/.local/bin
~/.cache/pypoetry/cache/repositories
key: poetry-installation-and-repos-${{ matrix.python-version }}-${{ env.POETRY_VERSION }}
- name: Install Poetry
run: |
pipx install poetry==$POETRY_VERSION
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@5ccb29d8773c3f3f653e1705f474dfaa8a06a912 # v4.4.0
- name: "Prepare: restore caches, install Poetry, set up Python"
id: prepare
uses: ./.github/actions/prepare
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
cache-dependency-path: 'pyproject.toml'
poetry-version: ${{ env.POETRY_VERSION }}
- name: Install Python dependencies
run: |
# Selectively install the optional dependencies for some Python versions
Expand All @@ -102,12 +74,21 @@ jobs:
poetry install -E "nn omikuji yake";
fi
poetry run python -m nltk.downloader punkt
- name: Test with pytest
run: |
poetry run pytest --cov=./ --cov-report xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0
- name: Save cache
if: steps.prepare.outputs.cache-matched-key != format('poetry-installation-and-cache-{0}-{1}-{2}', matrix.python-version, env.POETRY_VERSION, hashFiles('**/poetry.lock'))
uses: actions/cache/save@v3
with:
path: |
~/.cache/pipx/venvs
~/.local/bin
~/.cache/pypoetry/
# A new key is created to update the cache if some dependency has been updated
key: poetry-installation-and-cache-${{ matrix.python-version }}-${{ env.POETRY_VERSION }}-${{ hashFiles('**/poetry.lock') }}

publish-docker-latest:
name: publish latest Docker image
Expand Down Expand Up @@ -143,23 +124,11 @@ jobs:
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
- name: Load cached Poetry installation and repositories info
uses: actions/cache@v3
with:
path: |
~/.cache/pipx/venvs
~/.local/bin
~/.cache/pypoetry/cache/repositories
key: poetry-installation-and-repos-${{ matrix.python-version }}-${{ env.POETRY_VERSION }}
- name: Install Poetry
run: |
pipx install poetry==$POETRY_VERSION
- name: Set up Python 3.9
uses: actions/setup-python@5ccb29d8773c3f3f653e1705f474dfaa8a06a912 # v4.4.0
- name: "Prepare: restore caches, install Poetry, set up Python"
uses: ./.github/actions/prepare
with:
python-version: '3.9'
cache: 'poetry'
cache-dependency-path: 'pyproject.toml'
poetry-version: ${{ env.POETRY_VERSION }}
- name: Build and publish distribution to PyPI
env:
POETRY_HTTP_BASIC_PYPI_USERNAME: __token__
Expand Down

0 comments on commit 3e8f42f

Please sign in to comment.