Skip to content

Update test-ci.yml

Update test-ci.yml #11

Workflow file for this run

name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
linter-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python "3.10"
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Black setup
shell: bash
run: pip install black ruff mypy
- name: Black Check
shell: bash
run: black . --diff --color --check
test-cpu:
runs-on: ubuntu-latest
needs: linter-check
strategy:
fail-fast: true
matrix:
python-version: ["3.12", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
shell: bash
run: |
python --version
python -m pip install --upgrade pip
python -m pip install .[test]
- name: Run Tests
shell: bash
run: |
export COVERAGE_FILE=coverage_${{ matrix.python-version }}
pytest -n auto --cov=src --cov-report xml:coverage.xml --cov-report term-missing:skip-covered --ignore=tests/phantoms/test_brainweb.py --ignore=tests/phantoms/test_osf.py
path: coverage_${{ matrix.backend }}
- name: Upload coverage
if: success()
uses: actions/upload-artifact@v4
with:
name: coverage_${{ matrix.python-version }}
get-commit-message:
runs-on: ubuntu-latest
outputs:
message: ${{ steps.get_commit_message.outputs.message }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get commit message
id: get_commit_message
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
echo "Commit message $COMMIT_MESSAGE"
echo "::set-output name=message::$COMMIT_MESSAGE"
coverage:
runs-on: ubuntu-latest
needs: [test-cpu, get-commit-message]
if: ${{ always() }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Collect Coverages
uses: actions/download-artifact@v4
with:
path: coverage_data
pattern: coverage_*
merge-multiple: true
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: add the coverage tool
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install coverage[toml]
python -m pip install -e .
- name: Combine coverage
run: |
export COVERAGE_FILE=coverage_combined
coverage combine -a coverage_data/*
- name: Upload Combined coverage
uses: actions/upload-artifact@v4
with:
name: coverage_combined
path: coverage_combined
- name: Reports
run: |
export COVERAGE_FILE=coverage_combined
coverage xml
coverage report
echo COVERAGE_PERC=$(coverage report | tail -n 1 | grep -oE [0-9\.]*?% | cut -d '%' -f1) >> $GITHUB_ENV
- name: Create a Coverage Badge
if: ${{github.event_name == 'push'}}
run: |
wget https://img.shields.io/badge/coverage-${{env.COVERAGE_PERC}}%25-green -O coverage_badge.svg
- name: Upload badge as artifact
if: ${{github.event_name == 'push'}}
uses: actions/upload-artifact@v4
with:
name: coverage_badge
path: coverage_badge.svg
BuildDocs:
name: Build API Documentation
runs-on: ubuntu-latest
needs: get-commit-message
if: ${{ contains(needs.get-commit-message.outputs.message, '!docs_build') || github.ref == 'refs/heads/master' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get history and tags for SCM versioning to work
run: |
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
shell: bash -l {0}
run: |
python -m pip install --upgrade pip
python -m pip install .[doc]
python -m pip install finufft
- name: Build API documentation
run: |
python -m sphinx docs docs_build
- name: Display data
run: ls -R
working-directory: docs_build/_static
- name: Upload artifact
id: artifact-upload-step
uses: actions/upload-artifact@v4
with:
# Upload the docs
name: docs
path: 'docs_build'
retention-days: 5
CompileDocs:
name: Compile the coverage badge in docs
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/master' }}
needs: [BuildDocs, coverage]
steps:
- name: Get the docs_build artifact
uses: actions/download-artifact@v4
with:
name: docs
path: docs_build
overwrite: true
- name: Get the badge from CI
uses: actions/download-artifact@v4
with:
name: coverage_badge
path: docs_build/_static
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: ReUpload artifacts
uses: actions/upload-artifact@v4
with:
name: docs_final
retention-days: 20
path: docs_build