diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 75fc127c3..48a2817a1 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -7,80 +7,232 @@ on: branches: - main +env: + MAIN_PYTHON_VERSION: '3.10' + PACKAGE_NAME: 'ansys-optislang-core' + IMPORT_NAME: 'ansys.optislang.core' + + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + + jobs: style: name: Code style runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: - python-version: 3.7 + python-version: ${{ env.MAIN_PYTHON_VERSION }} + - name: Install dependencies run: | - python -m pip install --upgrade pip flit tox + python -m pip install --upgrade pip tox + - name: Test with tox run: tox -e style + docs-style: + name: Documentation Style Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Running Vale + uses: errata-ai/vale-action@reviewdog + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + with: + files: doc + reporter: github-pr-check + level: error + filter_mode: nofilter + fail_on_error: true + vale_flags: "--config=doc/.vale.ini" tests: - name: Tests and coverage + name: Tests + needs: [style] runs-on: ${{ matrix.os }} strategy: matrix: - os: [windows-latest, ubuntu-latest] - python-version: ['3.7', '3.8', '3.9', '3.10'] + os: [windows-latest, ubuntu-latest, macos-latest] + cfg: + - {python-version: "3.7", toxenv: "py37"} + - {python-version: "3.8", toxenv: "py38"} + - {python-version: "3.9", toxenv: "py39"} + - {python-version: "3.10", toxenv: "py310"} fail-fast: false steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + - name: Clone repository + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.cfg.python-version }} + uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ matrix.cfg.python-version }} + - name: Install dependencies run: | - python -m pip install --upgrade pip flit tox tox-gh-actions + python -m pip install --upgrade pip tox + - name: Test with tox - # Only the tox environment specified in the tox.ini gh-actions is run - run: tox + run: tox -e ${{ matrix.cfg.toxenv }}-cov + + - name: Install package + run: | + python -m pip install -r requirements/requirements_build.txt + python -m pip install . + + - name: Store version + run: | + echo "::set-output name=PACKAGE_VERSION::$(python -c "from ${{ env.IMPORT_NAME }} import __version__; print(__version__)")" + id: version + + - name: Generate wheelhouse + run: | + pip wheel . -w wheelhouse + + - name: Zip wheelhouse + uses: vimtor/action-zip@v1 + with: + files: wheelhouse + dest: ${{ env.PACKAGE_NAME }}-v${{ steps.version.outputs.PACKAGE_VERSION }}-wheelhouse-${{ runner.os }}-${{ matrix.cfg.python-version }}.zip + + - name: Upload Wheelhouse + uses: actions/upload-artifact@v3 + with: + name: ${{ env.PACKAGE_NAME }}-v${{ steps.version.outputs.PACKAGE_VERSION }}-wheelhouse-${{ runner.os }}-${{ matrix.cfg.python-version }} + path: '*.zip' + retention-days: 7 + - name: Upload coverage results as artifacts + uses: actions/upload-artifact@v3 + if: | + (matrix.cfg.python-version == env.MAIN_PYTHON_VERSION) && + (runner.os == 'Linux') + with: + name: HTML-Coverage + path: .cov/html + retention-days: 7 + + # - name: Upload coverage to Codecov + # uses: codecov/codecov-action@v3 + # if: | + # (matrix.cfg.python-version == env.MAIN_PYTHON_VERSION) && + # (runner.os == 'Linux') + # with: + # files: .cov/coverage.xml docs: name: Documentation runs-on: ubuntu-latest + needs: [docs-style] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: - python-version: 3.7 - - name: Install OS packages - run: | - sudo apt update - sudo apt install pandoc + python-version: ${{ env.MAIN_PYTHON_VERSION }} + - name: Install dependencies run: | - python -m pip install --upgrade pip flit tox + sudo apt-get update && sudo apt-get install pandoc + python -m pip install --upgrade pip tox + - name: Generate the documentation with tox run: tox -e doc + - name: Upload documentation as artifact + uses: actions/upload-artifact@v3 + with: + name: HTML-Documentation + path: .tox/doc_out + retention-days: 7 + + # - name: Deploy documentation to gh-pages + # if: github.event_name == 'push' && contains(github.ref, 'refs/tags') + # uses: JamesIves/github-pages-deploy-action@v4.4.0 + # with: + # token: ${{ secrets.github_token }} + # branch: gh-pages + # folder: .tox/doc_out + # clean: true + # single-commit: true build: name: Build library + needs: [tests, docs] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: - python-version: 3.7 + python-version: ${{ env.MAIN_PYTHON_VERSION }} + - name: Install dependencies and build the library run: | - python -m pip install --upgrade pip flit + python -m pip install --upgrade pip python -m pip install -r requirements/requirements_build.txt - flit build + python -m build python -m twine check dist/* - + + - name: Upload wheel and binaries as artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ env.PACKAGE_NAME }}-packages + path: dist/ + retention-days: 7 + + release: + name: Release project + if: github.event_name == 'push' && contains(github.ref, 'refs/tags') + needs: [build] + runs-on: ubuntu-latest + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.MAIN_PYTHON_VERSION }} + + - uses: actions/download-artifact@v3 + + - name: Display structure of downloaded files + run: ls -R + + - 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 + + # - 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 + with: + files: | + ./**/*.whl + ./**/*.tar.gz + ./**/*.zip diff --git a/tox.ini b/tox.ini index 7659468f7..86499896d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,19 +1,11 @@ [tox] description = Default tox environments list envlist = - style,{py37,py38,py39,py310}{,-coverage}, doc + style,{py37,py38,py39,py310}{,-cov}, doc skip_missing_interpreters = true isolated_build = true isolated_build_env = build -[gh-actions] -description = The tox environment to be executed in gh-actions for a given python version -python = - 3.7: style,py37-coverage - 3.8: style,py38-coverage - 3.9: style,py39-coverage - 3.10: style,py310-coverage - [testenv] # ``LOCALAPPDATA`` environment variable must be specified in windows os passenv = * @@ -27,7 +19,7 @@ basepython = {style,reformat,doc,build}: python3 setenv = PYTHONUNBUFFERED = yes - coverage: PYTEST_EXTRA_ARGS = --cov=ansys.optislang --cov-report=term --cov-report=xml --cov-report=html + cov: PYTEST_EXTRA_ARGS = --cov=ansys.optislang.core --cov-report=term --cov-report=xml:.cov/coverage.xml --cov-report=html:.cov/html deps = -r{toxinidir}/requirements/requirements_tests.txt