Skip to content

Commit c22695e

Browse files
committed
feat[ci]: Add notebook spell check with PR comments
1 parent 65712a2 commit c22695e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+331
-117
lines changed

.codespellrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[codespell]
2+
skip = .git,*.pdf,*.png,*.jpg,*.jpeg,*.gif,*.svg,*.bmp,*.tiff,*.pyc,venv,.venv,.ipynb_checkpoints
3+
check-filenames = true
4+
quiet-level = 2
5+
ignore-words-list = flexcompute,tidy3d,TE,TM,te,tm,FOM,fom,Commun,Thru
6+
ignore-regex = [a-f0-9]{40}
7+
builtin = clear,rare,informal

.github/workflows/lint-notebooks.yml

+67-16
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,78 @@
1-
name: "notebooks-linting"
1+
name: "lint-notebooks"
22

33
on:
4-
workflow_dispatch:
54
push:
6-
branches: [ main, develop ]
5+
branches: [ develop ]
76
pull_request:
8-
branches: [ main, develop ]
7+
branches: [ develop ]
8+
9+
permissions:
10+
contents: read
11+
pull-requests: write
912

1013
jobs:
1114
lint:
12-
name: Run notebook linting
15+
name: Run notebook linting and spell check
1316
runs-on: ubuntu-latest
1417
steps:
15-
- uses: actions/checkout@v4
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0 # required for changed-files action
22+
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v5
25+
26+
- name: Run ruff format check
27+
run: uvx ruff format --check --diff .
28+
29+
- name: Run ruff lint check
30+
run: uvx ruff check .
31+
32+
- name: Get changed notebook files
33+
id: changed_notebooks
34+
if: github.event_name == 'pull_request'
35+
uses: tj-actions/changed-files@v46
1636
with:
17-
fetch-depth: 1
18-
19-
- uses: astral-sh/ruff-action@v3
37+
files: |
38+
**.ipynb
39+
40+
- name: Run spell check on changed notebooks
41+
id: spellcheck
42+
if: github.event_name == 'pull_request' && steps.changed_notebooks.outputs.any_changed == 'true'
43+
continue-on-error: true
44+
run: |
45+
uvx python spellcheck.py ${{ steps.changed_notebooks.outputs.all_changed_files }} > spellcheck_output.txt || true
46+
47+
- name: Prepare spellcheck comment body
48+
id: prepare_comment
49+
if: >
50+
github.event_name == 'pull_request' &&
51+
steps.changed_notebooks.outputs.any_changed == 'true' &&
52+
steps.spellcheck.outcome == 'success' &&
53+
hashFiles('spellcheck_output.txt') != ''
54+
run: |
55+
echo "<!-- lint-notebooks-spellcheck-comment -->" > comment_body.txt
56+
echo "" >> comment_body.txt
57+
cat spellcheck_output.txt >> comment_body.txt
58+
echo "Generated by GitHub Action run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> comment_body.txt
59+
60+
- name: Find existing comment
61+
uses: peter-evans/find-comment@v3
62+
id: find_comment
63+
if: steps.prepare_comment.outcome == 'success'
64+
with:
65+
issue-number: ${{ github.event.pull_request.number }}
66+
comment-author: 'github-actions[bot]'
67+
body-includes: '<!-- lint-notebooks-spellcheck-comment -->'
68+
69+
- name: Post or Update spell check comment
70+
if: steps.prepare_comment.outcome == 'success'
71+
uses: peter-evans/create-or-update-comment@v4
2072
with:
21-
version: 0.5.5
22-
23-
- name: Run ruff format
24-
run: ruff format --check --diff .
25-
26-
- name: Run ruff check
27-
run: ruff check .
73+
token: ${{ secrets.GITHUB_TOKEN }}
74+
repository: ${{ github.repository }}
75+
issue-number: ${{ github.event.pull_request.number }}
76+
comment-id: ${{ steps.find_comment.outputs.comment-id }}
77+
body-path: comment_body.txt
78+
edit-mode: replace

AdjointPlugin0Quickstart.ipynb

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdjointPlugin10YBranchLevelSet.ipynb

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdjointPlugin11CircuitMZI.ipynb

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdjointPlugin12LightExtractor.ipynb

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdjointPlugin13Metasurface.ipynb

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdjointPlugin14PreFab.ipynb

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdjointPlugin1Intro.ipynb

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdjointPlugin2GradientChecking.ipynb

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdjointPlugin3InverseDesign.ipynb

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdjointPlugin5BoundaryGradients.ipynb

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdjointPlugin6GratingCoupler.ipynb

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdjointPlugin7Metalens.ipynb

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdjointPlugin8WaveguideBend.ipynb

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdjointPlugin9WDM.ipynb

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AndersonLocalization.ipynb

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)