1- name : CI
1+ name : CI-CD
22
33on :
44 push :
55 branches : [ "main" ]
66 pull_request :
77 branches : [ "main" ]
88
9- workflow_dispatch :
10-
119jobs :
12- linter-check :
13- runs-on : ubuntu-latest
14- steps :
15- - name : Checkout
16- uses : actions/checkout@v3
17- - name : Set up Python "3.10"
18- uses : actions/setup-python@v4
19- with :
20- python-version : " 3.10"
21- - name : Black setup
22- shell : bash
23- run : pip install black ruff mypy
24- - name : Black Check
25- shell : bash
26- run : black . --diff --color --check
27-
28- test-cpu :
10+ test :
2911 runs-on : ubuntu-latest
30- needs : linter-check
12+
3113 strategy :
32- fail-fast : true
3314 matrix :
34- python-version : ["3.12", "3.10"]
15+ python-version : [3.11, 3.12] # Specify the desired Python versions
3516
3617 steps :
37- - uses : actions/checkout@v3
38- - name : Set up Python ${{ matrix.python-version }}
39- uses : actions/setup-python@v4
40- with :
41- python-version : ${{ matrix.python-version }}
42- - name : Install Dependencies
43- shell : bash
44- run : |
45- python --version
46- python -m pip install --upgrade pip
47- python -m pip install .[test]
48- - name : Run Tests
49- shell : bash
50- run : |
51- export COVERAGE_FILE=coverage_${{ matrix.python-version }}
52- pytest -n auto --cov --disable-pytest-warnings --cov-branch --cov-report=term
53- - name : Upload coverage
54- if : success()
55- uses : actions/upload-artifact@v4
56- with :
57- name : coverage_${{ matrix.python-version }}
58- path : coverage_${{ matrix.python-version }}
59-
60- get-commit-message :
61- runs-on : ubuntu-latest
62- outputs :
63- message : ${{ steps.get_commit_message.outputs.message }}
64- steps :
65- - uses : actions/checkout@v3
66- with :
67- ref : ${{ github.event.pull_request.head.sha }}
68- - name : Get commit message
69- id : get_commit_message
70- run : |
71- COMMIT_MESSAGE=$(git log -1 --pretty=%B)
72- echo "Commit message $COMMIT_MESSAGE"
73- echo "::set-output name=message::$COMMIT_MESSAGE"
74-
75- coverage :
76- runs-on : ubuntu-latest
77- needs : [test-cpu, get-commit-message]
78- if : ${{ always() }}
79- steps :
80- - name : Checkout
81- uses : actions/checkout@v3
82-
83- - name : Collect Coverages
84- uses : actions/download-artifact@v4
85- with :
86- path : coverage_data
87- pattern : coverage_*
88- merge-multiple : true
89-
90- - name : Set up Python 3.10
91- uses : actions/setup-python@v4
92- with :
93- python-version : ${{ env.PYTHON_VERSION }}
94-
95- - name : add the coverage tool
96- shell : bash
97- run : |
98- python -m pip install --upgrade pip
99- python -m pip install coverage[toml]
100- python -m pip install -e .
101-
102- - name : Combine coverage
103- run : |
104- export COVERAGE_FILE=coverage_combined
105- coverage combine -a coverage_data/*
18+ - name : Checkout code
19+ uses : actions/checkout@v4
10620
107- - name : Upload Combined coverage
108- uses : actions/upload-artifact@v4
21+ - name : Set up Python
22+ uses : actions/setup-python@v5
10923 with :
110- name : coverage_combined
111- path : coverage_combined
112-
113- - name : Reports
114- run : |
115- export COVERAGE_FILE=coverage_combined
116- coverage xml
117- coverage report
118- echo COVERAGE_PERC=$(coverage report | tail -n 1 | grep -oE [0-9\.]*?% | cut -d '%' -f1) >> $GITHUB_ENV
24+ python-version : ${{ matrix.python-version }}
11925
120- - name : Create a Coverage Badge
121- if : ${{github.event_name == 'push'}}
26+ - name : Install dependencies
12227 run : |
123- wget https://img.shields.io/badge/coverage-${{env.COVERAGE_PERC}}%25-green -O coverage_badge.svg
28+ pip install .[test]
12429
125- - name : Upload badge as artifact
126- if : ${{github.event_name == 'push'}}
127- uses : actions/upload-artifact@v4
30+ - name : Run tests
31+ run : pytest --cov --cov-report=xml tests
32+
33+ - name : Upload coverage reports to Codecov
34+ uses : codecov/codecov-action@v4.0.1
12835 with :
129- name : coverage_badge
130- path : coverage_badge.svg
36+ token : ${{ secrets.CODECOV_TOKEN }}
37+ slug : INFN-MRI/torchsim
13138
132- BuildDocs :
133- name : Build API Documentation
134- runs-on : ubuntu-latest
135- needs : get-commit-message
136- if : ${{ contains(needs.get-commit-message.outputs.message, '!docs_build') || github.ref == 'refs/heads/main' }}
39+ docs :
40+ runs-on : ubuntu-20.04
41+ needs : test
13742 steps :
13843 - name : Checkout
139- uses : actions/checkout@v3
44+ uses : actions/checkout@v4
14045
141- - name : Get history and tags for SCM versioning to work
142- run : |
143- git fetch --prune --unshallow
144- git fetch --depth=1 origin +refs/tags/*:refs/tags/*
145-
14646 - name : Set up Python
147- uses : actions/setup-python@v4
47+ uses : actions/setup-python@v5
14848 with :
14949 python-version : " 3.10"
15050
151- - name : Restore cached ixi directory
51+ - name : Restore cached IXI directory
15252 uses : actions/cache/restore@v4
15353 id : cache-restore
15454 with :
@@ -166,49 +66,22 @@ jobs:
16666 run : |
16767 python -m sphinx docs docs_build
16868
169- - name : Display data
170- run : ls -R
171- working-directory : docs_build/_static
69+ - name : Display structure of docs
70+ run : ls -R docs_build/
17271
173- - name : Cache ixi directory
72+ - name : Cache IXI directory
17473 uses : actions/cache/save@v4
17574 if : ${{ steps.cache-restore.outputs.cache-hit != 'true' }}
17675 with :
17776 path : ~/.ixi
178- key : ${{ runner.os }}-ixi
179-
180- - name : Upload artifact
181- id : artifact-upload-step
182- uses : actions/upload-artifact@v4
183- with :
184- # Upload the docs
185- name : docs
186- path : ' docs_build'
187- retention-days : 5
188-
189- CompileDocs :
190- name : Compile the coverage badge in docs
191- runs-on : ubuntu-latest
192- if : ${{ github.ref == 'refs/heads/main' }}
193- needs : [BuildDocs, coverage]
194- steps :
195- - name : Get the docs_build artifact
196- uses : actions/download-artifact@v4
197- with :
198- name : docs
199- path : docs_build
200- overwrite : true
201-
202- - name : Get the badge from CI
203- uses : actions/download-artifact@v4
204- with :
205- name : coverage_badge
206- path : docs_build/_static
207- github-token : ${{ secrets.GITHUB_TOKEN }}
77+ key : ${{ runner.os }}-ixi
20878
209- - name : ReUpload artifacts
210- uses : actions/upload-artifact @v4
79+ - name : Deploy to GitHub Pages
80+ uses : peaceiris/actions-gh-pages @v4
21181 with :
212- name : docs_final
213- retention-days : 20
214- path : docs_build
82+ github_token : ${{ secrets.GITHUB_TOKEN }}
83+ publish_dir : ./docs_build
84+ destination_dir : . # Ensure you deploy to the root of the gh-pages branch
85+ publish_branch : gh-pages
86+ keep_files : false
87+
0 commit comments