snok / install-poetry

Github action for installing and configuring Poetry
MIT License
572 stars 53 forks source link

The `with` `virtualenvs-in-project` setting does not seem to work for me #124

Closed HarrisonWilde closed 1 year ago

HarrisonWilde commented 1 year ago

My action looks like this:

name: Build MkDocs

on: 
  push:
    branches: [main]

permissions:
  contents: write

jobs:
  deploy:

    runs-on: ubuntu-latest

    steps:
      - name: Check-out repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Setup python
        id: setup-python
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'
      - name: Load cached Poetry installation
        id: cached-poetry
        uses: actions/cache@v3
        with:
          path: ~/.local
          key: poetry-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}
      - name: Install Poetry
        if: steps.cached-poetry.outputs.cache-hit != 'true'
        uses: snok/install-poetry@v1
      - name: Configure Poetry
        run: poetry config virtualenvs.in-project true
      - 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') }}
      - name: Install dependencies
        if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
        run: poetry install --no-interaction --no-root --with docs
      - name: Install project
        run: poetry install --no-interaction --with docs
      - name: Deploy MkDocs
        run: |
          source .venv/bin/activate
          mkdocs gh-deploy --force --clean --verbose

I used to instead use the with usage underneath the action, but I kept getting an error that on the "Install Dependencies" stage of the workflow it was looking for a virtual env outside of the project folder. Is this a problem with caching the install?

sondrelg commented 1 year ago

I don't have a clear understanding of what is wrong. Could you elaborate a little? Even better, do you have a link to a failing workflow?

HarrisonWilde commented 1 year ago

Sure, here is a link to a failing workflow: https://github.com/nhsx/NHSSynth/actions/runs/4947627734/jobs/8847264713

So the problem is something with the cacheing of the poetry installation I think. But I have always had that with option set meaning the venv should be in the project. However, you can see in the readout from that workflow that it is looking elsewhere. Hence my "fix" of manually setting the config. Just thought I would open the convo to attempt to solve this.

sondrelg commented 1 year ago

I know Github has had some issues today. Would you mind invalidating the cache and trying once more, just to rule out Github being the cause?

tcrasset commented 1 year ago

I seem to have read somewhere that you shouldn't specify .venv as the location when using virtualenvs.in-project=true, as .venv is already the default location for installing the dependencies in the project.

Also, make sure that in the caching step, you are using the correct path. I think the path is relative to the github workspace, so:

sondrelg commented 1 year ago

Did you manage to resolve this? Closing for now, but feel free to update the issue later :+1: