Skip to content

Commit d43cb39

Browse files
feat: Proper semantic versioning schema-change verification (#2642)
* Create schema directory * chore: Autogenerate schemas * chore: Regenerate schema pre-commit * Add pre-commit * Add schema diff verification * fix * forgot venv * run on bash * a * Enforce changes * regenerate schemas * Maybe precommit makes sense now * Maybe precommit makes sense now * Maybe precommit makes sense now * Only trigger on PRs * semantics * standard naming * Implement heat simulation and feedback
1 parent 3299996 commit d43cb39

11 files changed

+48938
-40
lines changed

.github/workflows/tidy3d-python-client-tests.yml

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ jobs:
119119
lint:
120120
needs: determine-test-scope
121121
if: ( needs.determine-test-scope.outputs.local_tests == 'true' ) || ( needs.determine-test-scope.outputs.remote_tests == 'true' )
122-
name: Run linting
122+
name: verify-linting
123123
runs-on: ubuntu-latest
124124
container: ghcr.io/astral-sh/uv:debian
125125
steps:
@@ -134,7 +134,102 @@ jobs:
134134
run: ruff format --check --diff
135135
- name: Run ruff check
136136
run: ruff check tidy3d
137-
137+
138+
verify-schema-change:
139+
name: verify-schema-change
140+
needs: determine-test-scope
141+
if: (( needs.determine-test-scope.outputs.local_tests == 'true' ) || ( needs.determine-test-scope.outputs.remote_tests == 'true' )) && (github.event_name == 'pull_request')
142+
runs-on: ubuntu-latest
143+
container: ghcr.io/astral-sh/uv:debian
144+
defaults:
145+
run:
146+
shell: bash
147+
steps:
148+
- name: checkout-pr-branch
149+
uses: actions/checkout@v4
150+
with:
151+
path: 'pr'
152+
153+
- name: checkou-develop-branch
154+
uses: actions/checkout@v4
155+
with:
156+
ref: 'develop'
157+
path: 'develop'
158+
159+
- name: install-depedencies
160+
run: |
161+
uv venv $GITHUB_WORKSPACE/.venv -p 3.11
162+
source $GITHUB_WORKSPACE/.venv/bin/activate
163+
uv pip install -e "$GITHUB_WORKSPACE/pr"
164+
165+
- name: get-tidy3d-version
166+
id: get-version
167+
run: |
168+
source $GITHUB_WORKSPACE/.venv/bin/activate
169+
version=$(python -c "import tidy3d; print(tidy3d.__version__)")
170+
echo "tidy3d version is $version"
171+
echo "version=$version" >> $GITHUB_OUTPUT
172+
173+
- name: verify-committed-schema
174+
run: |
175+
echo "Regenerating schema to check if committed files are up-to-date..."
176+
source $GITHUB_WORKSPACE/.venv/bin/activate
177+
python $GITHUB_WORKSPACE/pr/scripts/regenerate_schema.py
178+
179+
echo "Checking for differences..."
180+
cd pr
181+
git diff --exit-code -- tidy3d/schemas
182+
echo "✅ Committed schema is up-to-date."
183+
184+
- name: run-schema-diff
185+
id: schema-diff
186+
run: |
187+
# Use git diff to compare the two directories and get a list of changes
188+
# The command exits with 0 if no changes, 1 if changes are found.
189+
# We use '|| true' to prevent the workflow from stopping here on failure.
190+
diff_output=$(git diff --no-index --name-status ./develop/tidy3d/schemas ./pr/tidy3d/schemas || true)
191+
192+
# Check if there are any changes
193+
if [ -z "$diff_output" ]; then
194+
echo "✅ Schemas are up-to-date."
195+
echo "changed=false" >> $GITHUB_OUTPUT
196+
exit 0
197+
fi
198+
199+
# If there are changes, create a Markdown table
200+
echo "❌ Schema has changed! Please regenerate and commit the changes."
201+
echo "changed=true" >> $GITHUB_OUTPUT
202+
203+
# Write the report to the GitHub Step Summary
204+
echo "### Schema Change Summary" >> $GITHUB_STEP_SUMMARY
205+
echo "| Status | File |" >> $GITHUB_STEP_SUMMARY
206+
echo "|:---:|:---|" >> $GITHUB_STEP_SUMMARY
207+
208+
echo "$diff_output" | while read -r line; do
209+
status_code=$(echo "$line" | cut -f1)
210+
file_path=$(echo "$line" | cut -f2 | sed 's#pr/tidy3d/schemas/##') # Clean up path
211+
212+
case $status_code in
213+
"A") status="Added 🟢";;
214+
"M") status="Modified 🟡";;
215+
"D") status="Removed 🔴";;
216+
*) status="Unknown";;
217+
esac
218+
219+
echo "| $status | \`$file_path\` |" >> $GITHUB_STEP_SUMMARY
220+
done
221+
222+
- name: verify-allowed-changes
223+
if: steps.schema-diff.outputs.changed == 'true'
224+
run: |
225+
version="${{ steps.get-version.outputs.version }}"
226+
if [[ "$version" == *rc* ]]; then
227+
echo "✅ Passing: Schema changed on a release candidate version ($version), which is permitted."
228+
else
229+
echo "❌ Failing: Schema changed on a non-rc release version ($version)."
230+
exit 1
231+
fi
232+
138233
local-tests:
139234
# Run on open PRs OR when manually triggered with local_tests=true
140235
needs: determine-test-scope
@@ -332,7 +427,7 @@ jobs:
332427
( needs.determine-test-scope.outputs.pr_approval_state == 'true' ) &&
333428
( needs.determine-test-scope.outputs.local_tests == 'true' ) ||
334429
( needs.determine-test-scope.outputs.remote_tests == 'true' )
335-
needs: [local-tests, remote-tests, lint]
430+
needs: [local-tests, remote-tests, lint, verify-schema-change]
336431
runs-on: ubuntu-latest
337432
steps:
338433
- name: check-passing-remote-tests
@@ -343,6 +438,9 @@ jobs:
343438
if [[ "${{ needs.lint.result }}" != 'success' ]]; then
344439
echo "❌ Linting failed or was skipped."
345440
exit 1
441+
elif [[ "${{ needs.verify-schema-change.result }}" != 'success' ]]; then
442+
echo "❌ verify-schema-change failed or was skipped."
443+
exit 1
346444
elif [[ "${{ needs.remote-tests.result }}" != 'success' ]]; then
347445
echo "❌ remote-tests failed or were skipped."
348446
exit 1 # Given remote-tests always run after a PR is approved

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@ repos:
55
- id: ruff-check
66
args: [ --fix ]
77
- id: ruff-format
8+
9+
- repo: local
10+
hooks:
11+
- id: regenerate-schema
12+
name: regenerate-schema
13+
entry: python scripts/regenerate_schema.py
14+
language: system
15+
files: ^tidy3d/.*\.py$ # Run only when Python files in the core 'tidy3d' directory are modified.
16+
stages: [pre-commit] # Explicitly run during the commit stage.

0 commit comments

Comments
 (0)