Skip to content

Commit 697430b

Browse files
🤖 📦 Tests in Docker Image (#2404)
* Tests in docker? * Testing docker CI * Running with uv * Test uv action again * uv docker * depreciate gdspy * chore(github): use diff-cover for easy local diff coverage computation * add missing permissions for the Github token * fix fetch depth for change coverage computation and fix diff-cover args * use fetch-depth of 0 to fetch all of the history * move checks to local test script and add manual pre-commit hook * Now we can run tests * Test no vtk * run on deploynode * Further containerization * Remove uv references * Remove uv references * Test vtk installation * Correct python version * Try again * Does it work in debian * Does it work in debian * try if slim x11 is the issue * coverage reports * try * try * try * remove pre-commit and keep simple local scripts for testing * Does this work? * remove the general coverage report due to instabilities * fix runners * Requires right fetchdept * does this fix it * does it skip properly * Think we're in business * Gonna get tests running and then fix diff * Try again * final touches from review --------- Co-authored-by: Frederik Schubert <[email protected]>
1 parent f8d421d commit 697430b

File tree

5 files changed

+1790
-1511
lines changed

5 files changed

+1790
-1511
lines changed

.github/workflows/run_tests.yml

Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ on:
2424

2525
jobs:
2626
determine-test-scope:
27-
runs-on: [ inhouse ]
27+
runs-on: [ deploynode ]
2828
if: |
2929
github.event.pull_request.draft == false ||
3030
github.ref == 'refs/heads/develop' ||
@@ -115,7 +115,8 @@ jobs:
115115
needs: determine-test-scope
116116
if: ( needs.determine-test-scope.outputs.local_tests == 'true' ) || ( needs.determine-test-scope.outputs.remote_tests == 'true' )
117117
name: Run linting
118-
runs-on: [ inhouse ]
118+
runs-on: [ deploynode ]
119+
container: ghcr.io/astral-sh/uv:debian
119120
steps:
120121
- uses: actions/checkout@v4
121122
with:
@@ -132,8 +133,9 @@ jobs:
132133
# Run on open PRs OR when manually triggered with local_tests=true
133134
needs: determine-test-scope
134135
if: needs.determine-test-scope.outputs.local_tests == 'true'
135-
name: Python ${{ matrix.python-version }} - self-hosted-runner
136-
runs-on: [ inhouse ]
136+
name: Python ${{ matrix.python-version }} - self-hosted-runner
137+
runs-on: [ deploynode ]
138+
container: ghcr.io/astral-sh/uv:debian
137139
strategy:
138140
matrix:
139141
python-version: ['3.9', '3.13']
@@ -147,83 +149,95 @@ jobs:
147149
steps:
148150
- uses: actions/checkout@v4
149151
with:
150-
fetch-depth: 1
151-
152-
- name: Set up Python ${{ matrix.python-version }}
153-
uses: actions/setup-python@v4
154-
with:
155-
python-version: ${{ matrix.python-version }}
152+
fetch-depth: 0
156153

157154
- name: Install project
155+
env:
156+
PYTHON_VERSION: ${{ matrix.python-version }}
158157
run: |
159-
python -m venv ${GITHUB_WORKSPACE}/.venv
158+
if [ -f /.dockerenv ]; then
159+
echo "Running inside a Docker container (detected via /.dockerenv)"
160+
else
161+
echo "Not running inside a Docker container (/.dockerenv not found)"
162+
fi
163+
uv venv -p $PYTHON_VERSION ${GITHUB_WORKSPACE}/.venv
160164
source ${GITHUB_WORKSPACE}/.venv/bin/activate
161-
python --version
162165
which python
163-
which pip
164-
pip list
165-
pip install --upgrade pip wheel setuptools
166-
pip install gdstk --only-binary gdstk
167-
pip install -e ".[dev]"
166+
which uv
167+
python --version
168+
uv pip list
169+
uv pip install gdstk --only-binary gdstk
170+
uv pip install -e ".[dev]"
171+
172+
echo "Testing vtk is correctly installed."
173+
python -c "import vtk"
168174
169175
- name: Run tests with coverage
170176
env:
171177
PYTHONUNBUFFERED: "1"
172178
run: |
173179
source ${GITHUB_WORKSPACE}/.venv/bin/activate
174-
pytest --cov=tidy3d -rF --tb=short tests/_test_data/_test_datasets_no_vtk.py
180+
# pytest --cov=tidy3d -rF --tb=short tests/_test_data/_test_datasets_no_vtk.py
175181
pytest --cov=tidy3d -rF --tb=short tests
176182
coverage report -m
177-
coverage xml -o coverage.xml
183+
coverage xml -o ${GITHUB_WORKSPACE}/coverage.xml
178184
TOTAL_COVERAGE=$(coverage report --format=total)
179185
echo "total=$TOTAL_COVERAGE" >> "$GITHUB_ENV"
180186
echo "### Total coverage: ${TOTAL_COVERAGE}%"
181187
182-
- name: Produce the coverage report
183-
uses: insightsengineering/coverage-action@v2
184-
with:
185-
path: ./coverage.xml
186-
threshold: 90.0
187-
fail: false
188-
publish: true
189-
diff: true
190-
diff-branch: develop
191-
diff-storage: _xml_coverage_reports
192-
coverage-summary-title: "Code Coverage Summary"
193-
togglable-report: true
194-
195-
- name: Changed files
196-
id: diff
197-
uses: step-security/changed-files@v46
198-
with:
199-
files: '**/*.py'
188+
- name: verify-coverage-report-location
189+
run: |
190+
ls $GITHUB_WORKSPACE
200191
201-
- name: Slice report down to changed files
202-
if: ${{ steps.diff.outputs.all_changed_files != '' }}
203-
env:
204-
CHANGED: ${{ steps.diff.outputs.all_changed_files }}
192+
- name: Produce the diff coverage report
193+
if: matrix.python-version == '3.13'
205194
run: |
206-
echo $CHANGED
207195
source ${GITHUB_WORKSPACE}/.venv/bin/activate
208-
include=$(printf '%s\n' $CHANGED | sed 's|^|**/|' | paste -sd, -)
209-
coverage xml -i -o changed.xml --include="$include"
196+
git config --global --add safe.directory ${GITHUB_WORKSPACE}
197+
diff-cover ${GITHUB_WORKSPACE}/coverage.xml \
198+
--compare-branch origin/${{ github.event.pull_request.base.ref }} \
199+
--format markdown:diff-coverage.md
210200
211-
- name: Produce the changed files coverage report
212-
uses: insightsengineering/coverage-action@v2
213-
if: ${{ steps.diff.outputs.all_changed_files != '' }}
201+
- uses: actions/github-script@v7
202+
if: matrix.python-version == '3.13'
214203
with:
215-
path: ./changed.xml
216-
threshold: 90.0
217-
publish: true
218-
fail: false
219-
coverage-summary-title: "Changed Files Coverage"
204+
result-encoding: string
205+
script: |
206+
const fs = require('fs');
207+
const marker = '<!-- diff-cover-report -->';
208+
const body = fs.readFileSync('diff-coverage.md','utf8');
209+
const report = `${marker}\n${body}`;
210+
const {data:comments}=await github.rest.issues.listComments({
211+
owner:context.repo.owner,
212+
repo:context.repo.repo,
213+
issue_number:context.issue.number,
214+
});
215+
const existing = comments.find(c=>c.body.startsWith(marker));
216+
if(existing) {
217+
await github.rest.issues.updateComment({
218+
owner:context.repo.owner,
219+
repo:context.repo.repo,
220+
comment_id:existing.id,
221+
body:report,
222+
});
223+
} else {
224+
await github.rest.issues.createComment({
225+
owner:context.repo.owner,
226+
repo:context.repo.repo,
227+
issue_number:context.issue.number,
228+
body:report,
229+
});
230+
}
220231
221232
remote-tests:
222233
# Run tests on a push event OR a workflow dispatch with remote_tests
223234
needs: determine-test-scope
224235
if: needs.determine-test-scope.outputs.remote_tests == 'true'
225236
name: Python ${{ matrix.python-version }} - ${{ matrix.platform }}
226237
runs-on: ${{ matrix.platform }}
238+
permissions:
239+
contents: read
240+
pull-requests: write
227241
strategy:
228242
matrix:
229243
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
@@ -234,7 +248,7 @@ jobs:
234248
env: # Set environment variables for the whole job
235249
PIP_ONLY_BINARY: gdstk
236250
MPLBACKEND: agg
237-
251+
238252
concurrency:
239253
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}-${{ matrix.platform }}-${{ matrix.python-version }}-remote
240254
cancel-in-progress: true
@@ -299,7 +313,7 @@ jobs:
299313
name: pr-requirements-pass
300314
if: ( needs.determine-test-scope.outputs.local_tests == 'true' ) || ( needs.determine-test-scope.outputs.remote_tests == 'true' )
301315
needs: [local-tests, remote-tests, lint]
302-
runs-on: [ inhouse ]
316+
runs-on: [ deploynode ]
303317
steps:
304318
- name: check-passing-remote-tests
305319
run: |

0 commit comments

Comments
 (0)