44 workflow_dispatch :
55 push :
66 branches : [main, dev, demo]
7- paths :
8- - ' code/**'
9- - ' pyproject.toml'
10- - ' package.json'
11- - ' pytest.ini'
12- - ' .github/workflows/tests.yml'
137 pull_request :
148 branches : [main, dev, demo]
159 types :
2115 merge_group :
2216
2317jobs :
24- test_package :
25- name : Tests
18+ check-changes :
2619 runs-on : ubuntu-latest
20+ outputs :
21+ backend_changed : ${{ steps.filter.outputs.backend }}
22+ frontend_changed : ${{ steps.filter.outputs.frontend }}
2723 steps :
2824 - uses : actions/checkout@v6
25+ with :
26+ fetch-depth : 0
27+
28+ - name : Check for relevant changes
29+ id : filter
30+ uses : dorny/paths-filter@v3
31+ with :
32+ filters : |
33+ backend:
34+ - 'code/backend/**'
35+ - 'code/app.py'
36+ - 'code/create_app.py'
37+ - 'code/tests/**'
38+ - 'pyproject.toml'
39+ - 'pytest.ini'
40+ - '.github/workflows/tests.yml'
41+ frontend:
42+ - 'code/frontend/**'
43+ - 'package.json'
44+ - '.github/workflows/tests.yml'
45+
46+ - name : Log detected changes
47+ run : |
48+ echo "Backend changed: ${{ steps.filter.outputs.backend }}"
49+ echo "Frontend changed: ${{ steps.filter.outputs.frontend }}"
50+
51+ python-tests :
52+ name : Python Tests
53+ needs : check-changes
54+ if : needs.check-changes.outputs.backend_changed == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call'
55+ runs-on : ubuntu-latest
56+ steps :
57+ - uses : actions/checkout@v6
58+
2959 - name : Install Poetry
3060 run : pip install poetry
61+
3162 - name : Setup python
3263 uses : actions/setup-python@v6
3364 with :
3465 python-version : " 3.11"
3566 architecture : x64
3667 cache : ' poetry'
68+
3769 - name : Install dependencies through poetry
3870 run : |
3971 poetry install
72+
4073 - name : Get coverage artifact ID
4174 id : coverage-artifact
4275 uses : actions/github-script@v8
@@ -64,28 +97,32 @@ jobs:
6497 return workflowRuns.data.workflow_runs[0]?.id ?? "";
6598 result-encoding : string
6699 retries : 3
100+
67101 - name : Download main coverage artifact
68102 uses : actions/download-artifact@v7
69103 if : github.event_name == 'pull_request' && steps.coverage-artifact.outputs.result != ''
70- continue-on-error : true # There is a chance that the artifact doesn't exist, or has expired
104+ continue-on-error : true
71105 with :
72106 name : coverage
73107 path : " ${{ github.workspace }}/coverage-main"
74108 github-token : ${{ secrets.GITHUB_TOKEN }}
75109 run-id : ${{ steps.coverage-artifact.outputs.result }}
110+
76111 - name : Get coverage from main
77112 id : coverage-value
78113 run : |
79114 MIN_COVERAGE=0
80115
81116 if [[ -f "./coverage-main/coverage.xml" ]]; then
82- MIN_COVERAGE=$(grep -m 1 "<coverage" "./coverage-main/coverage.xml" | sed -E 's/.*line-rate="([^"]*)".*/\1/') # Extract the line rate from the XML
83- MIN_COVERAGE=$(awk "BEGIN {print int($MIN_COVERAGE * 100)}") # Turn into percentage, rounding down to avoid rounding issues
117+ MIN_COVERAGE=$(grep -m 1 "<coverage" "./coverage-main/coverage.xml" | sed -E 's/.*line-rate="([^"]*)".*/\1/')
118+ MIN_COVERAGE=$(awk "BEGIN {print int($MIN_COVERAGE * 100)}")
84119 fi
85120
86121 echo "MIN_COVERAGE=$MIN_COVERAGE" >> "$GITHUB_OUTPUT"
122+
87123 - name : Run Python Tests
88124 run : make python-test optional_args="--junitxml=coverage-junit.xml --cov=code --cov-report=term-missing --cov-report=xml:coverage.xml --cov-fail-under=${{ steps.coverage-value.outputs.MIN_COVERAGE }} ./code/tests"
125+
89126 - uses : actions/upload-artifact@v6
90127 if : ${{ !cancelled() }}
91128 with :
@@ -94,13 +131,24 @@ jobs:
94131 coverage-junit.xml
95132 coverage.xml
96133 if-no-files-found : error
134+
135+ - name : Lint
136+ run : make lint
137+
138+ frontend-tests :
139+ name : Frontend Tests
140+ needs : check-changes
141+ if : needs.check-changes.outputs.frontend_changed == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call'
142+ runs-on : ubuntu-latest
143+ steps :
144+ - uses : actions/checkout@v6
145+
97146 - name : Setup node
98147 uses : actions/setup-node@v6
99148 with :
100149 node-version : 20
101150 cache : " npm"
102151 cache-dependency-path : " code/frontend/package-lock.json"
152+
103153 - name : Run frontend unit tests
104154 run : make unittest-frontend
105- - name : Lint
106- run : make lint
0 commit comments