diff --git a/_doc-build-linux/action.yml b/_doc-build-linux/action.yml index 1476aa451..9db21de05 100644 --- a/_doc-build-linux/action.yml +++ b/_doc-build-linux/action.yml @@ -185,56 +185,134 @@ runs: sudo apt-get update sudo apt-get install -y poppler-utils - - name: "Check if requirements.txt file exists" + # ------------------------------------------------------------------------ + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Determine context. + + - name: "Determine GitHub environment variables" shell: bash run: | - echo "EXISTS_DOC_REQUIREMENTS=$(if [ -f ${{ inputs.requirements-file }} ]; then echo 'true'; else echo 'false'; fi)" >> $GITHUB_ENV + if [[ -f "pyproject.toml" ]] && grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then + echo "BUILD_BACKEND=$(echo 'poetry')" >> $GITHUB_ENV + echo "SPHINX_BUILD_MAKE=$(echo 'poetry run -- make')" >> $GITHUB_ENV + else + echo "BUILD_BACKEND=$(echo 'pip')" >> $GITHUB_ENV + echo "SPHINX_BUILD_MAKE=$(echo 'make')" >> $GITHUB_ENV + fi + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Build backend: ${{ env.BUILD_BACKEND }} + Sphinx build make: ${{ env.SPHINX_BUILD_MAKE }} + + # ------------------------------------------------------------------------ + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Set up python to build the documentation. + + # NOTE: Installation of poetry in a separate environment to the project to + # avoid situations in which both poetry and the project have shared + # dependencies with different version. This can lead to CICD failures. For + # more information, see https://github.com/ansys/actions/pull/560 + - name: "Add pipx/bin directory to Github Path" + if: env.BUILD_BACKEND == 'poetry' + shell: bash + run: echo "${{ runner.temp }}/pipx/bin" >> $GITHUB_PATH - - name: "Print previous output" + # NOTE: Poetry uses virtual environments when installing a project. As we + # want to control that creation, we store POETRY_VIRTUALENVS_CREATE=false + # in the GitHub environment. + - name: "Set poetry environment variable(s)" + if: env.BUILD_BACKEND == 'poetry' + shell: bash + run: echo "POETRY_VIRTUALENVS_CREATE=false" >> $GITHUB_ENV + + # NOTE: Install pipx in a location that can be used in following CICD jobs + # but ensure that poetry is installed in a temporary folder cleaned before + # and after each job. This way poetry is kinda "installed at system level" + # making it available in the following call and installed in a different + # environment from the project. + - name: "Install poetry and create a virtual environment" + if: env.BUILD_BACKEND == 'poetry' + shell: bash + run: | + python -m pip install pipx + python -m pipx install poetry + python -m venv .venv + env: + PIPX_BIN_DIR: ${{ runner.temp }}/pipx/bin + PIPX_HOME : ${{ runner.temp }}/pipx/home + + - name: "Create a virtual environment" + if: env.BUILD_BACKEND == 'pip' shell: bash run: | - echo "Output was found ${{ env.EXISTS_DOC_REQUIREMENTS }}" + python -m venv .venv + + # ------------------------------------------------------------------------ - name: "Update pip" shell: bash - run: python -m pip install -U pip + run: | + source .venv/bin/activate + python -m pip install -U pip + + - name: "Check if requirements.txt file exists" + shell: bash + run: | + echo "EXISTS_DOC_REQUIREMENTS=$(if [ -f ${{ inputs.requirements-file }} ]; then echo 'true'; else echo 'false'; fi)" >> $GITHUB_ENV - name: "Install documentation dependencies from requirements file" shell: bash if: env.EXISTS_DOC_REQUIREMENTS == 'true' run: | + source .venv/bin/activate python -m pip install -r ${{ inputs.requirements-file }} - name: "Install Python library" shell: bash if: inputs.skip-install == 'false' run: | - python -m pip install . + source .venv/bin/activate + if [[ ${{ env.BUILD_BACKEND }} == 'poetry' ]]; then + poetry install + else + python -m pip install . + fi - name: "Install documentation dependencies from pyproject.toml" shell: bash if: env.EXISTS_DOC_REQUIREMENTS == 'false' run: | - if grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then - python -m pip install poetry + source .venv/bin/activate + if [[ ${{ env.BUILD_BACKEND }} == 'poetry' ]]; then poetry install --with doc else python -m pip install .[doc] fi - - name: "Determine make command context" - shell: bash - run: | - if [[ -f "pyproject.toml" ]] && grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then - echo "SPHINX_BUILD_MAKE=$(echo 'poetry run -- make')" >> $GITHUB_ENV - else - echo "SPHINX_BUILD_MAKE=$(echo 'make')" >> $GITHUB_ENV - fi + # ------------------------------------------------------------------------ + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Build HTML, PDF and JSON documentation. - name: "Build HTML, PDF, and JSON documentation" if: inputs.requires-xvfb == 'false' shell: bash run: | + source .venv/bin/activate ${{ env.SPHINX_BUILD_MAKE }} -C doc html SPHINXOPTS="${{ inputs.sphinxopts }}" ${{ env.SPHINX_BUILD_MAKE }} -C doc pdf if [[ ${{ inputs.check-links }} == 'true' ]]; @@ -250,6 +328,7 @@ runs: if: inputs.requires-xvfb == 'true' shell: bash run: | + source .venv/bin/activate xvfb-run ${{ env.SPHINX_BUILD_MAKE }} -C doc html SPHINXOPTS="${{ inputs.sphinxopts }}" xvfb-run ${{ env.SPHINX_BUILD_MAKE }} -C doc pdf if [[ ${{ inputs.check-links }} == 'true' ]]; @@ -274,6 +353,7 @@ runs: if: ${{ inputs.add-pdf-html-docs-as-assets == 'true' }} shell: bash run: | + source .venv/bin/activate python ${{ github.action_path }}/../doc-build/parse_doc_conf.py - uses: ansys/actions/_logging@main diff --git a/_doc-build-windows/action.yml b/_doc-build-windows/action.yml index e90bd9d88..5f520ef07 100644 --- a/_doc-build-windows/action.yml +++ b/_doc-build-windows/action.yml @@ -33,8 +33,8 @@ description: | `_ is available after installing the documentation dependencies, the action uses it to generate documentation from the source. It requires that all the - documentation is contained in the ``doc/`` directory of a project. The - action locates the ``doc/make.bat`` and runs the ``make.bat html`` and + documentation is contained in the ``doc\`` directory of a project. The + action locates the ``doc\make.bat`` and runs the ``make.bat html`` and ``make.bat pdf`` commands. If desired, the ``make.bat json`` command can also be executed to generate JSON documentation. @@ -100,7 +100,7 @@ inputs: Whether to add PDF and HTML documentation as assets of the HTML documentation. The HTML documentation is compressed before being added. The PDF file name is expected to be retrieved through the documentation's - configuration file 'conf.py' in 'doc/source'. + configuration file 'conf.py' in 'doc\source'. .. warning:: @@ -212,47 +212,116 @@ runs: # ------------------------------------------------------------------------ + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Determine context. + + - name: "Determine GitHub environment variables" + shell: powershell + run: | + if ((Test-Path "pyproject.toml") -and (Get-Content "pyproject.toml" | Select-String -Pattern 'build-backend = "poetry\.core\.masonry\.api"')) { + echo "BUILD_BACKEND=$(echo 'poetry')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + echo "SPHINX_BUILD_MAKE=$(echo 'poetry run -- make.bat')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } else { + echo "BUILD_BACKEND=$(echo 'pip')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + echo "SPHINX_BUILD_MAKE=$(echo '.\make.bat')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Build backend: ${{ env.BUILD_BACKEND }} + Sphinx build make: ${{ env.SPHINX_BUILD_MAKE }} + + # ------------------------------------------------------------------------ + - uses: ansys/actions/_logging@main with: level: "INFO" message: > Set up python to build the documentation. - - name: "Update pip" + # NOTE: Installation of poetry in a separate environment to the project to + # avoid situations in which both poetry and the project have shared + # dependencies with different version. This can lead to CICD failures. For + # more information, see https://github.com/ansys/actions/pull/560 + - name: "Add pipx/bin directory to Github Path" + if: env.BUILD_BACKEND == 'poetry' shell: powershell - run: python -m pip install -U pip + run: echo "${{ runner.temp }}/pipx/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - name: Check if requirements.txt file exists + # NOTE: Poetry uses virtual environments when installing a project. As we + # want to control that creation, we store POETRY_VIRTUALENVS_CREATE=false + # in the GitHub environment. + - name: "Set poetry environment variable(s)" + if: env.BUILD_BACKEND == 'poetry' + shell: powershell + run: echo "POETRY_VIRTUALENVS_CREATE=$(echo false)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + # NOTE: Install pipx in a location that can be used in following CICD jobs + # but ensure that poetry is installed in a temporary folder cleaned before + # and after each job. This way poetry is kinda "installed at system level" + # making it available in the following call and installed in a different + # environment from the project. + - name: "Install poetry and create a virtual environment" + if: env.BUILD_BACKEND == 'poetry' shell: powershell run: | - echo "EXISTS_DOC_REQUIREMENTS=$(if (Test-Path '${{ inputs.requirements-file }}') { echo 'true' } else { echo 'false' })" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + python -m pip install pipx + python -m pipx install poetry + python -m venv .venv + env: + PIPX_BIN_DIR: ${{ runner.temp }}/pipx/bin + PIPX_HOME : ${{ runner.temp }}/pipx/home + + - name: "Create a virtual environment" + if: env.BUILD_BACKEND == 'pip' + shell: powershell + run: python -m venv .venv + + # ------------------------------------------------------------------------ + + - name: "Update pip" + shell: powershell + run: | + .venv\Scripts\Activate.ps1 + python -m pip install -U pip - - name: Print previous output + - name: "Check if requirements.txt file exists" shell: powershell run: | - echo "Output was found ${{ env.EXISTS_DOC_REQUIREMENTS }}" + echo "EXISTS_DOC_REQUIREMENTS=$(if (Test-Path '${{ inputs.requirements-file }}') { echo 'true' } else { echo 'false' })" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - name: Install documentation dependencies from requirements file shell: powershell if: ${{ env.EXISTS_DOC_REQUIREMENTS == 'true' }} run: | + .venv\Scripts\Activate.ps1 python -m pip install -r ${{ inputs.requirements-file }} - name: Install Python library shell: powershell if: ${{ inputs.skip-install == 'false' }} run: | - python -m pip install . + .venv\Scripts\Activate.ps1 + if ("${{ env.BUILD_BACKEND }}" -eq 'poetry' ) { + poetry install + } else { + python -m pip install . + } - name: Install documentation dependencies from pyproject.toml shell: powershell if: ${{ env.EXISTS_DOC_REQUIREMENTS == 'false' }} run: | - if (Get-Content "pyproject.toml" | Select-String -Pattern 'build-backend = "poetry\.core\.masonry\.api"') { - python -m pip install poetry - poetry install --with doc + .venv\Scripts\Activate.ps1 + if ("${{ env.BUILD_BACKEND }}" -eq 'poetry' ) { + poetry install --with doc } else { - python -m pip install .[doc] + python -m pip install .[doc] } # ------------------------------------------------------------------------ @@ -263,19 +332,11 @@ runs: message: > Build HTML, PDF and JSON documentation. - - name: Determine command context - shell: powershell - run: | - if ((Test-Path "pyproject.toml") -and (Get-Content "pyproject.toml" | Select-String -Pattern 'build-backend = "poetry\.core\.masonry\.api"')) { - echo "SPHINX_BUILD_MAKE=$(echo 'poetry run -- doc\make.bat')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - } else { - echo "SPHINX_BUILD_MAKE=$(echo 'doc\make.bat')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - } - - name: Build HTML, PDF, and JSON documentation shell: powershell run: | - echo "Sphinx build make value is ${{ env.SPHINX_BUILD_MAKE }}" + .venv\Scripts\Activate.ps1 + cd doc ${{ env.SPHINX_BUILD_MAKE }} html SPHINXOPTS="${{ inputs.sphinxopts }}" ${{ env.SPHINX_BUILD_MAKE }} pdf if ("${{ inputs.check-links }}" -eq 'true' ) { @@ -298,6 +359,7 @@ runs: if: ${{ inputs.add-pdf-html-docs-as-assets == 'true' }} shell: powershell run: | + .venv\Scripts\Activate.ps1 python ${{ github.action_path }}\..\doc-build\parse_doc_conf.py - uses: ansys/actions/_logging@main diff --git a/check-vulnerabilities/action.yml b/check-vulnerabilities/action.yml index b4a00b406..d0420e629 100644 --- a/check-vulnerabilities/action.yml +++ b/check-vulnerabilities/action.yml @@ -185,22 +185,106 @@ runs: with: repository: ${{ env.DEPENDENCY_CHECK_REPOSITORY }} + # ------------------------------------------------------------------------ + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Determine context. + + - name: "Determine GitHub environment variables" + + shell: bash + run: | + if [[ -f "pyproject.toml" ]] && grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then + echo "BUILD_BACKEND=$(echo 'poetry')" >> $GITHUB_ENV + else + echo "BUILD_BACKEND=$(echo 'pip')" >> $GITHUB_ENV + fi + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Build backend: ${{ env.BUILD_BACKEND }} + + # ------------------------------------------------------------------------ + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Set up python to check vulnerabilities. + - name: "Set up Python ${{ inputs.python-version }}" uses: ansys/actions/_setup-python@main with: python-version: ${{ inputs.python-version }} use-cache: false + # NOTE: Installation of poetry in a separate environment to the project to + # avoid situations in which both poetry and the project have shared + # dependencies with different version. This can lead to CICD failures. For + # more information, see https://github.com/ansys/actions/pull/560 + - name: "Add pipx/bin directory to Github Path" + if: env.BUILD_BACKEND == 'poetry' + shell: bash + run: echo "${{ runner.temp }}/pipx/bin" >> $GITHUB_PATH + + # NOTE: Poetry uses virtual environments when installing a project. As we + # want to control that creation, we store POETRY_VIRTUALENVS_CREATE=false + # in the GitHub environment. + - name: "Set poetry environment variable(s)" + if: env.BUILD_BACKEND == 'poetry' + shell: bash + run: echo "POETRY_VIRTUALENVS_CREATE=false" >> $GITHUB_ENV + + # NOTE: Install pipx in a location that can be used in following CICD jobs + # but ensure that poetry is installed in a temporary folder cleaned before + # and after each job. This way poetry is kinda "installed at system level" + # making it available in the following call and installed in a different + # environment from the project. + - name: "Install poetry and create a virtual environment" + if: env.BUILD_BACKEND == 'poetry' + shell: bash + run: | + python -m pip install pipx + python -m pipx install poetry + python -m venv .venv + env: + PIPX_BIN_DIR: ${{ runner.temp }}/pipx/bin + PIPX_HOME : ${{ runner.temp }}/pipx/home + + - name: "Create a virtual environment" + if: env.BUILD_BACKEND == 'pip' + shell: bash + run: | + python -m venv .venv + + # ------------------------------------------------------------------------ + + - name: "Update pip" + shell: bash + run: | + source .venv/bin/activate + python -m pip install -U pip + - name: "Install requirements" shell: bash run: | - python -m pip install --upgrade pip + source .venv/bin/activate pip install -r ${{ github.action_path }}/requirements.txt - name: "Install library" shell: bash run: | - python -m pip install . + source .venv/bin/activate + if [[ ${{ env.BUILD_BACKEND }} == 'poetry' ]]; then + poetry install + else + python -m pip install . + fi - name: "Download the list of ignored safety vulnerabilities" shell: bash @@ -210,6 +294,7 @@ runs: - name: "Run safety and bandit" shell: bash run: | + source .venv/bin/activate # Load accepted safety vulnerabilities mapfile ignored_safety_vulnerabilities < ignored-safety.txt ignored_vulnerabilities='' @@ -224,6 +309,7 @@ runs: - name: "Run safety advisory checks" shell: bash run: | + source .venv/bin/activate if [[ ${{ inputs.hide-log }} == 'true' ]]; then python ${{ github.action_path }}/check_vulnerabilities.py > /dev/null 2>&1 else diff --git a/code-style/action.yml b/code-style/action.yml index ed1f0fe52..fd39581c5 100644 --- a/code-style/action.yml +++ b/code-style/action.yml @@ -96,31 +96,96 @@ runs: - name: "Install Git and clone project" uses: actions/checkout@v4 + # ------------------------------------------------------------------------ + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Determine context. + + - name: "Determine GitHub environment variables" + shell: bash + run: | + if [[ -f "pyproject.toml" ]] && grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then + echo "BUILD_BACKEND=$(echo 'poetry')" >> $GITHUB_ENV + else + echo "BUILD_BACKEND=$(echo 'pip')" >> $GITHUB_ENV + fi + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Build backend: ${{ env.BUILD_BACKEND }} + + # ------------------------------------------------------------------------ + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Set up python to check code style. + - name: "Set up Python" uses: ansys/actions/_setup-python@main with: python-version: ${{ inputs.python-version }} use-cache: ${{ inputs.use-python-cache }} - - name: "Upgrade pip and disable virtual environment (for poetry only)" + # NOTE: Installation of poetry in a separate environment to the project to + # avoid situations in which both poetry and the project have shared + # dependencies with different version. This can lead to CICD failures. For + # more information, see https://github.com/ansys/actions/pull/560 + - name: "Add pipx/bin directory to Github Path" + if: env.BUILD_BACKEND == 'poetry' + shell: bash + run: echo "${{ runner.temp }}/pipx/bin" >> $GITHUB_PATH + + # NOTE: Poetry uses virtual environments when installing a project. As we + # want to control that creation, we store POETRY_VIRTUALENVS_CREATE=false + # in the GitHub environment. + - name: "Set poetry environment variable(s)" + if: env.BUILD_BACKEND == 'poetry' + shell: bash + run: echo "POETRY_VIRTUALENVS_CREATE=false" >> $GITHUB_ENV + + # NOTE: Install pipx in a location that can be used in following CICD jobs + # but ensure that poetry is installed in a temporary folder cleaned before + # and after each job. This way poetry is kinda "installed at system level" + # making it available in the following call and installed in a different + # environment from the project. + - name: "Install poetry and create a virtual environment" + if: env.BUILD_BACKEND == 'poetry' shell: bash run: | - python -m pip install --upgrade pip - if grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then - # For projects using poetry, do not use a virtual environment. - # Poetry uses virtual environments to install its dependencies, but this might - # lead to problems if it is not activated prior to executing poetry commands. - # Store POETRY_VIRTUALENVS_CREATE=false in the GitHub environment to prevent - # poetry from creating a virtual environment. - # - echo "POETRY_VIRTUALENVS_CREATE=false" >> $GITHUB_ENV - fi + python -m pip install pipx + python -m pipx install poetry + python -m venv .venv + env: + PIPX_BIN_DIR: ${{ runner.temp }}/pipx/bin + PIPX_HOME : ${{ runner.temp }}/pipx/home + + - name: "Create a virtual environment" + if: env.BUILD_BACKEND == 'pip' + shell: bash + run: | + python -m venv .venv + + # ------------------------------------------------------------------------ + + - name: "Update pip" + shell: bash + run: | + source .venv/bin/activate + python -m pip install -U pip - name: "Install project (if required)" if: inputs.skip-install == 'false' shell: bash run: | - if grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then + source .venv/bin/activate + if [[ ${{ env.BUILD_BACKEND }} == 'poetry' ]]; then python -m pip install poetry python -m poetry install else @@ -130,12 +195,14 @@ runs: - name: "Install pre-commit" shell: bash run: | + source .venv/bin/activate python -m pip install pre-commit pre-commit install - name: "Run pre-commit" shell: bash run: | + source .venv/bin/activate pre-commit run --all-files --show-diff-on-failure # ------------------------------------------------------------------------ diff --git a/tests-pytest/action.yml b/tests-pytest/action.yml index 42c2b8dbe..b2c6b4e5f 100644 --- a/tests-pytest/action.yml +++ b/tests-pytest/action.yml @@ -101,31 +101,96 @@ runs: uses: actions/checkout@v4 if: ${{ inputs.checkout == 'true' }} + # ------------------------------------------------------------------------ + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Determine context. + + - name: "Determine GitHub environment variables" + shell: bash + run: | + if [[ -f "pyproject.toml" ]] && grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then + echo "BUILD_BACKEND=$(echo 'poetry')" >> $GITHUB_ENV + else + echo "BUILD_BACKEND=$(echo 'pip')" >> $GITHUB_ENV + fi + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Build backend: ${{ env.BUILD_BACKEND }} + + # ------------------------------------------------------------------------ + + - uses: ansys/actions/_logging@main + with: + level: "INFO" + message: > + Set up python to test. + - name: "Set up Python" uses: ansys/actions/_setup-python@main with: python-version: ${{ inputs.python-version }} use-cache: ${{ inputs.use-python-cache }} - - name: "Upgrade pip and disable virtual environment (for poetry only)" + # NOTE: Installation of poetry in a separate environment to the project to + # avoid situations in which both poetry and the project have shared + # dependencies with different version. This can lead to CICD failures. For + # more information, see https://github.com/ansys/actions/pull/560 + - name: "Add pipx/bin directory to Github Path" + if: env.BUILD_BACKEND == 'poetry' + shell: bash + run: echo "${{ runner.temp }}/pipx/bin" >> $GITHUB_PATH + + # NOTE: Poetry uses virtual environments when installing a project. As we + # want to control that creation, we store POETRY_VIRTUALENVS_CREATE=false + # in the GitHub environment. + - name: "Set poetry environment variable(s)" + if: env.BUILD_BACKEND == 'poetry' + shell: bash + run: echo "POETRY_VIRTUALENVS_CREATE=false" >> $GITHUB_ENV + + # NOTE: Install pipx in a location that can be used in following CICD jobs + # but ensure that poetry is installed in a temporary folder cleaned before + # and after each job. This way poetry is kinda "installed at system level" + # making it available in the following call and installed in a different + # environment from the project. + - name: "Install poetry and create a virtual environment" + if: env.BUILD_BACKEND == 'poetry' shell: bash run: | - python -m pip install --upgrade pip - if grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then - # For projects using poetry, do not use a virtual environment. - # Poetry uses virtual environments to install its dependencies, but this might - # lead to problems if it is not activated prior to executing poetry commands. - # Store POETRY_VIRTUALENVS_CREATE=false in the GitHub environment to prevent - # poetry from creating a virtual environment. - # - echo "POETRY_VIRTUALENVS_CREATE=false" >> $GITHUB_ENV - fi + python -m pip install pipx + python -m pipx install poetry + python -m venv .venv + env: + PIPX_BIN_DIR: ${{ runner.temp }}/pipx/bin + PIPX_HOME : ${{ runner.temp }}/pipx/home + + - name: "Create a virtual environment" + if: env.BUILD_BACKEND == 'pip' + shell: bash + run: | + python -m venv .venv + + # ------------------------------------------------------------------------ + + - name: "Update pip" + shell: bash + run: | + source .venv/bin/activate + python -m pip install -U pip - name: "Install project (if required)" if: inputs.skip-install == 'false' shell: bash run: | - if grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then + source .venv/bin/activate + if [[ ${{ env.BUILD_BACKEND }} == 'poetry' ]]; then python -m pip install poetry poetry install else @@ -152,13 +217,16 @@ runs: - name: "Install test dependencies from the requirements file" shell: bash if: env.EXISTS_TESTS_REQUIREMENTS == 'true' - run: python -m pip install -r requirements/requirements_tests.txt + run: | + source .venv/bin/activate + python -m pip install -r requirements/requirements_tests.txt - name: "Install test dependencies from pyproject.toml" shell: bash if: env.EXISTS_TESTS_REQUIREMENTS == 'false' run: | - if grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then + source .venv/bin/activate + if [[ ${{ env.BUILD_BACKEND }} == 'poetry' ]]; then poetry install --with tests else python -m pip install .[tests] @@ -168,10 +236,12 @@ runs: if: inputs.requires-xvfb == 'false' shell: bash run: | + source .venv/bin/activate pytest ${{ inputs.pytest-markers }} ${{ inputs.pytest-extra-args }} ${{ inputs.pytest-postargs }} - name: "Executing test suite using xvfb" if: inputs.requires-xvfb == 'true' shell: bash run: | + source .venv/bin/activate xvfb-run pytest ${{ inputs.pytest-markers }} ${{ inputs.pytest-extra-args }} ${{ inputs.pytest-postargs }}