Skip to content

Commit

Permalink
Workflow using pyansys actions (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobPasMue authored Feb 6, 2023
1 parent 60497a5 commit 3f26733
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 198 deletions.
283 changes: 88 additions & 195 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,25 @@ env:
DOCKER_IMAGE_NAME: ghcr.io/pyansys/prime
DOCKER_IMAGE_TAG: '23.1.0'
MAIN_PYTHON_VERSION: '3.9'
PACKAGE_NAME: 'ansys-meshing-prime'
PACKAGE_NAMESPACE: 'ansys.meshing.prime'
DOCUMENTATION_CNAME: 'prime.docs.pyansys.com'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

style:
name: Pre-commit Check
name: Code style
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
- name: PyAnsys code style checks
uses: pyansys/actions/code-style@v3
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}

- name: "Install pre-commit"
run: pip install pre-commit

- name: "Run pre-commit"
run: pre-commit run --all-files --show-diff-on-failure

docs-style:
name: Documentation Style Check
runs-on: ubuntu-latest
Expand All @@ -49,107 +45,49 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}

build:
name: Build the package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
smoke-tests:
name: Build and Smoke tests
runs-on: ${{ matrix.os }}
needs: [style]
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

- name: Cache pip
uses: actions/cache@v3
steps:
- name: Build wheelhouse and perform smoke test
uses: pyansys/actions/build-wheelhouse@v3
with:
path: ~/.cache/pip
key: Python-${{ runner.os }}-v${{ env.MAIN_PYTHON_VERSION }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
Python-${{ runner.os }}-v${{ env.MAIN_PYTHON_VERSION }}
library-name: ${{ env.PACKAGE_NAME }}
library-namespace: ${{ env.PACKAGE_NAMESPACE }}
operating-system: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}

