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 1 commit
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
91 changes: 74 additions & 17 deletions _doc-build-linux/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,56 +179,111 @@ 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 environnement variables"
SMoraisAnsys marked this conversation as resolved.
Show resolved Hide resolved
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

- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Build backend: ${{ env.BUILD_BACKEND }}
Sphinx build make: ${{ SPHINX_BUILD_MAKE }}

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Set up python to build the documentation.

- name: "Print previous output"
- name: "Set poetry environment variable(s) (if required)"
shell: bash
if: env.BUILD_BACKEND == 'poetry'
run: |
echo "Output was found ${{ env.EXISTS_DOC_REQUIREMENTS }}"
# 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

- 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 poetry (if required)"
shell: bash
if: env.BUILD_BACKEND == 'poetry'
run: |
source .venv/bin/activate
python -m pip install poetry
Andy-Grigg marked this conversation as resolved.
Show resolved Hide resolved

- 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]
python -m pip install .[doc] ${{ env.PYTHON_NO_CACHE_OPTION }}
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 @@ -244,6 +299,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 @@ -268,6 +324,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
81 changes: 61 additions & 20 deletions _doc-build-windows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,47 +211,95 @@ runs:

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Determine context.

- name: "Determine Github environnement variables"
SMoraisAnsys marked this conversation as resolved.
Show resolved Hide resolved
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 -- doc\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 'doc\make.bat')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
SMoraisAnsys marked this conversation as resolved.
Show resolved Hide resolved
}

- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Build backend: ${{ env.BUILD_BACKEND }}
Sphinx build make: ${{ SPHINX_BUILD_MAKE }}

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Set up python to build the documentation.

- name: "Update pip"
- name: "Set poetry environment variable(s) (if required)"
shell: powershell
run: python -m pip install -U pip
if: env.BUILD_BACKEND == 'poetry'
run: |
# 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

- name: Check if requirements.txt file exists
- name: "Update pip"
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
.venv\Scripts\Activate.ps1
python -m pip install -U pip

- name: Print previous output
- name: Check if requirements.txt file exists
SMoraisAnsys marked this conversation as resolved.
Show resolved Hide resolved
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 poetry (if required)"
shell: bash
if: env.BUILD_BACKEND == 'poetry'
run: |
.venv\Scripts\Activate.ps1
Andy-Grigg marked this conversation as resolved.
Show resolved Hide resolved
python -m pip install poetry

- 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 @@ -262,18 +310,10 @@ 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: |
.venv\Scripts\Activate.ps1
echo "Sphinx build make value is ${{ env.SPHINX_BUILD_MAKE }}"
${{ env.SPHINX_BUILD_MAKE }} html SPHINXOPTS="${{ inputs.sphinxopts }}"
${{ env.SPHINX_BUILD_MAKE }} pdf
Expand All @@ -297,6 +337,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
71 changes: 69 additions & 2 deletions check-vulnerabilities/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,87 @@ runs:
with:
repository: ${{ env.DEPENDENCY_CHECK_REPOSITORY }}

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Determine context.

- name: "Determine Github environnement variables"
SMoraisAnsys marked this conversation as resolved.
Show resolved Hide resolved
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

- 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 poetry environment variable(s) (if required)"
shell: bash
if: env.BUILD_BACKEND == 'poetry'
run: |
# 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

- name: "Set up Python ${{ inputs.python-version }}"
uses: ansys/actions/_setup-python@main
with:
python-version: ${{ inputs.python-version }}
use-cache: false

- name: Create virtual environment
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 poetry (if required)"
shell: bash
if: env.BUILD_BACKEND == 'poetry'
run: |
source .venv/bin/activate
python -m pip install poetry

- 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
Expand All @@ -210,6 +275,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=''
Expand All @@ -224,6 +290,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
Expand Down
Loading
Loading