Skip to content

Commit e6fa86a

Browse files
robtaylorclaude
andcommitted
Add GitHub workflow to test tutorial code examples
- Validates all code examples referenced in tutorial.md - Runs each example to verify it works correctly - Checks generated outputs (Verilog files and simulation waveforms) - Creates a test summary of which examples passed/failed - Archives results as workflow artifacts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 7388ec2 commit e6fa86a

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: Tutorial Code Test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- 'tutorial.md'
8+
- 'docs/_code/**'
9+
- '.github/workflows/tutorial-test.yml'
10+
pull_request:
11+
branches: [ main ]
12+
paths:
13+
- 'tutorial.md'
14+
- 'docs/_code/**'
15+
- '.github/workflows/tutorial-test.yml'
16+
workflow_dispatch: # Allow manual trigger
17+
18+
jobs:
19+
validate-tutorial:
20+
name: Validate Tutorial Content
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v3
25+
26+
- name: Check tutorial refers to existing files
27+
run: |
28+
# Extract code filename references from tutorial.md
29+
TUTORIAL_FILES=$(grep -o "```python.*\.py" tutorial.md | grep -o "[a-zA-Z_]*\.py" | sort | uniq)
30+
31+
echo "Files mentioned in tutorial.md:"
32+
echo "$TUTORIAL_FILES"
33+
34+
# Check if each mentioned file exists in docs/_code/
35+
for file in $TUTORIAL_FILES; do
36+
if [ ! -f "docs/_code/$file" ]; then
37+
echo "Error: $file mentioned in tutorial.md but missing from docs/_code/"
38+
exit 1
39+
else
40+
echo "✓ Found docs/_code/$file"
41+
fi
42+
done
43+
44+
test-tutorial:
45+
name: Test Tutorial Code
46+
runs-on: ubuntu-latest
47+
needs: validate-tutorial
48+
49+
steps:
50+
- name: Checkout code
51+
uses: actions/checkout@v3
52+
53+
- name: Set up Python
54+
uses: actions/setup-python@v4
55+
with:
56+
python-version: '3.9'
57+
58+
- name: Install PDM
59+
run: |
60+
pip install pdm
61+
62+
- name: Install dependencies
63+
run: |
64+
sudo apt-get update
65+
sudo apt-get install -y gtkwave
66+
pdm install
67+
68+
- name: Run and_gate.py example
69+
run: |
70+
pdm run python docs/_code/and_gate.py
71+
ls -la and_gate.v && head -n 10 and_gate.v
72+
73+
- name: Run blinky.py example
74+
run: |
75+
pdm run python docs/_code/blinky.py
76+
ls -la blinky.vcd
77+
78+
- name: Run up_counter.py example
79+
run: |
80+
pdm run python docs/_code/up_counter.py
81+
ls -la counter.v && head -n 10 counter.v
82+
83+
- name: Run uart_receiver.py example
84+
run: |
85+
pdm run python docs/_code/uart_receiver.py
86+
ls -la uart_rx.v && head -n 10 uart_rx.v
87+
88+
- name: Run uart_sim.py example
89+
run: |
90+
pdm run python docs/_code/uart_sim.py
91+
ls -la uart_sim.vcd
92+
93+
- name: Run controlled_blinker.py example
94+
run: |
95+
pdm run python docs/_code/controlled_blinker.py
96+
ls -la blinker_system.v && head -n 10 blinker_system.v
97+
ls -la blinker_system.vcd
98+
99+
- name: Verify waveform files with GTKWave
100+
run: |
101+
gtkwave -V
102+
for vcd_file in *.vcd; do
103+
if [ -f "$vcd_file" ]; then
104+
echo "Verifying $vcd_file with GTKWave..."
105+
gtkwave -V "$vcd_file" || true
106+
fi
107+
done
108+
109+
- name: Generate test summary
110+
run: |
111+
echo "## Tutorial Code Test Results" > summary.md
112+
echo "| Example | Status |" >> summary.md
113+
echo "|---------|--------|" >> summary.md
114+
115+
check_file() {
116+
if [ -f "$1" ]; then
117+
echo "| $2 | ✅ Pass |" >> summary.md
118+
else
119+
echo "| $2 | ❌ Fail |" >> summary.md
120+
EXIT_CODE=1
121+
fi
122+
}
123+
124+
EXIT_CODE=0
125+
check_file "and_gate.v" "AND Gate"
126+
check_file "blinky.vcd" "LED Blinker"
127+
check_file "counter.v" "Up Counter"
128+
check_file "uart_rx.v" "UART Receiver"
129+
check_file "uart_sim.vcd" "UART Simulation"
130+
check_file "blinker_system.v" "Controlled Blinker"
131+
check_file "blinker_system.vcd" "Blinker Simulation"
132+
133+
cat summary.md
134+
exit $EXIT_CODE
135+
136+
- name: Archive generated files
137+
uses: actions/upload-artifact@v3
138+
with:
139+
name: tutorial-outputs
140+
path: |
141+
*.v
142+
*.vcd
143+
summary.md

0 commit comments

Comments
 (0)