Skip to content

fix: doc build without python cache #621

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

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
196 changes: 28 additions & 168 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,188 +21,48 @@ concurrency:

jobs:

labeler:
name: "Labels"
permissions:
contents: read
pull-requests: write
doc-build-linux:
name: "Doc build Linux"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: "Update labels"
uses: micnncim/action-label-syncer@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Label pull-request"
# Skip if user does not have write permissions - PR coming from a fork
if: github.event.pull_request.head.repo.full_name == github.repository
uses: actions/labeler@v5.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

pr-title-style:
name: "Pull-request title style"
runs-on: ubuntu-latest
needs: labeler
steps:
- uses: ansys/actions/check-pr-title@main
with:
token: ${{ secrets.GITHUB_TOKEN }}

code-style:
name: "Code style"
runs-on: ubuntu-latest
needs: pr-title-style
steps:
- name: "Run code style checks"
uses: ansys/actions/code-style@main
- name: "Build documentation without cache"
uses: ansys/actions/doc-build@fix/doc-build-without-python-cache-new
env:
PYTHON_NO_CACHE_OPTION: ''
with:
skip-install: true
python-version: ${{ env.MAIN_PYTHON_VERSION }}
use-python-cache: false
needs-quarto: true

- name: "Verify private actions are not pointing to the 'main' branch"
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
run: |
if $(grep -q --exclude-dir={.git,.github,doc} "ansys\/actions\/.*\@main" -r .); then
echo -e "\033[1;91m[ERROR]: Found private actions pointing to the 'main' branch.\033[0m"
grep -q --exclude-dir={.git,.github,doc} "ansys\/actions\/.*\@main" -r .
fi

doc-style:
name: "Doc style"
runs-on: ubuntu-latest
needs: pr-title-style
steps:
- name: "Run documentation style checks"
uses: ansys/actions/doc-style@main
- name: "Build documentation with cache"
uses: ansys/actions/doc-build@fix/doc-build-without-python-cache-new
env:
PYTHON_NO_CACHE_OPTION: ''
with:
token: ${{ secrets.GITHUB_TOKEN }}
skip-install: true
python-version: ${{ env.MAIN_PYTHON_VERSION }}
use-python-cache: true
needs-quarto: true

doc-build:
name: "Doc build"
doc-build-windows:
name: "Doc build Windows"
runs-on: ubuntu-latest
needs: doc-style
steps:
- name: "Build documentation"
uses: ansys/actions/doc-build@main
- name: "Build documentation without cache"
uses: ansys/actions/doc-build@fix/doc-build-without-python-cache-new
with:
skip-install: true
python-version: ${{ env.MAIN_PYTHON_VERSION }}
use-python-cache: false
needs-quarto: true

tests:
name: "Tests"
runs-on: ubuntu-latest
needs: code-style
permissions:
id-token: write
contents: write
steps:

- name: "Install Git and clone project"
uses: actions/checkout@v4

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

- name: "Isolate testing library"
run: mv .ci/${{ env.test-library-name }} ~/

- name: "Install build and twine"
shell: bash
run: |
python -m pip install build twine

