action.yml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. name: "Setup Python and Poetry"
  2. description: "setup Python and Poetry with caches"
  3. inputs:
  4. os:
  5. description: "Operating system to use"
  6. required: false
  7. default: "ubuntu-latest"
  8. python-version:
  9. description: "Python version to use"
  10. required: true
  11. venv-id:
  12. description: "ID to identify cached environment (should be unique from other steps)"
  13. required: true
  14. poetry-dependency-install-flags:
  15. description: "Flags to pass to poetry when running `poetry install --no-interaction --no-root`"
  16. required: true
  17. run-poetry-install:
  18. description: "Should we run the poetry install steps"
  19. required: false
  20. default: true
  21. runs:
  22. using: "composite"
  23. steps:
  24. - name: Install poetry
  25. shell: bash
  26. run: |
  27. pipx install poetry
  28. which poetry
  29. poetry --version # Check poetry installation
  30. - name: Set up Python ${{ inputs.python-version }}
  31. id: setup-python
  32. uses: actions/setup-python@v5
  33. with:
  34. python-version: ${{ inputs.python-version }}
  35. cache: poetry
  36. - name: Set Poetry environment
  37. shell: bash
  38. run: |
  39. # This line used to be needed, but seems to have been
  40. # sorted with newer poetry versions. We can still check whether
  41. # the right version of python is used by looking at the output of
  42. # `poetry run which python` below and whether the right version
  43. # of python is used in the tests (or whatever step is being done)
  44. # poetry env use "python${{ inputs.python-version }}"
  45. poetry config virtualenvs.create true
  46. poetry config virtualenvs.in-project true
  47. - name: Install dependencies
  48. if: ${{ (inputs.run-poetry-install == 'true') && (steps.setup-python.outputs.cache-hit != 'true') }}
  49. shell: bash
  50. run: |
  51. poetry install --no-interaction --no-root ${{ inputs.poetry-dependency-install-flags }}
  52. # Now run same command but let the package install too
  53. - name: Install package
  54. # To ensure that the package is always installed, this step is run even if the cache was hit
  55. if: ${{ inputs.run-poetry-install == 'true' }}
  56. shell: bash
  57. run: |
  58. poetry install --no-interaction ${{ inputs.poetry-dependency-install-flags }}
  59. poetry run python --version # Check python version just in case