Skip to content

Commit fb48029

Browse files
committed
chore(workflows): Improve debug output and error handling in config sanitization process
1 parent fe559f1 commit fb48029

2 files changed

Lines changed: 148 additions & 25 deletions

File tree

.github/scripts/sanitize-config.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,39 @@
77
"""
88

99
import sys
10-
import yaml
10+
import re
1111

1212

1313
def sanitize_config(config_file_path):
14-
"""Remove node.dev and node.admin sections from config file."""
14+
"""Remove node.dev and node.admin sections from config file using regex."""
15+
print(f"Sanitizing config file: {config_file_path}")
16+
1517
# Read the YAML file
1618
with open(config_file_path, 'r') as f:
17-
config = yaml.safe_load(f)
19+
content = f.read()
20+
21+
print(f"Original file size: {len(content)} bytes")
1822

19-
# Remove node.dev and node.admin if they exist
20-
if 'node' in config:
21-
if 'dev' in config['node']:
22-
del config['node']['dev']
23-
if 'admin' in config['node']:
24-
del config['node']['admin']
23+
# Remove node.admin section
24+
# This regex matches the admin: line and all indented content that follows
25+
admin_pattern = r'(\n\s+admin:\s*\n(?:\s+(?:port:\s*\d+|\S.*)\s*\n)*)'
26+
if re.search(admin_pattern, content):
27+
content = re.sub(admin_pattern, '\n', content)
28+
print("Removed node.admin section")
2529

26-
# Write back to file preserving the structure
30+
# Remove node.dev section
31+
# This regex matches the dev: line and all indented content that follows
32+
dev_pattern = r'(\n\s+dev:\s*\n(?:\s+\S.*\s*\n)*)'
33+
if re.search(dev_pattern, content):
34+
content = re.sub(dev_pattern, '\n', content)
35+
print("Removed node.dev section")
36+
37+
# Write back to file
2738
with open(config_file_path, 'w') as f:
28-
yaml.dump(config, f, default_flow_style=False, sort_keys=False, allow_unicode=True)
39+
f.write(content)
40+
41+
print(f"Sanitized file size: {len(content)} bytes")
42+
print("Config sanitization completed")
2943

3044

3145
def main():

.github/workflows/sync-docs-from-node.yml

Lines changed: 123 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ jobs:
9393
fetch-depth: 0 # Fetch all history for tags
9494
sparse-checkout: |
9595
docs
96-
configs
96+
configs/node/config.yaml.example
9797
sparse-checkout-cone-mode: true
9898
path: source-repo
9999

@@ -131,8 +131,14 @@ jobs:
131131
132132
# Debug: Check what files we have after checkout
133133
echo "::group::Debug: Files after version checkout"
134-
echo "Checking configs directory:"
135-
find configs -type f -name "*.yaml*" 2>/dev/null || echo "No configs directory or yaml files found"
134+
echo "Current directory: $(pwd)"
135+
echo "All directories in source-repo:"
136+
find . -type d -name "config*" | head -20
137+
echo "All yaml files:"
138+
find . -name "*.yaml*" -type f | head -20
139+
echo "Checking specific paths:"
140+
ls -la configs/ 2>/dev/null || echo "No configs directory"
141+
ls -la config/ 2>/dev/null || echo "No config directory"
136142
echo "::endgroup::"
137143
138144
- name: Create branch for changes
@@ -240,6 +246,7 @@ jobs:
240246
set -euo pipefail
241247
SYNC_REPORT="${{ runner.temp }}/sync_report.md"
242248
SOURCE_CONFIG="source-repo/configs/node/config.yaml.example"
249+
243250
DEST_CONFIG="content/validators/config.yaml"
244251
245252
echo "" >> $SYNC_REPORT
@@ -248,19 +255,22 @@ jobs:
248255
249256
# Debug: Check what files exist in source-repo/configs
250257
echo "::group::Debug: Checking source-repo/configs directory"
251-
echo "Looking for: $SOURCE_CONFIG"
252258
echo "Current directory: $(pwd)"
253259
echo "Source repo structure:"
254260
ls -la source-repo/ || echo "source-repo not found"
255261
echo "Configs directory:"
256262
ls -la source-repo/configs/ 2>/dev/null || echo "configs directory not found"
257263
echo "Node directory:"
258264
ls -la source-repo/configs/node/ 2>/dev/null || echo "node directory not found"
265+
echo "All files in configs (recursive):"
266+
find source-repo/configs -type f 2>/dev/null || echo "No files found in configs"
259267
echo "YAML files in configs:"
260268
find source-repo/configs -type f -name "*.yaml*" 2>/dev/null || echo "No yaml files found"
261269
echo "::endgroup::"
262-
270+
271+
# Check if the source config file exists
263272
if [ -f "$SOURCE_CONFIG" ]; then
273+
echo "Found config file at: $SOURCE_CONFIG"
264274
mkdir -p "$(dirname "$DEST_CONFIG")"
265275
266276
# Debug: Print original config
@@ -274,10 +284,27 @@ jobs:
274284
275285
# Copy and sanitize the config
276286
cp "$SOURCE_CONFIG" "$TEMP_CONFIG"
287+
if [ ! -f "$TEMP_CONFIG" ]; then
288+
echo "ERROR: Failed to copy config to temp location"
289+
exit 1
290+
fi
291+
292+
# Debug: Show config before sed replacements
293+
echo "::group::Config before sed replacements"
294+
grep -E "zksync.*url:" "$TEMP_CONFIG" || echo "No zksync URLs found"
295+
echo "::endgroup::"
277296
278297
# Replace actual URLs with TODO placeholders
279-
sed -i 's|zksyncurl: *"[^"]*"|zksyncurl: "TODO: Set your GenLayer Chain ZKSync HTTP RPC URL here"|' "$TEMP_CONFIG"
280-
sed -i 's|zksyncwebsocketurl: *"[^"]*"|zksyncwebsocketurl: "TODO: Set your GenLayer Chain ZKSync WebSocket RPC URL here"|' "$TEMP_CONFIG"
298+
# Use sed with backup for compatibility (works on both Linux and macOS)
299+
sed -i.bak 's|zksyncurl: *"[^"]*"|zksyncurl: "TODO: Set your GenLayer Chain ZKSync HTTP RPC URL here"|' "$TEMP_CONFIG"
300+
sed -i.bak 's|zksyncwebsocketurl: *"[^"]*"|zksyncwebsocketurl: "TODO: Set your GenLayer Chain ZKSync WebSocket RPC URL here"|' "$TEMP_CONFIG"
301+
# Remove backup files
302+
rm -f "${TEMP_CONFIG}.bak"
303+
304+
# Debug: Show config after sed replacements
305+
echo "::group::Config after sed replacements"
306+
grep -E "zksync.*url:" "$TEMP_CONFIG" || echo "No zksync URLs found after sed"
307+
echo "::endgroup::"
281308
282309
# Remove node.dev and node.admin sections using Python for reliable YAML parsing
283310
echo "::group::Debug: Running Python sanitization"
@@ -308,7 +335,44 @@ jobs:
308335
# Debug: Print sanitized config
309336
echo "::group::Sanitized config.yaml content"
310337
echo "After sanitization: $TEMP_CONFIG"
311-
cat "$TEMP_CONFIG" || echo "Failed to read sanitized config"
338+
if [ -f "$TEMP_CONFIG" ]; then
339+
echo "File size: $(wc -c < "$TEMP_CONFIG") bytes"
340+
echo "Complete sanitized config content:"
341+
echo "================================="
342+
cat "$TEMP_CONFIG"
343+
echo "================================="
344+
echo ""
345+
echo "Checking for removed sections:"
346+
grep -E "^\s*(dev|admin):" "$TEMP_CONFIG" && echo "WARNING: dev/admin sections still present!" || echo "Good: No dev/admin sections found"
347+
348+
# Verify the sanitized file has the expected structure
349+
echo "Verifying config structure:"
350+
if grep -q "^node:" "$TEMP_CONFIG"; then
351+
echo "✓ Found 'node:' section"
352+
else
353+
echo "✗ Missing 'node:' section"
354+
fi
355+
356+
if grep -q "^consensus:" "$TEMP_CONFIG"; then
357+
echo "✓ Found 'consensus:' section"
358+
else
359+
echo "✗ Missing 'consensus:' section"
360+
fi
361+
362+
if grep -q "^genvm:" "$TEMP_CONFIG"; then
363+
echo "✓ Found 'genvm:' section"
364+
else
365+
echo "✗ Missing 'genvm:' section"
366+
fi
367+
368+
if grep -q "^metrics:" "$TEMP_CONFIG"; then
369+
echo "✓ Found 'metrics:' section"
370+
else
371+
echo "✗ Missing 'metrics:' section"
372+
fi
373+
else
374+
echo "ERROR: Sanitized config file not found!"
375+
fi
312376
echo "::endgroup::"
313377
314378
# Debug: Check destination
@@ -326,18 +390,28 @@ jobs:
326390
# Check if the config has changed
327391
if [ -f "$DEST_CONFIG" ]; then
328392
if ! cmp -s "$TEMP_CONFIG" "$DEST_CONFIG"; then
329-
cp "$TEMP_CONFIG" "$DEST_CONFIG"
393+
# Force copy to ensure complete replacement
394+
cp -f "$TEMP_CONFIG" "$DEST_CONFIG"
330395
echo "- Updated: \`config.yaml\` (sanitized)" >> $SYNC_REPORT
331396
echo "config_updated=1" >> $GITHUB_OUTPUT
332397
echo "Config file was updated"
398+
399+
# Debug: Show what changed
400+
echo "::group::Config differences"
401+
echo "File sizes:"
402+
echo " Source (sanitized): $(wc -c < "$TEMP_CONFIG") bytes"
403+
echo " Destination (after copy): $(wc -c < "$DEST_CONFIG") bytes"
404+
echo "First 10 lines of updated config:"
405+
head -10 "$DEST_CONFIG"
406+
echo "::endgroup::"
333407
else
334408
echo "- No changes to \`config.yaml\`" >> $SYNC_REPORT
335409
echo "config_updated=0" >> $GITHUB_OUTPUT
336410
echo "Config file unchanged"
337411
fi
338412
else
339413
# Config doesn't exist, create it
340-
cp "$TEMP_CONFIG" "$DEST_CONFIG"
414+
cp -f "$TEMP_CONFIG" "$DEST_CONFIG"
341415
echo "- Added: \`config.yaml\` (sanitized)" >> $SYNC_REPORT
342416
echo "config_updated=1" >> $GITHUB_OUTPUT
343417
echo "Config file was created"
@@ -347,7 +421,15 @@ jobs:
347421
echo "::group::Debug: Verify config copy"
348422
if [ -f "$DEST_CONFIG" ]; then
349423
echo "Destination config after operation:"
350-
cat "$DEST_CONFIG" | head -20
424+
echo "File size: $(wc -c < "$DEST_CONFIG") bytes"
425+
echo "First 30 lines:"
426+
head -30 "$DEST_CONFIG"
427+
echo "---"
428+
echo "Checking final content:"
429+
echo "Has node section: $(grep -q '^node:' "$DEST_CONFIG" && echo "Yes" || echo "No")"
430+
echo "Has consensus section: $(grep -q '^consensus:' "$DEST_CONFIG" && echo "Yes" || echo "No")"
431+
echo "Has dev section: $(grep -q '^\s*dev:' "$DEST_CONFIG" && echo "Yes - ERROR!" || echo "No - Good")"
432+
echo "Has admin section: $(grep -q '^\s*admin:' "$DEST_CONFIG" && echo "Yes - ERROR!" || echo "No - Good")"
351433
else
352434
echo "ERROR: Destination config still doesn't exist!"
353435
fi
@@ -356,10 +438,19 @@ jobs:
356438
# Clean up temp file
357439
rm -f "$TEMP_CONFIG"
358440
else
359-
# Show path relative to source repo for clarity
360-
RELATIVE_PATH="${SOURCE_CONFIG#source-repo/}"
361-
printf -- "- Source config file not found: \`%s\`\n" "$RELATIVE_PATH" >> $SYNC_REPORT
441+
# Show what was searched
442+
echo "::group::Config file not found"
443+
echo "Expected config file at: $SOURCE_CONFIG"
444+
echo "::endgroup::"
445+
446+
printf -- "- Source config file not found at: \`%s\`\n" "${SOURCE_CONFIG#source-repo/}" >> $SYNC_REPORT
362447
echo "config_updated=0" >> $GITHUB_OUTPUT
448+
449+
# Try to create a minimal config if none exists
450+
echo "::group::Creating minimal config"
451+
echo "No config file found in source repository."
452+
echo "This might be expected for this version."
453+
echo "::endgroup::"
363454
fi
364455
365456
- name: Sync API gen method files
@@ -649,6 +740,24 @@ jobs:
649740
650741
npm run node-generate-api-docs
651742
echo "- ✅ Generated API documentation" >> $SYNC_REPORT
743+
744+
# Final config verification
745+
echo "::group::Final config.yaml verification"
746+
CONFIG_PATH="content/validators/config.yaml"
747+
if [ -f "$CONFIG_PATH" ]; then
748+
echo "Config file exists at: $CONFIG_PATH"
749+
echo "File size: $(wc -c < "$CONFIG_PATH") bytes"
750+
echo "First 30 lines:"
751+
head -30 "$CONFIG_PATH"
752+
echo "---"
753+
echo "Checking for sensitive sections:"
754+
grep -E "^\s*(dev|admin):" "$CONFIG_PATH" && echo "ERROR: Sensitive sections found!" || echo "✓ No sensitive sections"
755+
echo "Checking for TODO placeholders:"
756+
grep -i "TODO:" "$CONFIG_PATH" && echo "✓ TODO placeholders found" || echo "WARNING: No TODO placeholders"
757+
else
758+
echo "ERROR: Config file not found at $CONFIG_PATH"
759+
fi
760+
echo "::endgroup::"
652761
653762
- name: Check for changes
654763
id: check_changes

0 commit comments

Comments
 (0)