diff --git a/README.md b/README.md index fe79b675..7a19e3a8 100644 --- a/README.md +++ b/README.md @@ -509,6 +509,51 @@ jobs: The directory to cache will depend on the operating system of the runner. +Note that when the cache hits and the *Install Poetry* step is skipped, all configurations done during install are skipped. Therefore, the loaded Poetry will run with default settings. + +This may break the cache of Python dependencies when the `.lock` file changes and the Poetry *install* is recovered from an old cache. For example, if you set + +```yaml +with: + virtualenvs-in-project: true +``` + +and have a cache step for `.venv`, the `install-poetry` will run and configure Poetry to create the venv in `.venv` *the first time it is run*. Dependencies will install and will be cached. However, when you update your `.lock` file, the Poetry installation will be recovered from cache, and a new venv will be created in the default Poetry location (not `.venv`, because the install poetry step doesn't cache the settings), so the cache venv step will fail (as there's no `.venv` directory to cache). + +To remedy this, you should use this instead + +```yaml +name: test + +on: pull_request + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + - name: Set up python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Load cached Poetry installation + id: cached-poetry + uses: actions/cache@v3 + with: + path: ~/.local # the path depends on the OS + key: poetry-0 # increment to reset cache + - name: Install Poetry + if: steps.cached-poetry.outputs.cache-hit != 'true' + uses: snok/install-poetry@v1 + with: + virtualenvs-create: true + virtualenvs-in-project: true + - name: Configure poetry + if: steps.cached-poetry.outputs.cache-hit == 'true' + run: poetry config virtualenvs.in-project true +``` + ## Contributing Contributions are always welcome; submit a PR!