name: Docs Auto-Sync

on:
  schedule:
    - cron: '0 0 * * *' # Daily at midnight
  workflow_dispatch: # Manual trigger

jobs:
  autosync:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        
      - name: Build Decapod
        run: cargo build --release
        
      - name: Generate Docs
        run: ./target/release/decapod docs build
        
      - name: Check for drift
        id: drift
        run: |
          if [ -n "$(git status --porcelain docs/)" ]; then
            echo "drift=true" >> $GITHUB_OUTPUT
          else
            echo "drift=false" >> $GITHUB_OUTPUT
          fi
          
      - name: Create Pull Request
        if: steps.drift.outputs.drift == 'true'
        uses: peter-evans/create-pull-request@v6
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: "docs: auto-sync documentation from code state"
          title: "docs: auto-sync documentation from code state"
          body: |
            This is an automated PR to sync documentation with the current code state.
            Generated by Decapod Docs Auto-Sync workflow.
          branch: docs-autosync
          base: master
