Skip to content

Commit

Permalink
CI: update CI/CD workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
SMoraisAnsys committed Feb 14, 2024
1 parent 59f5de2 commit 4236c7a
Showing 1 changed file with 92 additions and 259 deletions.
351 changes: 92 additions & 259 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
@@ -1,301 +1,134 @@
name: CI-CD
name: Github CI-CD

on:
pull_request:
workflow_dispatch:
inputs:
freeze_linux:
type: boolean
default: true
description: Freeze linux
freeze_windows:
type: boolean
default: false
description: Freeze windows
force_release:
type: boolean
default: false
description: Force to push a release now
push:
tags:
- "*"
branches:
- "main"
pull_request:
branches:
- "main"
schedule:
- cron: "0 1 * * 1-5"
schedule: # UTC at 0300
- cron: "0 3 * * *"

env:
MAIN_PYTHON_VERSION: '3.10'
PACKAGE_NAME: 'pyaedt-examples'

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

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
- uses: ansys/actions/code-style@v5
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools tox
- name: Test with tox
run: tox -e style
use-python-cache: false

tests:
name: Tests and coverage
needs: [freeze]
runs-on: ${{ matrix.os }}
strategy:
# max-parallel: 1
matrix:
os: [ubuntu-latest]
cfg:
- {python-version: "3.10", toxenv: "py310"}
fail-fast: false

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.cfg.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.cfg.python-version }}

- uses: extractions/netrc@v1
with:
machine: github.com
username: pyansys-ci-bot
password: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools tox tox-gh-actions
- name: Test with tox
run: tox -e ${{ matrix.cfg.toxenv }}-coverage
# env:

- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: '**/test*.xml'
check_name: Test Report ${{ matrix.os }}:${{ matrix.cfg.python-version }}

wheels:
name: Wheels
doc-style:
name: Documentation style
runs-on: ubuntu-latest
outputs:
version: ${{ steps.wheels.outputs.version }}
steps:
- uses: actions/checkout@v3

- name: Set up python
uses: actions/setup-python@v3
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}

- uses: extractions/netrc@v1
with:
machine: github.com
username: pyansys-ci-bot
password: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}

- name: Install dependencies and build the library
id: wheels
run: |
python -m pip install --upgrade pip setuptools
python -m pip install -r requirements/requirements_build.txt
python build.py dev
python build.py wheels
python -m twine check dist/*
version=$(ls dist/ | grep template | grep -E -o "[0-9]+.[0-9]+.[0-9]+")
echo "version=$version" >> $GITHUB_OUTPUT
echo "Version: $version"
# - name: Version
# run: |
# ver=$(dev_env/bin/pip show ansys-rep-common | grep Version | awk '{print $2}')
# echo "version=$ver" >> $GITHUB_OUTPUT
# id: version

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ansys-rep-repo-template-package
path: |
dist/*.whl
retention-days: 5
- uses: ansys/actions/doc-style@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}

freeze:
name: Freeze
runs-on:
group: "Default Larger Runners"
labels: ubuntu-latest-16-cores
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.freeze_linux == 'true' }}
needs: [wheels, style]
strategy:
matrix:
image: [default]
fail-fast: false
doc-build:
name: Build documentation
runs-on: [windows-latest, pyaedt]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: ccache
uses: hendrikmuhs/ccache-action@v1.2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
- name: Set up Python ${{ env.MAIN_PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
registry: ghcr.io/ansys
username: pyansys-ci-bot
password: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
python-version: ${{ env.MAIN_PYTHON_VERSION }}

- name: Create .netrc
- name: Create virtual environment
run: |
printf "machine github.com\n\
login pyansys-ci-bot\n\
password ${{ secrets.PYANSYS_CI_BOT_TOKEN }}\n"\ >> ./.netrc
chmod 600 ./.netrc
python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install pip -U
python -m pip install wheel setuptools -U
python -c "import sys; print(sys.executable)"
- name: Image and docker properties
id: props
- name: Install project and documentation dependencies
run: |
echo "image=rep-repo-template-${{ matrix.image }}:${{github.run_id}}" >> $GITHUB_OUTPUT
echo "container=rep-repo-template-${{ matrix.image }}-${{github.run_id}}" >> $GITHUB_OUTPUT
echo "revision=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "short_revision=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
.venv\Scripts\Activate.ps1
pip install .
pip install .[doc]
# Copy-Item -Path "C:\actions-runner\opengl32.dll" -Destination ".venv\Lib\site-packages\vtkmodules" -Force
- name: Build image
uses: docker/build-push-action@v3
with:
push: false
context: .
tags: ${{ steps.props.outputs.image }}
file: docker/Dockerfile.${{ matrix.image }}
secret-files: |
"netrc=./.netrc"
outputs: type=docker,dest=/tmp/rep-repo-template-${{ matrix.image }}-image.tar
cache-from: type=gha
cache-to: type=gha,mode=max
secrets: |
GIT_AUTH_TOKEN=${{ secrets.PYANSYS_CI_BOT_TOKEN }}
build-args: |
branch=${{github.ref_name}}
revision=${{steps.props.outputs.revision}}
short_revision=${{steps.props.outputs.short_revision}}
- name: Load images
- name: Create HTML documentation
run: |
docker load --input /tmp/rep-repo-template-${{ matrix.image }}-image.tar
- name: Get binary
id: get-binary
run: |
docker image ls
docker run -d --name ${{ steps.props.outputs.container }} ${{ steps.props.outputs.image }}
docker cp ${{ steps.props.outputs.container }}:/app/rep-repo-template ./rep-repo-template-${{ matrix.image }}
chmod +x ./rep-repo-template-${{ matrix.image }}
.venv\Scripts\Activate.ps1
cd doc
.\make.bat html
- name: Test binary
run: |
version=$(docker exec ${{ steps.props.outputs.container }} /app/rep-repo-template)
echo "$version"
echo "$version" >> $GITHUB_STEP_SUMMARY
- name: Stop container
if: ${{ always() }}
run: |
docker container stop ${{steps.props.outputs.container}}
# - name: Upload image
# uses: actions/upload-artifact@v3
# with:
# name: rep-repo-template-${{ matrix.image }}-image
# path: /tmp/rep-repo-template-${{ matrix.image }}-image.tar
# retention-days: 1

- name: Upload artifact
- name: Upload HTML documentation artifact
uses: actions/upload-artifact@v3
with:
name: rep-repo-template-${{matrix.image}}
path: rep-repo-template-${{matrix.image}}

freeze-windows:
name: Freeze (windows)
runs-on:
group: "Default Larger Runners"
labels: windows-latest-8-cores
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.freeze_windows == 'true' }}
needs: [wheels, style]
steps:
- uses: actions/checkout@v3
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2

- name: Set up python
uses: actions/setup-python@v4
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: |
requirements/requirements_*.txt
**/setup.py
- uses: extractions/netrc@v1
with:
machine: github.com
username: pyansys-ci-bot
password: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
name: documentation-html
path: doc/_build/html
retention-days: 7

