Closed MarvinXu closed 1 year ago
If you want to skip it, just add the same if
condition on the step in the workflow :slightly_smiling_face:
Thanks! I modified my yml file, and it worked!
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- 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
installer-parallel: true
So if it's ok to skip it, can I make a PR to update the doc?
Yes, sure that would be great! :clap:
There is one problem though, if you skip poetry install, the passed-in poetry config will not be set.
I manually cached .venv
directory in my project, so after I updated my denpendencies, there was an error resaving venv cache because the default venv path is {cache-dir}/virtualenvs
:
Warning: Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.
I fixed it by manually run poetry config
:
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- 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
- run: |
poetry config virtualenvs.in-project true
#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
#----------------------------------------------
# run scripts
#----------------------------------------------
- name: Run scripts
run: |
poetry run start
How long does that take? Seems like the original configuration might be less complex?
How long does that take? Seems like the original configuration might be less complex?
Sorry I didn't quite get it. The first config is only part of my config. In the second config I only changed with
command under install-poetry
to run
command~
Here is the whole job: https://github.com/MarvinXu/my-python-scripts/actions/runs/3664946365/jobs/6195696592
The reason for skipping the install-step was to save the 3 seconds it took, right :slightly_smiling_face: Now, with the new step, it's taking roughly the same time
@sondrelg Ok, I get your point. Thank you!
@sondrelg Am I being right in saying that the install-poetry
action does not save the poetry config in the cache? So everytime I load the cached poetry version, I have to re-apply the config specified in the action options if I want my poetry environment to be loaded correctly if the dependencies are cached correctly (and thus I won't be doing a poetry install
):
- name: Load cached Poetry installation
uses: actions/cache@v3
id: cached-poetry
with:
path: ~/.local # the path depends on the OS
key: poetry-1
- name: Install poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1.3.3
with:
version: 1.4.2
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Reset poetry config <------------------------------------------
run: |
poetry config virtualenvs.in-project true
poetry config virtualenvs-create true
poetry config installer-parallel true
- name: Install API dependencies
if: steps.cached-api-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-ansi
- name: Run lint
run: source $(poetry env info --path)/bin/activate && make lint
No, that should not be right. The config should persist for the entire workflow 👍
As you can see, poetry cache works, but it still takes 3s to "Install Poetry". Is it possible to skip this step when cache hit, just like "Install dependencies"?