Skip to content

Commit 87b4e93

Browse files
Fix conditional GitHub testing (SimVascular#430)
* first pass at refactoring the github testing * Streamline check_for_changes logic * Minor update to comments * Reorg and rename tests * Moving test workflows out of test_workflows/ subdirectory because not allowed by Github * modify README to test * modify README to test * Update check for changes to compare against the previous commit in paths-filter * Update paths-filter base comparison to use pull request base SHA or previous commit * test modify README * Remove test modify README * Refactor testing using composite actions * Move checkout code to calling workflow * Move codecov_token from inside actions * test modify README only * Renaming coordinating job name to all-tests (more descriptive) * undo modify README * Remove skip-tests/action.yml * test modify README on open PR * undo test modify README on open PR
1 parent 6ae4572 commit 87b4e93

File tree

6 files changed

+233
-134
lines changed

6 files changed

+233
-134
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: 'Test macOS'
2+
description: 'Run tests on macOS with all dependencies'
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Install macOS dependencies
8+
shell: bash
9+
run: |
10+
brew reinstall -v gcc
11+
brew install -v vtk openblas lapack mesa open-mpi qt
12+
brew install lcov
13+
sudo ln -s /usr/local/opt/qt5/mkspecs /usr/local/mkspecs
14+
sudo ln -s /usr/local/opt/qt5/plugins /usr/local/plugins
15+
16+
- name: Install Miniconda
17+
shell: bash
18+
run: |
19+
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
20+
bash Miniconda3-latest-MacOSX-x86_64.sh -b -p $HOME/miniconda
21+
echo "$HOME/miniconda/bin" >> $GITHUB_PATH
22+
23+
- name: Build svZeroDSolver
24+
shell: bash
25+
run: |
26+
git clone https://github.com/SimVascular/svZeroDSolver.git
27+
cd svZeroDSolver
28+
mkdir build
29+
cd build
30+
cmake ..
31+
make -j2
32+
33+
- name: Build svMultiPhysics
34+
shell: bash
35+
run: |
36+
mkdir build
37+
cd build
38+
cmake -DENABLE_COVERAGE=ON -DENABLE_ARRAY_INDEX_CHECKING=ON -DENABLE_UNIT_TEST=ON ..
39+
make -j2
40+
41+
- name: Install test dependencies
42+
shell: bash
43+
run: |
44+
conda create -n svmultiphysics python=3.9
45+
conda run -n svmultiphysics pip install pytest pytest-cov pytest-mock numpy meshio pandas
46+
47+
- name: Run integration tests
48+
shell: bash
49+
run: |
50+
git lfs pull
51+
cd tests
52+
conda run -n svmultiphysics pytest -rPv --durations=0
53+
54+
- name: Run unit tests
55+
shell: bash
56+
run: |
57+
cd build/svMultiPhysics-build/Source/solver
58+
ctest --verbose
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: 'Test Ubuntu'
2+
description: 'Run tests on Ubuntu with coverage reporting'
3+
4+
inputs:
5+
codecov-token:
6+
description: 'Codecov token for uploading coverage reports'
7+
required: false
8+
default: ''
9+
10+
runs:
11+
using: 'composite'
12+
steps:
13+
- name: Build svZeroDSolver
14+
shell: bash
15+
run: |
16+
conda init
17+
source /conda/etc/profile.d/conda.sh
18+
conda activate svmultiphysics
19+
git clone https://github.com/SimVascular/svZeroDSolver.git
20+
cd svZeroDSolver
21+
mkdir build
22+
cd build
23+
cmake ..
24+
make -j2
25+
26+
- name: Build svMultiPhysics
27+
shell: bash
28+
run: |
29+
if [ -d "build" ]; then
30+
rm -rf "build"
31+
fi
32+
mkdir build
33+
cd build
34+
cmake -DENABLE_COVERAGE=ON -DENABLE_ARRAY_INDEX_CHECKING=ON -DENABLE_UNIT_TEST=ON -DSV_USE_TRILINOS:BOOL=ON ..
35+
make -j2
36+
cd ..
37+
38+
- name: Build svMultiPhysics (PETSc)
39+
shell: bash
40+
run: |
41+
if [ -d "build-petsc" ]; then
42+
rm -rf "build-petsc"
43+
fi
44+
mkdir build-petsc
45+
cd build-petsc
46+
cmake -DENABLE_COVERAGE=ON -DENABLE_ARRAY_INDEX_CHECKING=ON -DENABLE_UNIT_TEST=ON -DSV_PETSC_DIR:STRING=/petsc ..
47+
make -j2
48+
cd ..
49+
50+
- name: Run integration tests
51+
shell: bash
52+
run: |
53+
git config --global --add safe.directory /__w/svMultiPhysics/svMultiPhysics
54+
git lfs pull
55+
cd tests
56+
conda run -n svmultiphysics pytest -rPv --durations=0
57+
58+
- name: Run unit tests
59+
shell: bash
60+
run: |
61+
cd build/svMultiPhysics-build/Source/solver
62+
ctest --verbose
63+
64+
- name: Generate code coverage
65+
shell: bash
66+
run: |
67+
cd build/svMultiPhysics-build
68+
make coverage
69+
70+
- name: Save coverage report
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: coverage_report
74+
path: build/svMultiPhysics-build/coverage
75+
76+
- name: Upload coverage reports to Codecov
77+
uses: codecov/codecov-action@v5
78+
env:
79+
CODECOV_TOKEN: ${{ inputs.codecov-token }}

.github/workflows/test_macos.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/test_ubuntu.yml

Lines changed: 0 additions & 76 deletions
This file was deleted.

.github/workflows/tests.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
# Check if there are any changes to important code files
9+
check-for-changes:
10+
name: Check for relevant changes
11+
runs-on: ubuntu-latest
12+
outputs:
13+
run_full_tests: ${{ steps.set-outputs.outputs.run_full_tests }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Check for relevant file changes
19+
uses: dorny/paths-filter@v3
20+
id: filter
21+
with:
22+
base: ${{ github.event.pull_request.base.sha || github.event.before }}
23+
filters: |
24+
relevant:
25+
- 'Code/**'
26+
- 'tests/**'
27+
- '.github/**'
28+
29+
- name: Set test execution flag
30+
id: set-outputs
31+
run: |
32+
if [ "${{ steps.filter.outputs.relevant }}" = "true" ]; then
33+
echo "run_full_tests=true" >> "$GITHUB_OUTPUT"
34+
else
35+
echo "run_full_tests=false" >> "$GITHUB_OUTPUT"
36+
fi
37+
38+
# Run Ubuntu tests when relevant changes detected
39+
test-ubuntu:
40+
name: Test Ubuntu
41+
runs-on: ubuntu-latest
42+
container: simvascular/libraries:ubuntu22
43+
needs: check-for-changes
44+
if: ${{ needs.check-for-changes.outputs.run_full_tests == 'true' }}
45+
steps:
46+
- name: Checkout code
47+
uses: actions/checkout@v4
48+
- name: Run Ubuntu tests
49+
uses: ./.github/actions/test-ubuntu
50+
with:
51+
codecov-token: ${{ secrets.CODECOV_TOKEN }}
52+
53+
# Run macOS tests when relevant changes detected
54+
test-macos:
55+
name: Test macOS
56+
runs-on: macos-latest
57+
needs: check-for-changes
58+
if: ${{ needs.check-for-changes.outputs.run_full_tests == 'true' }}
59+
steps:
60+
- name: Checkout code
61+
uses: actions/checkout@v4
62+
- name: Run macOS tests
63+
uses: ./.github/actions/test-macos
64+
65+
# Single coordinating job for branch protection rules
66+
# This job succeeds if:
67+
# 1. Tests are skipped (no relevant changes) OR
68+
# 2. All tests pass (both Ubuntu and macOS)
69+
# This job fails only if tests actually fail
70+
all-tests:
71+
name: All Tests
72+
runs-on: ubuntu-latest
73+
needs: [check-for-changes, test-ubuntu, test-macos]
74+
if: always()
75+
steps:
76+
- name: Determine results of tests
77+
run: |
78+
# If tests were skipped, the job should succeed
79+
if [ "${{ needs.check-for-changes.outputs.run_full_tests }}" = "false" ]; then
80+
echo "✅ Tests were skipped - no relevant changes detected"
81+
exit 0
82+
fi
83+
84+
# If tests were supposed to run, check if they passed
85+
if [ "${{ needs.check-for-changes.outputs.run_full_tests }}" = "true" ]; then
86+
if [ "${{ needs.test-ubuntu.result }}" = "success" ] && [ "${{ needs.test-macos.result }}" = "success" ]; then
87+
echo "✅ All tests passed successfully"
88+
exit 0
89+
else
90+
echo "❌ One or more tests failed"
91+
echo "Ubuntu test result: ${{ needs.test-ubuntu.result }}"
92+
echo "macOS test result: ${{ needs.test-macos.result }}"
93+
exit 1
94+
fi
95+
fi

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,4 @@ mpirun --mca mpi_cuda_support 0 -n #TotalNumberOfTasks ...
397397
- if for some reason, it is complaining about not finding 'munge' then add --mca psec ^munge:
398398
```
399399
mpirun --mca psec ^munge -n #TotalNumberOfTasks ...
400-
```
400+
```

0 commit comments

Comments
 (0)