Giter Site home page Giter Site logo

Comments (12)

Hasenpfote avatar Hasenpfote commented on June 5, 2024 2

@FeeeeK
If POERTY_HOME is specified as anything other than the default, the cache process fails.

Below is an example that worked well for me.

details
name: Poetry caching on Windows with install-poetry

on: workflow_dispatch

permissions:
  contents: read

env:
  config-poetry-version: '' # Empty is the latest version.
  #config-poetry-path: ${USERPROFILE}\.local\bin # An error occurs.
  config-poetry-path: ${USERPROFILE}\.local\venv\Scripts
  config-poetry-cache-paths: |
    ~\.local\VERSION
    #~\.local\bin\poetry.exe # An error occurs.
    ~\.local\venv
  config-poetry-cache-key-fmt: 'd-poetry-{0}-{1}-python-{2}'
  config-venv-cache-key-fmt: 'd-venv-{0}-python-{1}-{2}'

jobs:
  create-cache:
    name: caching 1/2 - ${{ matrix.os }}, ${{ matrix.python-version }}
    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest]
        python-version: ['3.8']

    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Set up Python ${{ matrix.python-version }}
        id: setup-python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}

      - name: Load cached Poetry installation
        id: cached-poetry
        uses: actions/cache@v3
        with:
          path: ${{ env.config-poetry-cache-paths }}
          key: ${{ format(env.config-poetry-cache-key-fmt, env.config-poetry-version, matrix.os, steps.setup-python.outputs.python-version) }}

      - name: Install Poetry ${{ env.config-poetry-version }} for Windows
        if: steps.cached-poetry.outputs.cache-hit != 'true'
        env:
          POETRY_VERSION: ${{ env.config-poetry-version }}
        uses: snok/install-poetry@v1

      - name: Add Poetry to the PATH environment variable
        shell: bash
        run: |
          echo "${{ env.config-poetry-path }}" >> $GITHUB_PATH

      - name: Debug
        shell: cmd
        run: |
          set PATH

      - 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: ${{ format(env.config-venv-cache-key-fmt, matrix.os, steps.setup-python.outputs.python-version, hashFiles('**/poetry.lock')) }}

      - name: Set the environment used by Poetry on Windows 1/2
        if: runner.os == 'Windows' && steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
        id: py
        shell: bash
        run: |
          VER='${{ steps.setup-python.outputs.python-version }}'
          ARR=(${VER//./ })
          echo "tag=${ARR[0]}.${ARR[1]}" >> $GITHUB_OUTPUT

      - name: Set the environment used by Poetry on Windows 2/2
        if: runner.os == 'Windows' && steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
        shell: bash
        env:
          PY_PYTHON: ${{ steps.py.outputs.tag }}
        run: |
          poetry env use py

      - name: Install dependencies
        if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
        run: poetry install --no-interaction --no-root --with dev

      - name: Test with pytest
        run: |
          poetry run tox -e py

  # Same as above.
  load-cache:
    needs: create-cache
    name: caching 2/2 - ${{ matrix.os }}, ${{ matrix.python-version }}

    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest]
        python-version: ['3.8']

    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Set up Python ${{ matrix.python-version }}
        id: setup-python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}

      - name: Load cached Poetry installation
        id: cached-poetry
        uses: actions/cache@v3
        with:
          path: ${{ env.config-poetry-cache-paths }}
          key: ${{ format(env.config-poetry-cache-key-fmt, env.config-poetry-version, matrix.os, steps.setup-python.outputs.python-version) }}

      # No need if you have cached Poetry.
      #- name: Install Poetry ${{ env.config-poetry-version }} for Windows
      #  if: steps.cached-poetry.outputs.cache-hit != 'true'
      #  env:
      #    POETRY_VERSION: ${{ env.config-poetry-version }}
      #  uses: snok/install-poetry@v1

      - name: Add Poetry to the PATH environment variable
        shell: bash
        run: |
          echo "${{ env.config-poetry-path }}" >> $GITHUB_PATH

      - 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: ${{ format(env.config-venv-cache-key-fmt, matrix.os, steps.setup-python.outputs.python-version, hashFiles('**/poetry.lock')) }}

      # No need if you have cached venv.
      #- name: Install dependencies
      #  if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
      #  run: poetry install --no-interaction --no-root --with dev

      - name: Test with pytest
        run: |
          poetry run tox -e py

If you remove the commented parts, you will get the following error.
2022-12-27 00 44 08 github com e8dc679d547d

LOG: Poetry caching on Windows with install-poetry

EDIT
I found an issue that might be relevant.

In the end, though, it seems to require a bit of work.

...
env:
  config-poetry-version: '' # Empty is the latest version.
  #config-poetry-path: ${USERPROFILE}\.local\bin # An error occurs.
  config-poetry-path: ${USERPROFILE}\.local\venv\Scripts
  config-poetry-cache-paths: |
    ~\.local\VERSION
    ~\.local\bin\poetry.exe # An error occurs.
    ~\.local\venv
...
      - name: Load cached Poetry installation
        id: cached-poetry
        uses: actions/[email protected]
...

from install-poetry.

JonasKs avatar JonasKs commented on June 5, 2024 1

At, no it probably isn’t, a bit early in the morning and I didn’t read the error properly. 🥱

from install-poetry.

FeeeeK avatar FeeeeK commented on June 5, 2024 1

My build also stopped working on Windows, maybe the same issue? https://github.com/DigiScore/neoscore/actions/runs/3411874104/jobs/5676638880

You need to set the default shell to bash
image

from install-poetry.

ajyoon avatar ajyoon commented on June 5, 2024 1

@FeeeeK that did the trick, thank you!

from install-poetry.

JonasKs avatar JonasKs commented on June 5, 2024

Is the poetry/Python version the same combination as you’d expect in your cache?

Feel like we’ve seen this exact thing before, but I may be wrong.

from install-poetry.

JonasKs avatar JonasKs commented on June 5, 2024

Are you allowed to go directly to the c-path? Seems like poetry also acknowledges it’s already installed, but how you attempt to access it with a full path isn’t working.

from install-poetry.

FeeeeK avatar FeeeeK commented on June 5, 2024

This problem is only with windows, everything is normal on other operating systems
image

image

from install-poetry.

FeeeeK avatar FeeeeK commented on June 5, 2024

Here are the full logs
https://github.com/FeeeeK/vkbottle/actions/runs/3391518585

from install-poetry.

sondrelg avatar sondrelg commented on June 5, 2024

What happens if you update the cache key (e.g., by appending -1 to the end of key). Does it work the first and second run?

I suspect this is related to #104 (comment)

from install-poetry.

FeeeeK avatar FeeeeK commented on June 5, 2024

It works at first run, but fails after re-run

https://github.com/FeeeeK/vkbottle/actions/runs/3404825088/jobs/5662355031

image
image

from install-poetry.

sondrelg avatar sondrelg commented on June 5, 2024

Gave it a crack, but wasn't successful https://github.com/snok/install-poetry/actions/runs/3405983224

After looking over the readme I see I wrote that "it just doesn't work" a while back (ref) 😄 so I guess this has never worked - at least not to my knowledge. Weird though.

If anyone wants to take a look at this, PRs are welcome 👍

from install-poetry.

ajyoon avatar ajyoon commented on June 5, 2024

My build also stopped working on Windows, maybe the same issue? https://github.com/DigiScore/neoscore/actions/runs/3411874104/jobs/5676638880

from install-poetry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.