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

Migrate to pyansys/actions and include get_version_match function #153

Merged
merged 15 commits into from
Nov 24, 2022
Merged
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
178 changes: 65 additions & 113 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,147 +7,99 @@ on:
- "*"
branches:
- main
env:
MAIN_PYTHON_VERSION : '3.10'
PACKAGE_NAME: 'ansys-sphinx-theme'
PACKAGE_NAMESPACE: 'ansys_sphinx_theme'
DOCUMENTATION_CNAME: 'sphinxdocs.ansys.com'

jobs:

style:
code-style:
name: Code style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
- name: "Run PyAnsys code style checks"
uses: pyansys/actions/code-style@v1
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip tox
- name: Test with tox
run: tox -e style
python-version: ${{ env.MAIN_PYTHON_VERSION }}

docs-style:
name: Documentation Style Check
doc-style:
name: Doc style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Running Vale
uses: errata-ai/vale-action@reviewdog
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: "Run Ansys documentation style checks"
uses: pyansys/actions/doc-style@v1
with:
files: doc
reporter: github-pr-check
level: error
filter_mode: nofilter
fail_on_error: true
vale_flags: "--config=doc/.vale.ini"
token: ${{ secrets.GITHUB_TOKEN }}

docs:
name: Documentation
doc-build:
name: Doc building
runs-on: ubuntu-latest
needs: docs-style
needs: doc-style
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install dependencies
run: |
sudo apt update
sudo apt-get install -y build-essential zip pandoc texlive-latex-extra latexmk texlive-pstricks
python -m pip install --upgrade pip tox
python -m pip install -r requirements/requirements_doc.txt
python -m pip install --editable .
- name: Build HTML documentation
run: tox -e doc

- name: Upload HTML Documentation
uses: actions/upload-artifact@v3.1.1
- name: "Run Ansys documentation building action"
uses: pyansys/actions/doc-build@v1
with:
name: HTML-Documentation
path: .tox/doc_out/
retention-days: 7
python-version: ${{ env.MAIN_PYTHON_VERSION }}

- name: Build PDF Documentation
run: |
make -C doc pdf
- name: Upload PDF Documentation
uses: actions/upload-artifact@v3.1.1
doc-deploy-development:
name: Doc dev version deploy
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: doc-build
steps:
- name: "Deploy developers documentation"
uses: pyansys/actions/doc-deploy-dev@v1
with:
name: PDF-Documentation
path: doc/build/latex/ansys_sphinx_theme.pdf
retention-days: 7
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy to gh-pages
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
uses: JamesIves/github-pages-deploy-action@v4.4.1
doc-deploy-stable:
name: Doc stable version deploy
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
runs-on: ubuntu-latest
needs: doc-deploy-development
steps:
- name: "Deploy stable documentation"
uses: pyansys/actions/doc-deploy-stable@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: .tox/doc_out/
CLEAN: true
SINGLE_COMMIT: true
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}
python-version: ${{ env.MAIN_PYTHON_VERSION }}

build:
name: Build
build-library:
name: "Build library"
runs-on: ubuntu-latest
needs: style
needs: doc-deploy-stable
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip pipx
python -m pip install -r requirements/requirements_build.txt
- name: Build wheel and sdist
run: |
python -m build && python -m twine check dist/*
- name: Upload wheel and sdist to artifacts
uses: actions/upload-artifact@v3.1.1
- name: "Build library source and wheel artifacts"
uses: pyansys/actions/build-library@v1
with:
name: ansys-sphinx-theme
path: dist/
retention-days: 7
library-name: ${{ env.PACKAGE_NAME }}

release:
name: Release
name: "Release project to private PyPI, public PyPI and GitHub"
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
needs: [style, docs-style, docs, build]
needs: build-library
runs-on: ubuntu-latest

steps:
- uses: actions/download-artifact@v3
- name: Set up Python
uses: actions/setup-python@v4

- name: "Release to the private PyPI repository"
uses: pyansys/actions/release-pypi-private@v1
with:
python-version: 3.9
- name: Display structure of downloaded files
run: ls -R
- name: Install dependencies
run: |
python -m pip install --upgrade pip twine
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python -m twine upload --skip-existing ./**/*.whl
python -m twine upload --skip-existing ./**/*.tar.gz
- name: Publish to GitHub
uses: softprops/action-gh-release@v1
library-name: ${{ env.PACKAGE_NAME }}
twine-username: "__token__"
twine-token: ${{ secrets.PYANSYS_PYPI_PRIVATE_PAT }}

- name: "Release to the public PyPI repository"
uses: pyansys/actions/release-pypi-public@v1
with:
files: |
./**/*.whl
./**/*.tar.gz
./PDF-Documentation/ansys_sphinx_theme.pdf
- name: Release
uses: softprops/action-gh-release@v1
library-name: ${{ env.PACKAGE_NAME }}
twine-username: "__token__"
twine-token: ${{ secrets.PYPI_TOKEN }}

- name: "Release to GitHub"
uses: pyansys/actions/release-github@v1
with:
generate_release_notes: true
library-name: ${{ env.PACKAGE_NAME }}
9 changes: 9 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Sphinx documentation configuration file."""

from datetime import datetime
import os

from sphinx.builders.latex import LaTeXBuilder

Expand All @@ -12,6 +14,7 @@
ansys_logo_white,
ansys_logo_white_cropped,
generate_404,
get_version_match,
latex,
watermark,
)
Expand All @@ -21,6 +24,7 @@
copyright = f"(c) {datetime.now().year} ANSYS, Inc. All rights reserved"
author = "Ansys Inc."
release = version = __version__
cname = os.getenv("DOCUMENTATION_CNAME", "nocname.com")

# use the default ansys logo
html_logo = ansys_logo_black
Expand All @@ -47,6 +51,11 @@
"name": "Changelog",
},
],
"switcher": {
"json_url": f"https://{cname}/release/versions.json",
"version_match": get_version_match(__version__),
},
"navbar_end": ["version-switcher", "theme-switcher", "navbar-icon-links"],
}

html_short_title = html_title = "Ansys Sphinx Theme"
Expand Down
9 changes: 8 additions & 1 deletion src/ansys_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
page_404 = os.path.join(_this_path, "static", "404.rst")

html_logo = pyansys_logo_black

CSS_FILENAME = "ansys_sphinx_theme.css"


Expand All @@ -31,6 +30,14 @@ def get_html_theme_path():
return Path(__file__).parents[0].absolute()


def get_version_match(semver):
jorgepiloto marked this conversation as resolved.
Show resolved Hide resolved
"""Evaluate the version match for the multi-documentation."""
if semver.endswith("dev0"):
return "dev"
major, minor, _ = semver.split(".")
return ".".join([major, minor])


def setup(app):
"""Connect to the sphinx theme app."""
theme_path = get_html_theme_path()
Expand Down
2 changes: 1 addition & 1 deletion src/ansys_sphinx_theme/theme.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ show_breadcrumbs = True
show_icons = True
hidden_icons =
additional_breadcrumbs =
switcher =
switcher =