diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 6d69d4d3..1a9d1a6c 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -15,12 +15,18 @@ This workflow automatically synchronizes documentation from the `genlayerlabs/ge 2. Gets the latest tag from the repository to use in the branch name 3. Copies new or updated files: - Changelog files → `content/validators/changelog/` + - Config file → `content/validators/config.yaml` (sanitized - see note below) - API gen method docs → `pages/api-references/genlayer-node/gen/` - API debug method docs → `pages/api-references/genlayer-node/debug/` - **Note**: Both `.md` and `.mdx` files are supported. `.md` files are automatically renamed to `.mdx` when copied + - **Config Sanitization**: The config file is sanitized during sync: + - ZKSync URLs are replaced with TODO placeholders + - `node.dev` and `node.admin` sections are removed + - **Regex Filtering**: API files can be filtered using regex patterns (see Customizing section below) 4. Runs documentation generation scripts: - `generate-changelog.js` - `update-setup-guide-versions.js` + - `update-config-in-setup-guide.js` - `generate-api-docs.js` 5. Creates a PR with all changes, using the tag in the branch name (e.g., `sync-node-docs-v0.3.5`) @@ -39,8 +45,10 @@ Add this to a workflow in the genlayer-node repository: { "source_branch": "${{ github.ref_name }}", "changelog_path": "docs/changelog", - "api_gen_path": "docs/api/gen", - "api_debug_path": "docs/api/debug" + "api_gen_path": "docs/api/rpc/gen", + "api_debug_path": "docs/api/rpc/debug", + "api_gen_regex": "gen_(?!dbg_).*", + "api_debug_regex": "gen_dbg_.*" } ``` @@ -70,8 +78,13 @@ Add this to a workflow in the genlayer-node repository: From the Actions tab: 1. Select "Sync Documentation from Node Repository" 2. Click "Run workflow" -3. Optionally specify: - - Source branch (default: main) +3. Specify parameters: + - Tag for branch naming (required, e.g., v0.3.5) + - Source branch (optional, default: main) + - API gen path (optional, default: `docs/api/rpc/gen`) + - API debug path (optional, default: `docs/api/rpc/debug`) + - API gen regex filter (optional, default: `gen_(?!dbg_).*`) + - API debug regex filter (optional, default: `gen_dbg_.*`) ### File Structure Expected in genlayer-node @@ -90,11 +103,24 @@ docs/ │ ├── gen_dbg_ping.md # Will be copied as gen_dbg_ping.mdx │ ├── gen_dbg_trie.mdx # Will be copied as-is │ └── ... +configs/ +└── node/ + └── config.yaml.example # Will be copied to content/validators/config.yaml ``` -### Customizing Paths +### Customizing Paths and Filtering -The source paths can be customized in the event payload: +The source paths and filters can be customized in the event payload: + +#### Paths - `changelog_path`: Path to changelog files (default: `docs/changelog`) - `api_gen_path`: Path to API gen methods (default: `docs/api/rpc/gen`) -- `api_debug_path`: Path to API debug methods (default: `docs/api/rpc/debug`) \ No newline at end of file +- `api_debug_path`: Path to API debug methods (default: `docs/api/rpc/debug`) + +#### Regex Filters +- `api_gen_regex`: Regex pattern to filter gen API files (default: `gen_(?!dbg_).*`) + - This default pattern matches files starting with `gen_` but excludes those starting with `gen_dbg_` +- `api_debug_regex`: Regex pattern to filter debug API files (default: `gen_dbg_.*`) + - This default pattern matches only files starting with `gen_dbg_` + +The regex patterns are applied to the filename (without extension) to determine which files should be synced. \ No newline at end of file diff --git a/.github/workflows/example-trigger-from-node.yml.example b/.github/workflows/example-trigger-from-node.yml.example index adaf2d78..c9086dca 100644 --- a/.github/workflows/example-trigger-from-node.yml.example +++ b/.github/workflows/example-trigger-from-node.yml.example @@ -46,8 +46,10 @@ jobs: "source_branch": "${{ github.ref_name }}", "tag": "${{ steps.get_tag.outputs.tag }}", "changelog_path": "docs/changelog", - "api_gen_path": "docs/api/gen", - "api_debug_path": "docs/api/debug" + "api_gen_path": "docs/api/rpc/gen", + "api_debug_path": "docs/api/rpc/debug", + "api_gen_regex": "gen_(?!dbg_).*", + "api_debug_regex": "gen_dbg_.*" } - name: Summary diff --git a/.github/workflows/sync-docs-from-node.yml b/.github/workflows/sync-docs-from-node.yml index 21c767b4..2bdc2da3 100644 --- a/.github/workflows/sync-docs-from-node.yml +++ b/.github/workflows/sync-docs-from-node.yml @@ -12,6 +12,22 @@ on: tag: description: 'Tag/version for branch naming (e.g., v0.3.5)' required: true + api_gen_path: + description: 'Path to API gen files in source repo' + required: false + default: 'docs/api/rpc/gen' + api_debug_path: + description: 'Path to API debug files in source repo' + required: false + default: 'docs/api/rpc/debug' + api_gen_regex: + description: 'Regex pattern to filter API gen files (e.g., "gen_.*")' + required: false + default: 'gen_(?!dbg_).*' + api_debug_regex: + description: 'Regex pattern to filter API debug files (e.g., "gen_dbg_.*")' + required: false + default: 'gen_dbg_.*' jobs: sync-and-create-pr: @@ -52,12 +68,16 @@ jobs: echo "changelog_path=${{ github.event.client_payload.changelog_path || 'docs/changelog' }}" >> $GITHUB_OUTPUT echo "api_gen_path=${{ github.event.client_payload.api_gen_path || 'docs/api/rpc/gen' }}" >> $GITHUB_OUTPUT echo "api_debug_path=${{ github.event.client_payload.api_debug_path || 'docs/api/rpc/debug' }}" >> $GITHUB_OUTPUT + echo "api_gen_regex=${{ github.event.client_payload.api_gen_regex || 'gen_(?!dbg_).*' }}" >> $GITHUB_OUTPUT + echo "api_debug_regex=${{ github.event.client_payload.api_debug_regex || 'gen_dbg_.*' }}" >> $GITHUB_OUTPUT else echo "source_branch=${{ github.event.inputs.source_branch }}" >> $GITHUB_OUTPUT echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT echo "changelog_path=docs/changelog" >> $GITHUB_OUTPUT - echo "api_gen_path=docs/api/gen" >> $GITHUB_OUTPUT - echo "api_debug_path=docs/api/debug" >> $GITHUB_OUTPUT + echo "api_gen_path=${{ github.event.inputs.api_gen_path || 'docs/api/rpc/gen' }}" >> $GITHUB_OUTPUT + echo "api_debug_path=${{ github.event.inputs.api_debug_path || 'docs/api/rpc/debug' }}" >> $GITHUB_OUTPUT + echo "api_gen_regex=${{ github.event.inputs.api_gen_regex || 'gen_(?!dbg_).*' }}" >> $GITHUB_OUTPUT + echo "api_debug_regex=${{ github.event.inputs.api_debug_regex || 'gen_dbg_.*' }}" >> $GITHUB_OUTPUT fi - name: Clone genlayer-node repository (docs folder only) @@ -159,6 +179,78 @@ jobs: echo "changelog_total=0" >> $GITHUB_OUTPUT fi + - name: Sync config.yaml file + id: sync_config + run: | + set -euo pipefail + SYNC_REPORT="${{ runner.temp }}/sync_report.md" + SOURCE_CONFIG="source-repo/configs/node/config.yaml.example" + DEST_CONFIG="content/validators/config.yaml" + + echo "" >> $SYNC_REPORT + echo "## Config File Sync" >> $SYNC_REPORT + echo "" >> $SYNC_REPORT + + if [ -f "$SOURCE_CONFIG" ]; then + mkdir -p "$(dirname "$DEST_CONFIG")" + + # Create a temporary file for sanitized config + TEMP_CONFIG="${{ runner.temp }}/config_sanitized.yaml" + + # Copy and sanitize the config + cp "$SOURCE_CONFIG" "$TEMP_CONFIG" + + # Replace actual URLs with TODO placeholders + sed -i 's|zksyncurl: *"[^"]*"|zksyncurl: "TODO: Set your GenLayer Chain ZKSync HTTP RPC URL here"|' "$TEMP_CONFIG" + sed -i 's|zksyncwebsocketurl: *"[^"]*"|zksyncwebsocketurl: "TODO: Set your GenLayer Chain ZKSync WebSocket RPC URL here"|' "$TEMP_CONFIG" + + # Remove node.dev and node.admin sections using Python for reliable YAML parsing + python3 -c " +import yaml +import sys + +config_file = sys.argv[1] + +# Read the YAML file +with open(config_file, 'r') as f: + config = yaml.safe_load(f) + +# Remove node.dev and node.admin if they exist +if 'node' in config: + if 'dev' in config['node']: + del config['node']['dev'] + if 'admin' in config['node']: + del config['node']['admin'] + +# Write back to file preserving the structure +with open(config_file, 'w') as f: + yaml.dump(config, f, default_flow_style=False, sort_keys=False, allow_unicode=True) +" "$TEMP_CONFIG" + + # Check if the config has changed + if [ -f "$DEST_CONFIG" ]; then + if ! cmp -s "$TEMP_CONFIG" "$DEST_CONFIG"; then + cp "$TEMP_CONFIG" "$DEST_CONFIG" + echo "- Updated: \`config.yaml\` (sanitized)" >> $SYNC_REPORT + echo "config_updated=1" >> $GITHUB_OUTPUT + else + echo "- No changes to \`config.yaml\`" >> $SYNC_REPORT + echo "config_updated=0" >> $GITHUB_OUTPUT + fi + else + # Config doesn't exist, create it + cp "$TEMP_CONFIG" "$DEST_CONFIG" + echo "- Added: \`config.yaml\` (sanitized)" >> $SYNC_REPORT + echo "config_updated=1" >> $GITHUB_OUTPUT + fi + + # Clean up temp file + rm -f "$TEMP_CONFIG" + else + echo "- Source config file not found: \`configs/node/config.yaml.example\`" >> $SYNC_REPORT + echo "config_updated=0" >> $GITHUB_OUTPUT + fi + - name: Sync API gen method files id: sync_api_gen run: | @@ -166,9 +258,11 @@ jobs: SYNC_REPORT="${{ runner.temp }}/sync_report.md" SOURCE_API_GEN="source-repo/${{ steps.params.outputs.api_gen_path }}" DEST_API_GEN="pages/api-references/genlayer-node/gen" + API_GEN_REGEX="${{ steps.params.outputs.api_gen_regex }}" echo "" >> $SYNC_REPORT echo "## API Gen Methods Sync" >> $SYNC_REPORT + echo "Using regex filter: \`$API_GEN_REGEX\`" >> $SYNC_REPORT echo "" >> $SYNC_REPORT if [ -d "$SOURCE_API_GEN" ]; then @@ -184,27 +278,31 @@ jobs: ADDED=0 UPDATED=0 - # Process all source files + # Process all source files that match the regex for file in "$SOURCE_API_GEN"/*.mdx "$SOURCE_API_GEN"/*.md; do if [ -f "$file" ]; then basename_no_ext=$(basename "$file" | sed 's/\.[^.]*$//') - dest_filename="${basename_no_ext}.mdx" - dest_path="$DEST_API_GEN/$dest_filename" - - if [ -f "$dest_path" ]; then - # File exists - check if it's different - if ! cmp -s "$file" "$dest_path"; then + + # Check if filename (without extension) matches the regex filter + if echo "$basename_no_ext" | grep -E "^($API_GEN_REGEX)$" > /dev/null 2>&1; then + dest_filename="${basename_no_ext}.mdx" + dest_path="$DEST_API_GEN/$dest_filename" + + if [ -f "$dest_path" ]; then + # File exists - check if it's different + if ! cmp -s "$file" "$dest_path"; then + cp "$file" "$dest_path" + echo "- Updated: \`$dest_filename\`" >> $SYNC_REPORT + UPDATED=$((UPDATED + 1)) + fi + # Remove from tracking to identify deletions later + unset EXISTING_FILES["$dest_filename"] + else + # New file cp "$file" "$dest_path" - echo "- Updated: \`$dest_filename\`" >> $SYNC_REPORT - UPDATED=$((UPDATED + 1)) + echo "- Added: \`$dest_filename\`" >> $SYNC_REPORT + ADDED=$((ADDED + 1)) fi - # Remove from tracking to identify deletions later - unset EXISTING_FILES["$dest_filename"] - else - # New file - cp "$file" "$dest_path" - echo "- Added: \`$dest_filename\`" >> $SYNC_REPORT - ADDED=$((ADDED + 1)) fi fi done @@ -226,13 +324,25 @@ jobs: echo "- Deleted: \`_meta.json\`" >> $SYNC_REPORT fi - # Remove files that no longer exist in source + # Remove files that no longer exist in source or don't match the filter DELETED=${DELETED:-0} for dest_file in "${EXISTING_FILES[@]}"; do if [ -f "$dest_file" ]; then - rm "$dest_file" - echo "- Deleted: \`$(basename "$dest_file")\`" >> $SYNC_REPORT - DELETED=$((DELETED + 1)) + dest_basename_no_ext=$(basename "$dest_file" | sed 's/\.[^.]*$//') + # Check if the file should still exist based on source and filter + source_exists=false + if [ -f "$SOURCE_API_GEN/${dest_basename_no_ext}.mdx" ] || [ -f "$SOURCE_API_GEN/${dest_basename_no_ext}.md" ]; then + # Source exists, check if it matches the filter + if echo "$dest_basename_no_ext" | grep -E "^($API_GEN_REGEX)$" > /dev/null 2>&1; then + source_exists=true + fi + fi + + if [ "$source_exists" = false ]; then + rm "$dest_file" + echo "- Deleted: \`$(basename "$dest_file")\`" >> $SYNC_REPORT + DELETED=$((DELETED + 1)) + fi fi done @@ -265,9 +375,11 @@ jobs: SYNC_REPORT="${{ runner.temp }}/sync_report.md" SOURCE_API_DEBUG="source-repo/${{ steps.params.outputs.api_debug_path }}" DEST_API_DEBUG="pages/api-references/genlayer-node/debug" + API_DEBUG_REGEX="${{ steps.params.outputs.api_debug_regex }}" echo "" >> $SYNC_REPORT echo "## API Debug Methods Sync" >> $SYNC_REPORT + echo "Using regex filter: \`$API_DEBUG_REGEX\`" >> $SYNC_REPORT echo "" >> $SYNC_REPORT if [ -d "$SOURCE_API_DEBUG" ]; then @@ -283,27 +395,31 @@ jobs: ADDED=0 UPDATED=0 - # Process all source files + # Process all source files that match the regex for file in "$SOURCE_API_DEBUG"/*.mdx "$SOURCE_API_DEBUG"/*.md; do if [ -f "$file" ]; then basename_no_ext=$(basename "$file" | sed 's/\.[^.]*$//') - dest_filename="${basename_no_ext}.mdx" - dest_path="$DEST_API_DEBUG/$dest_filename" - - if [ -f "$dest_path" ]; then - # File exists - check if it's different - if ! cmp -s "$file" "$dest_path"; then + + # Check if filename (without extension) matches the regex filter + if echo "$basename_no_ext" | grep -E "^($API_DEBUG_REGEX)$" > /dev/null 2>&1; then + dest_filename="${basename_no_ext}.mdx" + dest_path="$DEST_API_DEBUG/$dest_filename" + + if [ -f "$dest_path" ]; then + # File exists - check if it's different + if ! cmp -s "$file" "$dest_path"; then + cp "$file" "$dest_path" + echo "- Updated: \`$dest_filename\`" >> $SYNC_REPORT + UPDATED=$((UPDATED + 1)) + fi + # Remove from tracking to identify deletions later + unset EXISTING_FILES["$dest_filename"] + else + # New file cp "$file" "$dest_path" - echo "- Updated: \`$dest_filename\`" >> $SYNC_REPORT - UPDATED=$((UPDATED + 1)) + echo "- Added: \`$dest_filename\`" >> $SYNC_REPORT + ADDED=$((ADDED + 1)) fi - # Remove from tracking to identify deletions later - unset EXISTING_FILES["$dest_filename"] - else - # New file - cp "$file" "$dest_path" - echo "- Added: \`$dest_filename\`" >> $SYNC_REPORT - ADDED=$((ADDED + 1)) fi fi done @@ -325,13 +441,25 @@ jobs: echo "- Deleted: \`_meta.json\`" >> $SYNC_REPORT fi - # Remove files that no longer exist in source + # Remove files that no longer exist in source or don't match the filter DELETED=${DELETED:-0} for dest_file in "${EXISTING_FILES[@]}"; do if [ -f "$dest_file" ]; then - rm "$dest_file" - echo "- Deleted: \`$(basename "$dest_file")\`" >> $SYNC_REPORT - DELETED=$((DELETED + 1)) + dest_basename_no_ext=$(basename "$dest_file" | sed 's/\.[^.]*$//') + # Check if the file should still exist based on source and filter + source_exists=false + if [ -f "$SOURCE_API_DEBUG/${dest_basename_no_ext}.mdx" ] || [ -f "$SOURCE_API_DEBUG/${dest_basename_no_ext}.md" ]; then + # Source exists, check if it matches the filter + if echo "$dest_basename_no_ext" | grep -E "^($API_DEBUG_REGEX)$" > /dev/null 2>&1; then + source_exists=true + fi + fi + + if [ "$source_exists" = false ]; then + rm "$dest_file" + echo "- Deleted: \`$(basename "$dest_file")\`" >> $SYNC_REPORT + DELETED=$((DELETED + 1)) + fi fi done @@ -371,6 +499,9 @@ jobs: npm run node-update-setup-guide echo "- ✅ Updated setup guide versions" >> $SYNC_REPORT + npm run node-update-config + echo "- ✅ Updated config in setup guide" >> $SYNC_REPORT + npm run node-generate-api-docs echo "- ✅ Generated API documentation" >> $SYNC_REPORT @@ -386,6 +517,7 @@ jobs: ${{ steps.sync_api_gen.outputs.api_gen_added || 0 }} + \ ${{ steps.sync_api_debug.outputs.api_debug_added || 0 }} )) TOTAL_UPDATED=$(( ${{ steps.sync_changelog.outputs.changelog_updated || 0 }} + \ + ${{ steps.sync_config.outputs.config_updated || 0 }} + \ ${{ steps.sync_api_gen.outputs.api_gen_updated || 0 }} + \ ${{ steps.sync_api_debug.outputs.api_debug_updated || 0 }} )) TOTAL_DELETED=$(( ${{ steps.sync_changelog.outputs.changelog_deleted || 0 }} + \ @@ -409,7 +541,7 @@ jobs: if: steps.check_changes.outputs.has_changes == 'true' run: | set -euo pipefail - git add content/validators/changelog pages/api-references pages/validators + git add content/validators pages/api-references pages/validators git commit -m "docs: Sync documentation from node repository ${{ steps.params.outputs.tag }} - Source: genlayerlabs/genlayer-node@${{ steps.params.outputs.source_branch }} @@ -465,6 +597,8 @@ jobs: - **Source Repository**: `genlayerlabs/genlayer-node` - **Source Branch**: `${{ steps.params.outputs.source_branch }}` - **Latest Tag**: `${{ steps.params.outputs.tag }}` + - **API Gen Filter**: `${{ steps.params.outputs.api_gen_regex }}` + - **API Debug Filter**: `${{ steps.params.outputs.api_debug_regex }}` - **Total Files Changed**: ${{ steps.check_changes.outputs.total_changes }} - Added: ${{ steps.check_changes.outputs.total_added }} files - Updated: ${{ steps.check_changes.outputs.total_updated }} files diff --git a/content/validators/config.yaml b/content/validators/config.yaml new file mode 100644 index 00000000..78ed8e2d --- /dev/null +++ b/content/validators/config.yaml @@ -0,0 +1,64 @@ +rollup: + zksyncurl: "TODO: Set your GenLayer Chain ZKSync HTTP RPC URL here" # ZKSync RPC URL + zksyncwebsocketurl: "TODO: Set your GenLayer Chain ZKSync WebSocket RPC URL here" # ZKSync WebSocket URL +consensus: + contractmanageraddress: "0x0761ff3847294eb3234f37Bf63fd7F1CA1E840bB" # ConsensusManager Smart Contract Address + contractmainaddress: "0xe30293d600fF9B2C865d91307826F28006A458f4" # ConsensusMain Smart Contract Address + contractdataaddress: "0x2a50afD9d3E0ACC824aC4850d7B4c5561aB5D27a" # ConsensusData Smart Contract Address + contractidlenessaddress: "0xD1D09c2743DD26d718367Ba249Ee1629BE88CF33" # Idleness Smart Contract Address + genesis: 817855 # (Optional) Genesis block number for this consensus deployment. If not provided, it will be auto-detected by searching for the first log from the ConsensusMain contract. +datadir: "./data/node" # Cache directory +logging: + level: "INFO" + # json: `true` for json output to console, false for human readable log formatting + json: false + # Configuration for https://github.com/natefinch/lumberjack + file: + # enabled: set to `true` to save logs to a folder + enabled: true + level: "DEBUG" + # folder: path to the folder where to store logs. Relative paths go under `datadir`. + folder: logs + # maxsize: maximum size in megabytes of the log file before it gets rotated. It defaults to 100 megabytes. + maxsize: 500 + # maxage: maximum number of days to retain old log files based on the timestamp encoded in their filename. + maxage: 7 + # maxbackups: maximum number of old log files to retain. Set to 0 for no limit + maxbackups: 10 + # localtime: determines if the time used for formatting the timestamps in backup files is the computer's local time. Set to `false` to use UTC time. + localtime: false + # compress: determines if the rotated log files should be compressed using gzip + compress: true +node: + mode: "validator" # "validator" or "archive" + rpc: + port: 9151 # JSON RPC port + endpoints: + groups: + ethereum: true # Enable Ethereum RPC endpoints + debug: false # Enable debug endpoints + methods: # Enabled `eth_` methods + eth_blockNumber: true + eth_getBlockByNumber: true + eth_getBlockByHash: true + eth_sendRawTransaction: false + ops: + port: 9153 # Metrics port + endpoints: + metrics: true # Enable metrics endpoint + health: true # Enable health endpoint + dev: # Configuration for development purposes + disableSubscription: false # Disable subscription + +genvm: + bin_dir: ./third_party/genvm/bin + manage_modules: true + +# Advanced configuration +merkleforest: + maxdepth: 16 + dbpath: "./data/node/merkle/forest/data.db" + indexdbpath: "./data/node/merkle/index.db" +merkletree: + maxdepth: 16 + dbpath: "./data/node/merkle/tree/" \ No newline at end of file diff --git a/package.json b/package.json index 52dd20ce..75b3c576 100644 --- a/package.json +++ b/package.json @@ -3,13 +3,14 @@ "version": "0.0.1", "description": "GenLayer documentation", "scripts": { - "dev": "npm run node-generate-changelog && npm run node-update-setup-guide && npm run node-generate-api-docs && node scripts/generate-full-docs.js && next dev", - "build": "npm run node-generate-changelog && npm run node-update-setup-guide && npm run node-generate-api-docs && node scripts/generate-full-docs.js && next build", + "dev": "npm run node-generate-changelog && npm run node-update-setup-guide && npm run node-update-config && npm run node-generate-api-docs && node scripts/generate-full-docs.js && next dev", + "build": "npm run node-generate-changelog && npm run node-update-setup-guide && npm run node-update-config && npm run node-generate-api-docs && node scripts/generate-full-docs.js && next build", "start": "next start", "generate-sitemap": "node scripts/generate-sitemap-xml.js", "node-generate-changelog": "node scripts/generate-changelog.js", "node-generate-api-docs": "node scripts/generate-api-docs.js", - "node-update-setup-guide": "node scripts/update-setup-guide-versions.js" + "node-update-setup-guide": "node scripts/update-setup-guide-versions.js", + "node-update-config": "node scripts/update-config-in-setup-guide.js" }, "repository": { "type": "git", diff --git a/scripts/update-config-in-setup-guide.js b/scripts/update-config-in-setup-guide.js new file mode 100755 index 00000000..cab78c8a --- /dev/null +++ b/scripts/update-config-in-setup-guide.js @@ -0,0 +1,73 @@ +#!/usr/bin/env node + +const fs = require('fs'); +const path = require('path'); + +/** + * Update the setup guide with the latest config from content/validators/config.yaml + */ +function updateConfigInSetupGuide() { + const configPath = path.join(process.cwd(), 'content/validators/config.yaml'); + const setupGuidePath = path.join(process.cwd(), 'pages/validators/setup-guide.mdx'); + + if (!fs.existsSync(configPath)) { + console.error(`Config file ${configPath} does not exist`); + return; + } + + if (!fs.existsSync(setupGuidePath)) { + console.error(`Setup guide file ${setupGuidePath} does not exist`); + return; + } + + // Read the config.yaml content + const configContent = fs.readFileSync(configPath, 'utf8'); + + // Read the setup guide + let setupGuideContent = fs.readFileSync(setupGuidePath, 'utf8'); + + // Pattern to match the YAML config block + // Looks for the text before the yaml block, the yaml block itself, and the text after + const configPattern = /(You can use the following example configuration[^`]*```yaml\n)([\s\S]*?)(\n```)/; + + if (configPattern.test(setupGuideContent)) { + // Replace the config content while preserving the surrounding text + setupGuideContent = setupGuideContent.replace( + configPattern, + `$1${configContent}$3` + ); + + // Write the updated content back + fs.writeFileSync(setupGuidePath, setupGuideContent); + console.log(`Updated setup guide config at ${new Date().toISOString()}`); + } else { + console.error('Could not find config pattern in setup guide'); + + // Try a more general pattern as fallback + const fallbackPattern = /(```yaml\n)([\s\S]*?)(\n```)/; + const matches = setupGuideContent.match(fallbackPattern); + + if (matches) { + // Check if this looks like the config block by looking for consensus addresses + if (matches[2].includes('contractmanageraddress') || matches[2].includes('consensus:')) { + setupGuideContent = setupGuideContent.replace( + fallbackPattern, + `$1${configContent}$3` + ); + fs.writeFileSync(setupGuidePath, setupGuideContent); + console.log(`Updated setup guide config using fallback pattern at ${new Date().toISOString()}`); + } else { + console.error('Found YAML block but it does not appear to be the config block'); + } + } else { + console.error('Could not find any YAML block in setup guide'); + } + } +} + +// Run the script +if (require.main === module) { + updateConfigInSetupGuide(); +} + +module.exports = { updateConfigInSetupGuide }; \ No newline at end of file