- name: "Build distribution artifacts and check their health"
shell: bash
run: |
cd ~/${{ env.test-library-name }}
ls -R && python -m build && python -m twine check dist/*

- name: "Upload distribution artifacts to GitHub artifacts"
uses: actions/upload-artifact@v4
with:
name: ${{ env.test-library-name }}-artifacts
path: ~/${{ env.test-library-name }}/dist/
retention-days: 7

- name: "Release to the test PyPI repository"
uses: ansys/actions/release-pypi-test@main
with:
library-name: ${{ env.test-library-name }}
use-trusted-publisher: true

doc-deploy-dev:
name: "Deploy developers documentation"
runs-on: ubuntu-latest
if: github.event_name == 'push' && !contains(github.ref, 'refs/tags')
needs: [doc-build, tests]
steps:
- uses: ansys/actions/doc-deploy-dev@main
with:
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}
bot-user: ${{ secrets.PYANSYS_CI_BOT_USERNAME }}
bot-email: ${{ secrets.PYANSYS_CI_BOT_EMAIL }}

release:
name: "Release to GitHub"
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
needs: [doc-build, tests]
steps:

- name: "Download HTML documentation"
uses: actions/download-artifact@v4
with:
name: documentation-html
path: documentation-html

- name: "Zip HTML documentation"
uses: vimtor/action-zip@v1.2
with:
files: documentation-html
dest: documentation-html.zip

- name: "Download PDF documentation"
uses: actions/download-artifact@v4
with:
name: documentation-pdf
path: documentation-pdf

- name: "Zip PDF documentation"
uses: vimtor/action-zip@v1.2
with:
files: documentation-pdf
dest: documentation-pdf.zip

- name: "Display the structure of downloaded files"
shell: bash
run: ls -R

- name: "Release to GitHub"
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: |
documentation-html.zip
documentation-pdf.zip

doc-deploy-stable:
name: "Deploy stable documentation"
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
needs: release
steps:
- uses: ansys/actions/doc-deploy-stable@main
- name: "Build documentation with cache"
uses: ansys/actions/doc-build@fix/doc-build-without-python-cache-new
env:
PYTHON_NO_CACHE_OPTION: ''
with:
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}
bot-user: ${{ secrets.PYANSYS_CI_BOT_USERNAME }}
bot-email: ${{ secrets.PYANSYS_CI_BOT_EMAIL }}
skip-install: true
python-version: ${{ env.MAIN_PYTHON_VERSION }}
use-python-cache: true
needs-quarto: true
75 changes: 49 additions & 26 deletions _doc-build-linux/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ inputs:
required: true
type: boolean

use-python-cache:
description: |
Whether to use the Python cache for installing previously downloaded
libraries. If ``true``, previously downloaded libraries are installed from the
Python cache. If ``false``, libraries are downloaded from the PyPI index.
required: true
type: boolean


runs:
using: "composite"
Expand Down Expand Up @@ -204,6 +212,18 @@ runs:
echo "SPHINX_BUILD_MAKE=$(echo 'make')" >> $GITHUB_ENV
fi

# NOTE: If one wants to use the Python cache, the environment variable PYTHON_NO_CACHE_OPTION is an empty string.
- name: "Extend GitHub environment variables depending on inputs.use-python-cache"
shell: bash
run: |
if [[ ${{ inputs.use-python-cache }} == 'false' ]]; then
if [[ ${{ env.BUILD_BACKEND }} == 'poetry' ]]; then
echo "PYTHON_NO_CACHE_OPTION=$(echo '--no-cache')" >> $GITHUB_ENV
else
echo "PYTHON_NO_CACHE_OPTION=$(echo '--no-cache-dir')" >> $GITHUB_ENV
fi
fi

- uses: ansys/actions/_logging@main
with:
level: "INFO"
Expand Down Expand Up @@ -252,6 +272,15 @@ runs:
PIPX_BIN_DIR: ${{ runner.temp }}/pipx/bin
PIPX_HOME : ${{ runner.temp }}/pipx/home

- name: Cache poetry
uses: actions/cache@v4
if: ${{ (env.BUILD_BACKEND == 'poetry') && (env.PYTHON_NO_CACHE_OPTION != '') }}
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-

- name: "Create a virtual environment"
if: env.BUILD_BACKEND == 'pip'
shell: bash
Expand All @@ -264,29 +293,39 @@ runs:
shell: bash
run: |
source .venv/bin/activate
python -m pip install -U pip
python -m pip install -U pip ${{ env.PYTHON_NO_CACHE_OPTION }}

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

- 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

- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Documentation requirements file found: ${{ env.EXISTS_DOC_REQUIREMENTS }}

- 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 }}
python -m pip install -r ${{ inputs.requirements-file }} ${{ env.PYTHON_NO_CACHE_OPTION }}

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

- name: "Install Python library"
shell: bash
if: inputs.skip-install == 'false'
run: |
source .venv/bin/activate
if [[ ${{ env.BUILD_BACKEND }} == 'poetry' ]]; then
poetry install
poetry install ${{ env.PYTHON_NO_CACHE_OPTION }}
else
python -m pip install .
python -m pip install . ${{ env.PYTHON_NO_CACHE_OPTION }}
fi

- name: "Install documentation dependencies from pyproject.toml"
Expand All @@ -295,9 +334,9 @@ runs:
run: |
source .venv/bin/activate
if [[ ${{ env.BUILD_BACKEND }} == 'poetry' ]]; then
poetry install --with doc
poetry install --with doc -vvv ${{ env.PYTHON_NO_CACHE_OPTION }}
else
python -m pip install .[doc]
python -m pip install .[doc] -vvv ${{ env.PYTHON_NO_CACHE_OPTION }}
fi

# ------------------------------------------------------------------------
Expand Down Expand Up @@ -455,24 +494,8 @@ runs:

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

- name: "Upload HTML documentation artifact"
uses: actions/upload-artifact@v4
with:
name: documentation-html
path: doc/_build/html
retention-days: 7

- name: "Upload PDF documentation artifact"
uses: actions/upload-artifact@v4
with:
name: documentation-pdf
path: doc/_build/latex/*.pdf
retention-days: 7

- name: "Upload JSON documentation artifact"
uses: actions/upload-artifact@v4
if: inputs.skip-json-build == 'false'
- uses: ansys/actions/_logging@main
with:
name: documentation-json
path: doc/_build/json
retention-days: 7
level: "INFO"
message: >
Upload HTML, PDF and JSON documentation.
Loading
Loading