Devcontainer and coverage reporting #120
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
# Pipeline that checks branches that have been pushed to "Main" OR are the source branch in a newly created pull request into "Main" | |
# Fails the test if there are Python syntax errors or undefined names OR pytest fails | |
name: Pydicer Pytest and Pylint Validaiton | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ["3.8", "3.9"] | |
poetry-version: [1.7.1] | |
# os: [ubuntu-20.04, macos-latest, windows-latest] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install Poetry | |
uses: abatilo/[email protected] | |
with: | |
poetry-version: ${{ matrix.poetry-version }} | |
- name: Install Python modules with poetry | |
run: | | |
poetry run pip install --upgrade pip | |
poetry install | |
poetry run pip install TotalSegmentator | |
- name: Lint with Pylint | |
run: | | |
poetry run pylint pydicer | |
# Run tests with coverage & generate badge | |
- name: Conditional Pytest coverage | |
run: | | |
if [[ "${{ matrix.python-version }}" == "3.9" ]]; then | |
echo "Running Pytest with coverage..." | |
poetry run pip install pytest-cov coverage | |
# Omit CLI from coverage report since it's not fully developed | |
poetry run pytest --cov=pydicer --cov-report=xml --cov-config=.coveragerc | |
poetry run coverage report --fail-under=70 # Fail if coverage is less than 70% | |
else | |
echo "Running Pytest without coverage..." | |
poetry run pytest | |
fi | |
# Commit the coverage badge back to repo (only on main branch & for a specific Python version) | |
- name: Generate coverage and commit coverage badge | |
if: github.ref == 'refs/heads/main' && matrix.python-version == '3.9' | |
run: | | |
poetry run pip install coverage-badge # These only work with python >=3.9 | |
# Generate an SVG coverage badge | |
poetry run coverage-badge -o coverage.svg | |
# Configure git | |
git config user.name "github-actions" | |
git config user.email "[email protected]" | |
# Pull latest changes to avoid conflicts | |
git pull --rebase | |
# Stage and commit coverage.svg | |
git add coverage.svg | |
git commit -m "Update coverage badge" || echo "No changes to commit" | |
# Push commit | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |