Skip to content

Sync Documentation from Node Repository #54

Sync Documentation from Node Repository

Sync Documentation from Node Repository #54

name: Sync Documentation from Node Repository
on:
repository_dispatch:
types: [sync-docs]
workflow_dispatch:
inputs:
version:
description: 'Version/tag to sync from genlayer-node repo (e.g., v0.3.5, or "latest" to detect)'
required: false
default: 'latest'
api_gen_path:
description: 'Path to API gen files in source repo'
required: false
default: 'docs/api/rpc'
api_debug_path:
description: 'Path to API debug files in source repo'
required: false
default: 'docs/api/rpc'
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_.*'
# Prevent concurrent runs of the same workflow
concurrency:
group: sync-docs-${{ github.ref }}-${{ github.event.inputs.version || github.event.client_payload.version || 'latest' }}
cancel-in-progress: true
jobs:
prepare:
name: 'Prepare Sync Parameters'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.detect_version.outputs.final_version }}
sync_config: ${{ steps.load_config.outputs.config }}
should_continue: ${{ steps.validate.outputs.should_continue }}
steps:
- name: Checkout documentation repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install pyyaml
- name: Load sync configuration
id: load_config
run: |
source .github/scripts/config-loader.sh
load_sync_config
- name: Extract and validate parameters
id: extract_params
run: |
source .github/scripts/version-utils.sh
# Determine parameters based on trigger type
if [[ "${{ github.event_name }}" == "repository_dispatch" ]]; then
VERSION="${{ github.event.client_payload.version }}"
CHANGELOG_PATH="${{ github.event.client_payload.changelog_path }}"
API_GEN_PATH="${{ github.event.client_payload.api_gen_path }}"
API_DEBUG_PATH="${{ github.event.client_payload.api_debug_path }}"
API_GEN_REGEX="${{ github.event.client_payload.api_gen_regex }}"
API_DEBUG_REGEX="${{ github.event.client_payload.api_debug_regex }}"
else
VERSION="${{ github.event.inputs.version }}"
CHANGELOG_PATH="docs/changelog"
API_GEN_PATH="${{ github.event.inputs.api_gen_path }}"
API_DEBUG_PATH="${{ github.event.inputs.api_debug_path }}"
API_GEN_REGEX="${{ github.event.inputs.api_gen_regex }}"
API_DEBUG_REGEX="${{ github.event.inputs.api_debug_regex }}"
fi
# Use defaults if values are empty
VERSION="${VERSION:-latest}"
CHANGELOG_PATH="${CHANGELOG_PATH:-docs/changelog}"
API_GEN_PATH="${API_GEN_PATH:-docs/api/rpc}"
API_DEBUG_PATH="${API_DEBUG_PATH:-docs/api/rpc}"
API_GEN_REGEX="${API_GEN_REGEX:-gen_(?!dbg_).*}"
API_DEBUG_REGEX="${API_DEBUG_REGEX:-gen_dbg_.*}"
extract_sync_parameters "${{ github.event_name }}" "$VERSION" "$CHANGELOG_PATH" "$API_GEN_PATH" "$API_DEBUG_PATH" "$API_GEN_REGEX" "$API_DEBUG_REGEX"
- name: Clone source repository for version detection
uses: actions/checkout@v4
with:
repository: genlayerlabs/genlayer-node
token: ${{ secrets.NODE_REPO_TOKEN || secrets.GITHUB_TOKEN }}
fetch-depth: 0
sparse-checkout: |
docs
configs/node/config.yaml.example
sparse-checkout-cone-mode: true
path: source-repo
- name: Detect final version
id: detect_version
run: |
source .github/scripts/version-utils.sh
detect_and_validate_version "${{ steps.extract_params.outputs.requested_version }}"
- name: Validate inputs and setup
id: validate
run: |
echo "should_continue=true" >> "$GITHUB_OUTPUT"
echo "✅ Preparation complete - ready to sync version: ${{ steps.detect_version.outputs.final_version }}"
sync-files:
name: 'Sync Documentation Files'
runs-on: ubuntu-latest
needs: prepare
if: needs.prepare.outputs.should_continue == 'true'
strategy:
matrix:
sync_type: [changelog, config, api_gen, api_debug]
fail-fast: false
steps:
- name: Checkout documentation repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js and dependencies
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: |
npm install
python3 -m pip install --upgrade pip pyyaml
- name: Setup Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Clone source repository
uses: actions/checkout@v4
with:
repository: genlayerlabs/genlayer-node
token: ${{ secrets.NODE_REPO_TOKEN || secrets.GITHUB_TOKEN }}
fetch-depth: 0
sparse-checkout: |
docs
configs/node/config.yaml.example
sparse-checkout-cone-mode: true
path: source-repo
ref: ${{ needs.prepare.outputs.version }}
- name: Sync files based on matrix type
id: sync
uses: ./.github/actions/sync-files
with:
sync_type: ${{ matrix.sync_type }}
version: ${{ needs.prepare.outputs.version }}
config: ${{ needs.prepare.outputs.sync_config }}
- name: Collect reports
id: collect_reports
run: |
# Store sync reports as artifacts for aggregation
REPORT_FILE="${{ runner.temp }}/sync_report_${{ matrix.sync_type }}.md"
if [[ -f "$REPORT_FILE" ]]; then
# Create artifacts directory
mkdir -p artifacts
cp "$REPORT_FILE" "artifacts/sync_report_${{ matrix.sync_type }}.md"
# Also output the changes count for this sync type
if [[ -f "${{ runner.temp }}/changes_${{ matrix.sync_type }}.txt" ]]; then
echo "changes_${{ matrix.sync_type }}=$(cat "${{ runner.temp }}/changes_${{ matrix.sync_type }}.txt")" >> "$GITHUB_OUTPUT"
else
echo "changes_${{ matrix.sync_type }}=0" >> "$GITHUB_OUTPUT"
fi
fi
- name: Upload sync reports
uses: actions/upload-artifact@v4
if: always()
with:
name: sync-reports-${{ matrix.sync_type }}
path: artifacts/
retention-days: 1
aggregate-results:
name: 'Aggregate Sync Results'
runs-on: ubuntu-latest
needs: [prepare, sync-files]
if: always() && needs.prepare.outputs.should_continue == 'true'
outputs:
total_changes: ${{ steps.calculate.outputs.total_changes }}
total_added: ${{ steps.calculate.outputs.total_added }}
total_updated: ${{ steps.calculate.outputs.total_updated }}
total_deleted: ${{ steps.calculate.outputs.total_deleted }}
sync_reports: ${{ steps.collect.outputs.all_reports }}
steps:
- name: Download all sync reports
uses: actions/download-artifact@v4
with:
pattern: sync-reports-*
merge-multiple: true
path: sync-reports/
- name: Calculate totals and collect reports
id: calculate
run: |
# Initialize counters
TOTAL_CHANGES=0
TOTAL_ADDED=0
TOTAL_UPDATED=0
TOTAL_DELETED=0
# Collect all reports
ALL_REPORTS=""
for report_file in sync-reports/sync_report_*.md; do
if [[ -f "$report_file" ]]; then
echo "📄 Processing: $(basename "$report_file")"
# Extract metrics from report if available
if grep -q "Changes:" "$report_file"; then
CHANGES=$(grep "Changes:" "$report_file" | grep -o '[0-9]\+' | head -1 || echo "0")
TOTAL_CHANGES=$((TOTAL_CHANGES + CHANGES))
fi
# Append report content
if [[ -n "$ALL_REPORTS" ]]; then
ALL_REPORTS="$ALL_REPORTS
---
"
fi
ALL_REPORTS="$ALL_REPORTS$(cat "$report_file")"
fi
done
# Output results
echo "total_changes=$TOTAL_CHANGES" >> "$GITHUB_OUTPUT"
echo "total_added=$TOTAL_ADDED" >> "$GITHUB_OUTPUT"
echo "total_updated=$TOTAL_UPDATED" >> "$GITHUB_OUTPUT"
echo "total_deleted=$TOTAL_DELETED" >> "$GITHUB_OUTPUT"
# Handle multiline output for reports
echo "all_reports<<EOF" >> "$GITHUB_OUTPUT"
echo "$ALL_REPORTS" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
echo "📊 Aggregated totals: $TOTAL_CHANGES changes"
- name: Store aggregated results
id: collect
run: |
echo "✅ Results aggregated successfully"
generate-docs:
name: 'Generate Documentation'
runs-on: ubuntu-latest
needs: [prepare, aggregate-results]
if: always() && needs.prepare.outputs.should_continue == 'true' && needs.aggregate-results.result != 'cancelled'
outputs:
generation_success: ${{ steps.generate.outputs.success }}
steps:
- name: Checkout documentation repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Run documentation generation scripts
id: generate
run: |
source .github/scripts/doc-generator.sh
if run_doc_generation_scripts '${{ needs.prepare.outputs.sync_config }}'; then
echo "success=true" >> "$GITHUB_OUTPUT"
verify_final_config
else
echo "success=false" >> "$GITHUB_OUTPUT"
echo "::error::Documentation generation failed"
exit 1
fi
create-pr:
name: 'Create Pull Request'
runs-on: ubuntu-latest
needs: [prepare, aggregate-results, generate-docs]
if: always() && needs.prepare.outputs.should_continue == 'true' && (needs.aggregate-results.result == 'success' || needs.generate-docs.result == 'success')
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout documentation repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Get aggregated results
id: get_results
run: |
# Use pre-calculated totals from aggregate-results job
TOTAL_CHANGES="${{ needs.aggregate-results.outputs.total_changes }}"
TOTAL_ADDED="${{ needs.aggregate-results.outputs.total_added }}"
TOTAL_UPDATED="${{ needs.aggregate-results.outputs.total_updated }}"
TOTAL_DELETED="${{ needs.aggregate-results.outputs.total_deleted }}"
echo "total_changes=$TOTAL_CHANGES" >> "$GITHUB_OUTPUT"
echo "total_added=$TOTAL_ADDED" >> "$GITHUB_OUTPUT"
echo "total_updated=$TOTAL_UPDATED" >> "$GITHUB_OUTPUT"
echo "total_deleted=$TOTAL_DELETED" >> "$GITHUB_OUTPUT"
echo "📊 Total changes detected: $TOTAL_CHANGES"
- name: Check for changes and create branch
id: check_changes
run: |
source .github/scripts/git-utils.sh
if check_for_changes; then
create_sync_branch "${{ needs.prepare.outputs.version }}"
# Use aggregated metrics from previous step
commit_and_push_changes \
"${{ needs.prepare.outputs.version }}" \
"${{ steps.get_results.outputs.total_changes }}" \
"${{ steps.get_results.outputs.total_added }}" \
"${{ steps.get_results.outputs.total_updated }}" \
"${{ steps.get_results.outputs.total_deleted }}"
else
echo "No changes to commit"
exit 0
fi
- name: Create Pull Request
if: steps.check_changes.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
source .github/scripts/pr-utils.sh
# Use aggregated sync reports and metrics
SYNC_REPORTS="${{ needs.aggregate-results.outputs.sync_reports }}"
create_documentation_pr \
"${{ needs.prepare.outputs.version }}" \
'${{ needs.prepare.outputs.sync_config }}' \
"$SYNC_REPORTS" \
"${{ steps.get_results.outputs.total_changes }}" \
"${{ steps.get_results.outputs.total_added }}" \
"${{ steps.get_results.outputs.total_updated }}" \
"${{ steps.get_results.outputs.total_deleted }}"
summary:
name: 'Workflow Summary'
runs-on: ubuntu-latest
needs: [prepare, aggregate-results, generate-docs, create-pr]
if: always()
steps:
- name: Generate workflow summary
run: |
echo "# Documentation Sync Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ needs.prepare.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "**Status:** ${{ job.status }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.create-pr.outputs.pr_url }}" != "" ]]; then
echo "**PR Created:** ${{ needs.create-pr.outputs.pr_url }}" >> $GITHUB_STEP_SUMMARY
else
echo "**Result:** No changes detected - no PR created" >> $GITHUB_STEP_SUMMARY
fi