- name: Prepare venv
- name: Create PDF documentation
run: |
python -m venv dev_env
dev_env\Scripts\python build.py dev
.venv\Scripts\Activate.ps1
cd doc
.\doc\make.bat pdf
- name: Freeze
run: |
dev_env\Scripts\python build.py dist
# - name: Test binary
# run: |
# ./freeze/build/rep-repo-template.exe --version
# $version = (./freeze/build/rep-repo-template.exe --version) | Out-String
# echo "$version"
# echo "$version" >> $env:GITHUB_STEP_SUMMARY

# - name: Setup tmate session
# if: ${{ failure() && github.event_name == 'workflow_dispatch' && inputs.ssh_enabled }}
# uses: mxschmitt/action-tmate@v3
# with:
# ## limits ssh access and adds the ssh public key for the user which triggered the workflow
# limit-access-to-actor: true
# ## limits ssh access and adds the ssh public keys of the listed GitHub users
# # limit-access-to-users: [username]

- name: Upload artifact
- name: Upload HTML documentation artifact
uses: actions/upload-artifact@v3
with:
name: rep-repo-template-windows
path: freeze/build/rep-repo-template.exe

release:
name: Create release
uses: ansys-internal/rep-job-management/.github/workflows/release.yml@main
needs: ['freeze','wheels','tests']
secrets: inherit
with:
tag: v${{ needs.wheels.outputs.version }}
force_release: ${{ github.event.inputs.force_release == 'true' }}
artifact: .*rep-launcher-service.*
files: |
/tmp/bin/*/*.whl
/tmp/bin/*/rep-launcher-service-*
name: documentation-html-edb
path: doc/_build/html/EDBAPI
retention-days: 7

# - name: Upload PDF documentation artifact
# uses: actions/upload-artifact@v3
# with:
# name: documentation-pdf
# path: doc/_build/pdf
# retention-days: 7

# - name: Release
# uses: softprops/action-gh-release@v1
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
# with:
# generate_release_notes: true
# files: |
# doc/_build/pdf



# release:
# if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
# needs: [doc-style, code-style]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4

# - uses: actions/download-artifact@v3

# - name: Display structure of downloaded files
# run: ls -R

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

# - name: Release
# uses: softprops/action-gh-release@v1
# with:
# generate_release_notes: true
# files: |
# ./documentation-html.zip
# ./documentation-pdf/*.pdf

0 comments on commit 4236c7a

Please sign in to comment.