Skip to content

Commit 8cc20a8

Browse files
robtaylorclaude
andcommitted
Integrate tutorial testing with Sphinx documentation
- Modified workflows to use docs/tutorial.rst instead of tutorial.md - Added support for parsing RST format code blocks and includes - Enhanced execution test to use actual code files from docs/_code/ - Removed standalone tutorial.md in favor of Sphinx integration - Updated path triggers to focus on docs directory files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent f35550f commit 8cc20a8

File tree

4 files changed

+44
-839
lines changed

4 files changed

+44
-839
lines changed

.github/workflows/tutorial-comprehension-test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ on:
44
push:
55
branches: [ main ]
66
paths:
7-
- 'tutorial.md'
7+
- 'docs/tutorial.rst'
88
- '.github/workflows/tutorial-comprehension-test.yml'
99
pull_request:
1010
branches: [ main ]
1111
paths:
12-
- 'tutorial.md'
12+
- 'docs/tutorial.rst'
1313
- '.github/workflows/tutorial-comprehension-test.yml'
1414
workflow_dispatch: # Allow manual trigger
1515

@@ -43,7 +43,7 @@ jobs:
4343
4444
async function analyzeTutorial() {
4545
// Read the tutorial content
46-
const tutorialContent = fs.readFileSync('tutorial.md', 'utf8');
46+
const tutorialContent = fs.readFileSync('docs/tutorial.rst', 'utf8');
4747
4848
// Create the prompt for Claude
4949
const prompt = `<tutorial>

.github/workflows/tutorial-execution-test.yml

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ on:
44
push:
55
branches: [ main ]
66
paths:
7-
- 'tutorial.md'
7+
- 'docs/tutorial.rst'
8+
- 'docs/_code/**'
89
- '.github/workflows/tutorial-execution-test.yml'
910
pull_request:
1011
branches: [ main ]
1112
paths:
12-
- 'tutorial.md'
13+
- 'docs/tutorial.rst'
14+
- 'docs/_code/**'
1315
- '.github/workflows/tutorial-execution-test.yml'
1416
workflow_dispatch: # Allow manual trigger
1517

@@ -49,10 +51,20 @@ jobs:
4951
run: |
5052
cat > execute_tutorial.js << 'EOF'
5153
const fs = require('fs');
54+
const path = require('path');
5255
const { exec, execSync } = require('child_process');
5356
const Anthropic = require('@anthropic-ai/sdk');
5457
const util = require('util');
5558
const execAsync = util.promisify(exec);
59+
60+
// Helper function to get code from a file reference
61+
function getCodeFromFileRef(fileRef) {
62+
const filePath = path.join('docs', fileRef);
63+
if (fs.existsSync(filePath)) {
64+
return fs.readFileSync(filePath, 'utf8');
65+
}
66+
return null;
67+
}
5668
5769
// Initialize Anthropic client
5870
const anthropic = new Anthropic({
@@ -61,18 +73,22 @@ jobs:
6173
6274
async function executeTutorial() {
6375
// Read the tutorial content
64-
const tutorialContent = fs.readFileSync('tutorial.md', 'utf8');
76+
const tutorialContent = fs.readFileSync('docs/tutorial.rst', 'utf8');
6577
6678
// First, have Claude analyze the tutorial and extract executable steps
6779
const analysisPrompt = `<tutorial>
6880
${tutorialContent}
6981
</tutorial>
7082
71-
You are an expert in hardware design, HDLs, and Python. Please analyze the above Amaranth HDL tutorial and extract a step-by-step execution plan.
83+
You are an expert in hardware design, HDLs, and Python. Please analyze the above Amaranth HDL tutorial (in RST format) and extract a step-by-step execution plan.
7284
73-
For each code example in the tutorial:
74-
1. Identify the filename it should be saved as
75-
2. Extract the exact code as shown in the tutorial
85+
Note that this is a Sphinx RST file, with code examples in these forms:
86+
1. Inline code blocks (marked with .. code-block:: python)
87+
2. File includes (marked with .. literalinclude:: _code/filename.py)
88+
89+
For each executable code example in the tutorial:
90+
1. Identify the filename it should be saved as (from literalinclude or reasonable name for code blocks)
91+
2. Extract the exact code needed for execution
7692
3. Identify any dependencies or prerequisites needed to run this code
7793
4. Describe what the expected output or result should be
7894
@@ -125,9 +141,18 @@ jobs:
125141
const step = executionPlan.steps[i];
126142
console.log(`\n==== Executing Step ${i+1}: ${step.name} ====`);
127143
128-
// Save the code to a file
129-
fs.writeFileSync(step.file, step.code);
130-
console.log(`Created file: ${step.file}`);
144+
// Check if we have this file already in docs/_code
145+
const docFilePath = path.join('docs', '_code', step.file);
146+
if (fs.existsSync(docFilePath)) {
147+
// Use the existing file from docs/_code
148+
const codeFromFile = fs.readFileSync(docFilePath, 'utf8');
149+
fs.writeFileSync(step.file, codeFromFile);
150+
console.log(`Using existing file from docs/_code/${step.file}`);
151+
} else {
152+
// Save the code to a file as extracted by Claude
153+
fs.writeFileSync(step.file, step.code);
154+
console.log(`Created file from extraction: ${step.file}`);
155+
}
131156
132157
// Execute the code
133158
try {

.github/workflows/tutorial-test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ on:
44
push:
55
branches: [ main ]
66
paths:
7-
- 'tutorial.md'
7+
- 'docs/tutorial.rst'
88
- 'docs/_code/**'
99
- '.github/workflows/tutorial-test.yml'
1010
pull_request:
1111
branches: [ main ]
1212
paths:
13-
- 'tutorial.md'
13+
- 'docs/tutorial.rst'
1414
- 'docs/_code/**'
1515
- '.github/workflows/tutorial-test.yml'
1616
workflow_dispatch: # Allow manual trigger
@@ -25,16 +25,16 @@ jobs:
2525

2626
- name: Check tutorial refers to existing files
2727
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)
28+
# Extract code filename references from tutorial.rst
29+
TUTORIAL_FILES=$(grep -o "_code/[a-zA-Z_]*\.py" docs/tutorial.rst | cut -d'/' -f2 | sort | uniq)
3030
31-
echo "Files mentioned in tutorial.md:"
31+
echo "Files mentioned in tutorial.rst:"
3232
echo "$TUTORIAL_FILES"
3333
3434
# Check if each mentioned file exists in docs/_code/
3535
for file in $TUTORIAL_FILES; do
3636
if [ ! -f "docs/_code/$file" ]; then
37-
echo "Error: $file mentioned in tutorial.md but missing from docs/_code/"
37+
echo "Error: $file mentioned in tutorial.rst but missing from docs/_code/"
3838
exit 1
3939
else
4040
echo "✓ Found docs/_code/$file"

0 commit comments

Comments
 (0)