- name: Build the library
run: |
pip install build
python -m build .
- name: Check package
run: |
pip install twine
twine check dist/*
- name: Upload wheel
uses: actions/upload-artifact@v3
with:
name: pyprimemesh-client
path: dist/
retention-days: 7

smoke:
name: Smoke testing the client for different platforms
needs: [ build ]
macos-build:
name: Build and Smoke tests (macOS)
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
runs-on: macos-latest
needs: [style]
strategy:
fail-fast: false
matrix:
os: [ windows-latest, ubuntu-latest ]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11' ]

runs-on: ${{ matrix.os }}
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
- name: Build wheelhouse and perform smoke test
uses: pyansys/actions/build-wheelhouse@v3
with:
library-name: ${{ env.PACKAGE_NAME }}
library-namespace: ${{ env.PACKAGE_NAMESPACE }}
operating-system: ${{ runner.os }}
python-version: ${{ matrix.python-version }}

- uses: actions/download-artifact@v3
with:
name: pyprimemesh-client
path: dist

- name: Install Library
run: |
pip install ansys-meshing-prime[all] --find-links dist --pre
- name: Test import
run: |
python -c "import ansys.meshing.prime as pyprimemesh; print('Successfully imported ansys.meshing.prime')"
python -c "from ansys.meshing.prime import __version__; print(__version__)"
docs:
name: Documentation
runs-on: ubuntu-latest
needs: [ docs-style ]
needs: [docs-style]
steps:
- uses: actions/checkout@v3

# Used to only publish documentation when there is a push
- name: Get Bot Application Token
if: github.event_name == 'push'
id: get_workflow_token
uses: peter-murray/workflow-application-token-action@v2
with:
application_id: ${{ secrets.BOT_APPLICATION_ID }}
application_private_key: ${{ secrets.BOT_APPLICATION_PRIVATE_KEY }}

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}

- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: Python-${{ runner.os }}-v${{ env.MAIN_PYTHON_VERSION }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
Python-${{ runner.os }}-v${{ env.MAIN_PYTHON_VERSION }}
- name: Install library and documentation requirements
run: |
pip install -e .[all,doc]

- name: Login in Github Container registry
uses: docker/login-action@v2
Expand All @@ -164,77 +102,23 @@ jobs:
- name: Setup headless display
uses: pyvista/setup-headless-display-action@v1

- name: Build HTML
run: |
make -C doc html #SPHINXOPTS="-W"
- name: "Run Ansys documentation building action"
uses: pyansys/actions/doc-build@v3
env:
PYPRIMEMESH_LAUNCH_CONTAINER: 1
PYPRIMEMESH_SPHINX_BUILD: 1
PYPRIMEMESH_IMAGE_TAG: ${{ env.DOCKER_IMAGE_TAG }}
ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER )}}

# - name: Build PDF Documentation
# run: |
# sudo apt update
# sudo apt-get install -y texlive-latex-extra latexmk
# make -C doc latexpdf

- name: Upload HTML Documentation
uses: actions/upload-artifact@v3
with:
name: pyprimemesh-docs-html
path: doc/build/html
retention-days: 7

# - name: Upload PDF Documentation
# uses: actions/upload-artifact@v3
# with:
# name: pyprimemesh-docs-pdf
# path: doc/build/latex/*.pdf
# retention-days: 7

- name: Deploy Stable Documentation
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'dev')
uses: JamesIves/[email protected]
with:
repository-name: pyansys/pyprimemesh-docs
token: ${{ steps.get_workflow_token.outputs.token }}
branch: gh-pages
folder: doc/build/html
clean: true
# By default, also '-W --keep-going'... we should eventually solve the warnings in the build process.
sphinxopts: '-j auto'

# Deploy Latest Developer Documentation
- name: Deploy Documentation
if: github.event_name == 'push' && contains(github.ref, 'refs/heads/main')
uses: JamesIves/[email protected]
with:
repository-name: pyansys/pyprimemesh-dev-docs
token: ${{ steps.get_workflow_token.outputs.token }}
branch: gh-pages
folder: doc/build/html
clean: true

testing:
name: Run Unit Tests
needs: [ smoke ]
needs: [ smoke-tests ]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}

- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: Python-${{ runner.os }}-v${{ env.MAIN_PYTHON_VERSION }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
Python-${{ runner.os }}-v${{ env.MAIN_PYTHON_VERSION }}
- name: Login in Github Container registry
uses: docker/login-action@v2
with:
Expand All @@ -245,60 +129,69 @@ jobs:
- name: Pull Ansys Prime Server
run: docker pull ${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG }}

- name: Install library with testing requirements and run tests
- name: "Run pytest"
uses: pyansys/actions/tests-pytest@v3
env:
PYPRIMEMESH_LAUNCH_CONTAINER: 1
PYPRIMEMESH_IMAGE_TAG: ${{ env.DOCKER_IMAGE_TAG }}
ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER )}}
run: |
pip install -e .[all,tests]
coverage run -m --source=src/ansys/meshing/prime/core,src/ansys/meshing/prime/lucid --module pytest -vv .
with:
pytest-markers: "-vv"
pytest-extra-args: "--cov=ansys.meshing.prime --cov-report=term --cov-report=html:.cov/html --cov-report=html:.cov/xml"

- uses: codecov/codecov-action@v3
name: 'Upload coverage to CodeCov'

release:
name: Release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
needs: [ testing, style, docs ]
package:
name: Package library
needs: [testing, docs]
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v4
- name: Build library source and wheel artifacts
uses: pyansys/actions/build-library@v3
with:
library-name: ${{ env.PACKAGE_NAME }}
python-version: ${{ env.MAIN_PYTHON_VERSION }}

- uses: actions/download-artifact@v3
release:
name: Release project
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
needs: [package, macos-build]
runs-on: ubuntu-latest
steps:
- name: Release to the private PyPI repository
uses: pyansys/actions/release-pypi-private@v3
with:
name: pyprimemesh-client
path: dist
library-name: ${{ env.PACKAGE_NAME }}
twine-username: "__token__"
twine-token: ${{ secrets.PYANSYS_PYPI_PRIVATE_PAT }}

# list current directory
- name: List directory structure
run: ls -R
- name: Release to GitHub
uses: pyansys/actions/release-github@v3
with:
library-name: ${{ env.PACKAGE_NAME }}

- name: Upload to Private PyPi
run: |
pip install twine
python -m twine upload --skip-existing ./**/*.whl
python -m twine upload --skip-existing ./**/*.tar.gz
env:
TWINE_USERNAME: PAT
TWINE_PASSWORD: ${{ secrets.PYANSYS_PYPI_PRIVATE_PAT }}
TWINE_REPOSITORY_URL: https://pkgs.dev.azure.com/pyansys/_packaging/pyansys/pypi/upload
upload_dev_docs:
name: Upload dev documentation
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: [package]
steps:
- name: Deploy the latest documentation
uses: pyansys/actions/doc-deploy-dev@v3
with:
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Upload to Public PyPi
run: |
pip install twine
twine upload --skip-existing ./**/*.whl
twine upload --skip-existing ./**/*.tar.gz
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

- name: Release
uses: softprops/action-gh-release@v1
upload_docs_release:
name: Upload release documentation
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
runs-on: ubuntu-latest
needs: [release]
steps:
- name: Deploy the stable documentation
uses: pyansys/actions/doc-deploy-stable@v3
with:
files: |
./**/*.whl
./**/*.tar.gz
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}
python-version: ${{ env.MAIN_PYTHON_VERSION }}
10 changes: 8 additions & 2 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXOPTS = -j auto
SPHINXBUILD = sphinx-build
SOURCEDIR = source
BUILDDIR = build
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
Expand All @@ -23,3 +23,9 @@ help:
clean:
rm -rf build
find . -type d -name "_autosummary" -exec rm -rf {} +

# Create PDF
pdf:
@$(SPHINXBUILD) -M latex "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
cd $(BUILDDIR)/latex && latexmk -r latexmkrc -pdf *.tex -interaction=nonstopmode || true
(test -f $(BUILDDIR)/latex/*.pdf && echo pdf exists) || exit 1
Loading

0 comments on commit 3f26733

Please sign in to comment.