77 - dev
88 - main
99 - releasing/*
10- paths-ignore : # skip if only docs are modified
11- - ' **.md'
12- - ' **.rst'
13- - ' docs/**'
1410 pull_request :
1511 branches :
1612 - dev
1713 - main
1814 - releasing/*
19- paths-ignore : # skip if only docs are modified
20- - ' **.md'
21- - ' **.rst'
22- - ' docs/**'
2315
2416permissions :
2517 contents : read
5547# When support is dropped for a version it is important to update these as appropriate.
5648
5749jobs :
50+ # This job will set its output value `skip` to 2 if only documentation was changed, either documentation files or
51+ # the docstrings of source files. If any source lines are changed, or non-documentation files are changed, the
52+ # result is 0 which then triggers tests to run. This job works by using the compare_sources.py script to compare
53+ # changed files to see if they differ in ways other than comments or docstrings.
54+ test_skip :
55+ runs-on : ubuntu-latest
56+ outputs :
57+ skip : ${{ steps.check-changes.outputs.skip }}
58+ steps :
59+ - uses : actions/checkout@v7
60+ with :
61+ fetch-depth : 2
62+ - name : Set up Python ${{ env.PYTHON_VER1 }}
63+ uses : actions/setup-python@v6
64+ with :
65+ python-version : ${{ env.PYTHON_VER1 }}
66+ cache : ' pip'
67+ - name : Check File Changes
68+ id : check-changes
69+ shell : bash
70+ run : |
71+ echo "skip=1" >> $GITHUB_OUTPUT
72+
73+ mkdir -p /tmp/check_changes
74+ if ! git diff --name-only HEAD^..HEAD ':!docs' > /tmp/check_changes/changed_files
75+ then
76+ echo "skip=0" >> "$GITHUB_OUTPUT"
77+ exit 0
78+ fi
79+
80+ while read i
81+ do
82+ echo "Checking for changes: $i"
83+ if ! git show HEAD^:$i > /tmp/check_changes/$(basename $i)
84+ then
85+ echo "New file found, or 'git show' failed, running tests."
86+ elif ! python monai/utils/compare_sources.py $i /tmp/check_changes/$(basename $i)
87+ then
88+ echo "Change found, running tests."
89+ else
90+ continue
91+ fi
92+
93+ echo "skip=0" >> $GITHUB_OUTPUT
94+ break
95+ done < /tmp/check_changes/changed_files
96+
5897 static-checks : # Perform static type and other checks using runtests.sh
5998 runs-on : ubuntu-latest
6099 strategy :
87126
88127 min-dep : # Test with minumum dependencies installed for different OS, Python, and PyTorch combinations
89128 runs-on : ${{ matrix.os }}
129+ needs : test_skip
90130 strategy :
91131 fail-fast : false
92132 matrix :
@@ -123,25 +163,29 @@ jobs:
123163
124164 timeout-minutes : 40
125165 steps :
126- - if : runner.os == 'Linux'
127- name : Clean unused tools
166+ - name : Clean unused tools
167+ if : runner.os == 'Linux' && needs.test_skip.outputs.skip == 0
128168 run : |
129169 find /opt/hostedtoolcache/* -maxdepth 0 ! -name 'Python' -exec rm -rf {} \;
130170 sudo rm -rf /usr/share/dotnet
131171 sudo rm -rf /usr/local/lib/android
132172 sudo rm -rf /opt/ghc /usr/local/.ghcup
133173 sudo docker system prune -f
134174 - uses : actions/checkout@v7
175+ if : needs.test_skip.outputs.skip == 0
135176 - name : Set up Python ${{ matrix.python-version }}
177+ if : needs.test_skip.outputs.skip == 0
136178 uses : actions/setup-python@v6
137179 with :
138180 python-version : ${{ matrix.python-version }}
139181 cache : ' pip'
140182 - name : Prepare pip wheel
183+ if : needs.test_skip.outputs.skip == 0
141184 run : |
142185 which python
143186 python -m pip install --upgrade pip wheel tomli
144187 - name : Install the minimum dependencies
188+ if : needs.test_skip.outputs.skip == 0
145189 run : |
146190 # min. requirements
147191 python -m pip install torch==${{ matrix.pytorch-version }}
@@ -150,6 +194,7 @@ jobs:
150194 python -m pip list
151195 shell : bash
152196 - name : Run quick tests
197+ if : needs.test_skip.outputs.skip == 0
153198 run : |
154199 nvidia-smi || true
155200 python monai/config/check_env.py --env --monai
@@ -168,71 +213,77 @@ jobs:
168213 matrix :
169214 os : [windows-latest, ubuntu-latest, macOS-latest] # macOS-latest is very slow (#8864), testing install only
170215 timeout-minutes : 120
216+ needs : test_skip
171217 env :
172218 QUICKTEST : True
173219 steps :
174- - if : runner.os == 'Linux'
175- name : Clean unused tools
220+ - name : Clean unused tools
221+ if : runner.os == 'Linux' && needs.test_skip.outputs.skip == 0
176222 run : |
177223 find /opt/hostedtoolcache/* -maxdepth 0 ! -name 'Python' -exec rm -rf {} \;
178224 sudo rm -rf /usr/share/dotnet
179225 sudo rm -rf /usr/local/lib/android
180226 sudo rm -rf /opt/ghc /usr/local/.ghcup
181227 sudo docker system prune -f
182- - if : runner.os == 'windows'
183- name : Config pagefile (Windows only)
228+ - name : Config pagefile (Windows only)
229+ if : runner.os == 'windows' && needs.test_skip.outputs.skip == 0
184230 uses : al-cheb/configure-pagefile-action@v1.5
185231 with :
186232 minimum-size : 8GB
187233 maximum-size : 16GB
188234 disk-root : " D:"
189235 - uses : actions/checkout@v7
236+ if : needs.test_skip.outputs.skip == 0
190237 - name : Set up Python ${{ env.PYTHON_VER1 }}
238+ if : needs.test_skip.outputs.skip == 0
191239 uses : actions/setup-python@v6
192240 with :
193241 python-version : ${{ env.PYTHON_VER1 }}
194242 cache : ' pip'
195243 - name : Prepare pip wheel
244+ if : needs.test_skip.outputs.skip == 0
196245 run : |
197246 which python
198247 python -m pip install --upgrade pip wheel
199- - if : runner.os == 'windows'
248+ - if : runner.os == 'windows' && needs.test_skip.outputs.skip == 0
200249 name : Install torch cpu from pytorch.org (Windows only)
201250 run : |
202251 python -m pip install torch==${WIN_FULLDEP_VER} torchvision==${WIN_FULLDEP_VISION_VER}+cpu --index-url https://download.pytorch.org/whl/cpu
203252 shell : bash
204- - if : runner.os != 'windows'
253+ - if : runner.os != 'windows' && needs.test_skip.outputs.skip == 0
205254 name : Install torch gpu
206255 run : |
207256 # install the lowest version of PyTorch supported
208257 python -m pip install torch==${PYTORCH_VER1} torchvision==${TORCHVISION_VER1}
209258 shell : bash
210- - if : runner.os == 'Linux'
259+ - if : runner.os == 'Linux' && needs.test_skip.outputs.skip == 0
211260 name : Install itk pre-release (Linux only)
212261 run : |
213262 python -m pip install --pre -U itk
214263 shell : bash
215264 - name : Install the complete dependencies
265+ if : needs.test_skip.outputs.skip == 0
216266 run : |
217267 python -m pip install --user --upgrade pip wheel tomli
218268 python monai/config/print_dependencies.py build-system | xargs pip install --no-build-isolation
219269 python -m pip install --no-build-isolation .[all,testing]
220270 python -m pip list
221271 shell : bash
222272 - name : Run compiled (${{ runner.os }})
273+ if : needs.test_skip.outputs.skip == 0
223274 run : |
224275 python -m pip uninstall -y monai
225276 BUILD_MONAI=1 python -m pip install --no-build-isolation -e . # compile the cpp extensions
226277 python -c 'import monai._C' > /dev/null
227278 nvidia-smi || true
228279 python monai/config/check_env.py --env --monai
229280 shell : bash
230- - if : runner.os != 'macOS'
281+ - if : runner.os != 'macOS' && needs.test_skip.outputs.skip == 0
231282 name : Run full tests
232283 run : |
233284 python -m unittest -v
234285 shell : bash
235- - if : runner.os == 'macOS'
286+ - if : runner.os == 'macOS' && needs.test_skip.outputs.skip == 0
236287 name : Run min tests
237288 run : |
238289 # TODO: enable large range of macOS tests which don't take a very long time
@@ -252,6 +303,8 @@ jobs:
252303 # ``.github/workflows/pythonapp-hyena-gpu.yml``.
253304 runs-on : ubuntu-latest
254305 timeout-minutes : 30
306+ needs : test_skip
307+ if : needs.test_skip.outputs.skip == 0
255308 steps :
256309 - name : Clean unused tools
257310 run : |
0 commit comments