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

Cache CI environment so it doesn't need to be rebuilt each time #458

Closed
DaniBodor opened this issue Jul 4, 2023 · 2 comments
Closed

Cache CI environment so it doesn't need to be rebuilt each time #458

DaniBodor opened this issue Jul 4, 2023 · 2 comments
Labels
CI continuous integration stale issue not touched from too much time

Comments

@DaniBodor
Copy link
Collaborator

From this blog post.

Reuse

If you must run the CI, the best way to reduce its impact is limit the actual work that needs to be done.

With the cache action, you can cache dependencies and build outputs to make your workflows faster and thus more efficient. Maybe you need to compile some dependency, download and pre-compute some data, or set up your python environment via pip. These typically do not change much from run to run, so try to cache these where possible.

Caching your Python environment

Just the installation of the dependencies of some Python code via pip can be quite significant. Some libraries just seem to pull in an endless stream of dependencies. So, why don't we cache our entire Python environment?

Below is a snippet that we find effective in our workflows for Python code.

As the cache key, we use a combination of the Python directory name (this includes the version) in combination with the hash of the pyproject.toml, setup.cfg, or requirements.txt file. Whenever these get updated, the cache gets invalidated and regenerated.

This means we can also safely skip the pip install step if we hit the cache. Depending on the number of dependencies, this virtually eliminates the setup time of your workflow.

# tests.yaml
jobs:
  test:
    steps:
      ...
      
      - uses: actions/cache@v3
        id: cache-python-env
        with:
          path: ${{ env.pythonLocation }}
          key: ${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}

      - name: Install dependencies
        if: steps.cache-python-env.outputs.cache-hit != 'true'
        run: |
          python -m pip install -e .[develop]
@DaniBodor
Copy link
Collaborator Author

DaniBodor commented Jul 4, 2023

Was tried in PR #454 , but didn't work. Might be something to do with apt (and conda?) installs not being cached properly. Feedback from Stef was:

ik denk dat het bij deze regel misgaat: sudo apt-get install -y dssp
Je cachet deze locatie hier: path: ${{ env.pythonLocation }}
alles wat je met apt installeert staat ergens anders
Je zou dus de apt install in een andere step moeten zetten

@DaniBodor DaniBodor added the CI continuous integration label Jul 4, 2023
@github-actions
Copy link

github-actions bot commented Aug 4, 2023

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale issue not touched from too much time label Aug 4, 2023
@gcroci2 gcroci2 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI continuous integration stale issue not touched from too much time
Projects
Status: Done
Development

No branches or pull requests

2 participants