name: Universal Sovereign Canon Anchor

on:
  push:
    branches:
      - master
      - main
  workflow_dispatch:

jobs:
  anchor-and-seed:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Cryptographic Anchoring (Level 8)
        run: |
          echo "Generating SHA-256 cryptographic anchor for current state..."
          find . -type f -not -path "*/\.git/*" -exec sha256sum {} + > state_manifest.sha256
          sha256sum state_manifest.sha256 > MASTER_ANCHOR.txt
          echo "Master Anchor Hash:"
          cat MASTER_ANCHOR.txt

      - name: Generate Hydra Network Seed (Level 12)
        run: |
          sudo apt-get update && sudo apt-get install -y mktorrent
          REPO_NAME=$(basename ${{ github.repository }})
          echo "Compressing raw repository ($REPO_NAME) for decentralized seeding..."
          tar -czf ${REPO_NAME}.tar.gz --exclude='.git' .
          echo "Generating BitTorrent file..."
          mktorrent -a "udp://tracker.opentrackr.org:1337/announce" -p -n "${REPO_NAME}" -o ${REPO_NAME}.torrent ${REPO_NAME}.tar.gz

      - name: Upload Artifacts (Torrent & Anchors)
        uses: actions/upload-artifact@v4
        with:
          name: epistemic-artifacts
          path: |
            MASTER_ANCHOR.txt
            state_manifest.sha256
            *.torrent
            *.tar.gz
