Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slow CI/CD runs for Python 3.10 #672

Merged
merged 12 commits into from
Feb 13, 2023

Conversation

juhoinkinen
Copy link
Member

@juhoinkinen juhoinkinen commented Feb 9, 2023

Lately the Python 3.10 test CI/CD jobs have been slow (~7 mins), because the Python dependencies have not been available from cache. First occurrence is in the CI/CD job #308, however it seems that the reason for the slow-down is introducing the linting job in PR #656, because this job has shared the cache keys with the Python 3.10 test job. This has prevented (re)creating/updating the cache by the test job (with the necessary optional dependencies); the "Post" steps for setup-python and caching steps in the test jobs have had errors like:

Failed to save: Unable to reserve cache with key setup-python-Linux-python-3.10.9-poetry-6025e512699131453ed16a5ae9a4be9139ae85329e34f47f750e6fb7af36d308, another job may be creating this cache. More details: Cache already exists.

To avoid this in the caching step the cache key is appended with -${{ github.job }} so the keys are now clearly different in lint and test jobs (poetry-installation-and-repos-3.10.8-1.2.0-lint vs. poetry-installation-and-repos-3.10-1.2.0-test). In the setup-python action the key cannot be specified, so the fix (for now) is to to pin the Python version to 3.10.8 in the linting job, but in the test job to more relaxed 3.10, which makes the keys different by the patch version (setup-python-Linux-python-3.10.8-poetry-<hash> vs. setup-python-Linux-python-3.10.9-poetry-<hash>).

Now restoring and saving cache is more controlled by using separate cache/restore and cache/save actions: restoring is performed before every job, but saving only after the test jobs that have various optional dependencies installed.

Also now the cache should be updated/recreated if some dependency has been updated, as the cache key includes hash of the poetry.lock. The cache restoration is based on "closest matching" key by using restore-keys (the plain key is not used at all).

The cache/save step is conditional: it is skipped if there are no changes in dependencies.

To make the workflow setup more manageable, the caching, Poetry install and Python setup steps are gathered in one composite action in .github/actions/prepare/action.yml file.

@juhoinkinen juhoinkinen added this to the 0.61 milestone Feb 9, 2023
@codecov
Copy link

codecov bot commented Feb 9, 2023

Codecov Report

Base: 99.56% // Head: 99.56% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (c10792c) compared to base (8a194c4).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #672   +/-   ##
=======================================
  Coverage   99.56%   99.56%           
=======================================
  Files          87       87           
  Lines        6145     6158   +13     
=======================================
+ Hits         6118     6131   +13     
  Misses         27       27           
Impacted Files Coverage Δ
annif/corpus/subject.py 100.00% <0.00%> (ø)
annif/util.py 98.57% <0.00%> (+0.26%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@juhoinkinen juhoinkinen marked this pull request as draft February 10, 2023 08:05
@juhoinkinen
Copy link
Member Author

Back to draft, there should be a better way to fix this.

@juhoinkinen juhoinkinen force-pushed the fix-gh-actions-cache-for-py3.10 branch from f6cffa3 to 39c46ea Compare February 10, 2023 13:21
@juhoinkinen
Copy link
Member Author

Force-pushed to drop very many unsuccessful commits trying to make caching step conditional, with lines like

if: steps.prepare.outputs.cache-matched-key != format('poetry-installation-and-cache-{0}-{1}-{2}', ${{ matrix.python-version }}, ${{ env.POETRY_VERSION }}, ${{ hashFiles('**/poetry.lock') }})

@juhoinkinen juhoinkinen marked this pull request as ready for review February 10, 2023 13:30
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@juhoinkinen juhoinkinen merged commit 3e8f42f into master Feb 13, 2023
@juhoinkinen juhoinkinen deleted the fix-gh-actions-cache-for-py3.10 branch February 13, 2023 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant