Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use virtual environment to be consistent #560

Merged
merged 23 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
65a4da2
refactor: use virtual environment to be consistent
SMoraisAnsys Sep 6, 2024
fb4f261
Update _doc-build-linux/action.yml
SMoraisAnsys Sep 9, 2024
ab99e1d
Update _doc-build-windows/action.yml
SMoraisAnsys Sep 9, 2024
058dc10
Apply suggestions from code review
SMoraisAnsys Sep 9, 2024
e941793
fix: remove unused env variable
SMoraisAnsys Sep 9, 2024
832672d
fix: missing fi statement
SMoraisAnsys Sep 9, 2024
666b8ef
tbr: using correct private action for testing
SMoraisAnsys Sep 10, 2024
1cd00df
fix: add forgotten fi
SMoraisAnsys Sep 10, 2024
077ca07
fix: shell value in windows
SMoraisAnsys Sep 10, 2024
450dd73
fix: wrong env reference
SMoraisAnsys Sep 10, 2024
cd422dd
fix: add step to move to doc folder
SMoraisAnsys Sep 12, 2024
521736d
fix: call to make.bat executable
SMoraisAnsys Sep 19, 2024
05460c1
fix: doc directory handling
SMoraisAnsys Sep 19, 2024
2c74b8e
fix: revert use of main in private action
SMoraisAnsys Sep 19, 2024
77343dd
Merge branch 'main' into fix/inconsistent-behavior
SMoraisAnsys Sep 19, 2024
9173d35
refactor: install poetry with pipx
SMoraisAnsys Sep 23, 2024
6e4a994
Update _doc-build-linux/action.yml
SMoraisAnsys Sep 23, 2024
260dd75
tbr: use branch private action for testing
SMoraisAnsys Sep 23, 2024
bb22e20
Merge branch 'main' into fix/inconsistent-behavior
SMoraisAnsys Sep 23, 2024
b52c769
Merge branch 'main' into fix/inconsistent-behavior
SMoraisAnsys Sep 24, 2024
d254729
fix: typo in Github env variable
SMoraisAnsys Sep 24, 2024
daf9a9f
Revert "tbr: use branch private action for testing"
SMoraisAnsys Sep 24, 2024
b5f74d3
Merge branch 'main' into fix/inconsistent-behavior
jorgepiloto Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 96 additions & 16 deletions _doc-build-linux/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
SMoraisAnsys marked this conversation as resolved.
Show resolved Hide resolved
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' ]];
Expand All @@ -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' ]];
Expand All @@ -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
Expand Down
110 changes: 86 additions & 24 deletions _doc-build-windows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ description: |
<https://www.sphinx-doc.org/en/master/man/sphinx-build.html>`_ 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.

Expand Down Expand Up @@ -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::

Expand Down Expand Up @@ -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]
}

# ------------------------------------------------------------------------
Expand All @@ -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' ) {
Expand All @@ -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
Expand Down
Loading
Loading