Skip to content

Commit

Permalink
update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mcencini committed Dec 5, 2024
1 parent 59372ae commit 18a30de
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 176 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Style

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]


workflow_dispatch:

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

env:
PYTHON_VERSION: "3.10"

jobs:
linter-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip

- name: Install Python deps
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install black ruff
python -m pip install -e .
- name: Black Check
shell: bash
run: black . --diff --color --check

# - name: ruff Check
# shell: bash
# run: ruff check src
199 changes: 36 additions & 163 deletions .github/workflows/test-ci.yml
Original file line number Diff line number Diff line change
@@ -1,154 +1,54 @@
name: CI
name: CI-CD

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:
test:
runs-on: ubuntu-latest
needs: linter-check

strategy:
fail-fast: true
matrix:
python-version: ["3.12", "3.10"]
python-version: [3.11, 3.12] # Specify the desired Python versions

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 --disable-pytest-warnings --cov-branch --cov-report=term
- name: Upload coverage
if: success()
uses: actions/upload-artifact@v4
with:
name: coverage_${{ matrix.python-version }}
path: 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: Checkout code
uses: actions/checkout@v4

- name: Upload Combined coverage
uses: actions/upload-artifact@v4
- name: Set up Python
uses: actions/setup-python@v5
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
python-version: ${{ matrix.python-version }}

- name: Create a Coverage Badge
if: ${{github.event_name == 'push'}}
- name: Install dependencies
run: |
wget https://img.shields.io/badge/coverage-${{env.COVERAGE_PERC}}%25-green -O coverage_badge.svg
pip install .[test]
- name: Upload badge as artifact
if: ${{github.event_name == 'push'}}
uses: actions/upload-artifact@v4
- name: Run tests
run: pytest --cov --cov-report=xml tests

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
name: coverage_badge
path: coverage_badge.svg
token: ${{ secrets.CODECOV_TOKEN }}
slug: INFN-MRI/torchsim

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/main' }}
docs:
runs-on: ubuntu-20.04
needs: test
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- 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
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Restore cached ixi directory
- name: Restore cached IXI directory
uses: actions/cache/restore@v4
id: cache-restore
with:
Expand All @@ -166,49 +66,22 @@ jobs:
run: |
python -m sphinx docs docs_build
- name: Display data
run: ls -R
working-directory: docs_build/_static
- name: Display structure of docs
run: ls -R docs_build/

- name: Cache ixi directory
- name: Cache IXI directory
uses: actions/cache/save@v4
if: ${{ steps.cache-restore.outputs.cache-hit != 'true' }}
with:
path: ~/.ixi
key: ${{ runner.os }}-ixi

- 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/main' }}
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 }}
key: ${{ runner.os }}-ixi

- name: ReUpload artifacts
uses: actions/upload-artifact@v4
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
name: docs_final
retention-days: 20
path: docs_build
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs_build
destination_dir: . # Ensure you deploy to the root of the gh-pages branch
publish_branch: gh-pages
keep_files: false

9 changes: 3 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ TorchSim is a pure Pytorch-based MR simulator, including analytical and EPG mode

|Coverage| |CI| |CD| |License| |Codefactor| |Sphinx| |PyPi| |Black| |PythonVersion|

.. |Coverage| image:: https://infn-mri.github.io/torchsim/_static/coverage_badge.svg
:target: https://infn-mri.github.io/torchsim

.. |CI| image:: https://github.com/INFN-MRI/torchsim/workflows/CI/badge.svg
:target: https://github.com/INFN-MRI/torchsim
.. |Coverage| image:: https://codecov.io/gh/INFN-MRI/torchsim/graph/badge.svg?token=qtB53xANwI
:target: https://codecov.io/gh/INFN-MRI/torchsim

.. |CD| image:: https://github.com/INFN-MRI/torchsim/workflows/CD/badge.svg
.. |CI/CD| image:: https://github.com/INFN-MRI/torchsim/workflows/CI-CD/badge.svg
:target: https://github.com/INFN-MRI/torchsim

.. |License| image:: https://img.shields.io/github/license/INFN-MRI/torchsim
Expand Down
14 changes: 7 additions & 7 deletions docs/sg_execution_times.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Computation times
=================
**01:31.589** total execution time for 4 files **from all galleries**:
**01:07.135** total execution time for 4 files **from all galleries**:

.. container::

Expand All @@ -33,14 +33,14 @@ Computation times
- Time
- Mem (MB)
* - :ref:`sphx_glr_generated_autoexamples_02-synth-data.py` (``../examples/02-synth-data.py``)
- 00:41.073
- 00:42.438
- 0.0
* - :ref:`sphx_glr_generated_autoexamples_03-fitting.py` (``../examples/03-fitting.py``)
- 00:24.580
- 0.0
* - :ref:`sphx_glr_generated_autoexamples_04-derivatives.py` (``../examples/04-derivatives.py``)
- 00:14.056
- 00:24.697
- 0.0
* - :ref:`sphx_glr_generated_autoexamples_01-simple-simulator.py` (``../examples/01-simple-simulator.py``)
- 00:11.881
- 00:00.000
- 0.0
* - :ref:`sphx_glr_generated_autoexamples_04-derivatives.py` (``../examples/04-derivatives.py``)
- 00:00.000
- 0.0

0 comments on commit 18a30de

Please sign in to comment.