blvm-node 0.1.9

Bitcoin Commons BLVM: Minimal Bitcoin node implementation using blvm-protocol and blvm-consensus
name: Cleanup Runner Disk

on:
  schedule:
    # Every Sunday at 03:00 UTC
    - cron: '0 3 * * 0'
  workflow_dispatch:
    inputs:
      dry_run:
        description: 'Dry run (print what would be deleted, do not delete)'
        required: false
        type: boolean
        default: false

permissions:
  contents: read

jobs:
  cleanup:
    name: Cleanup self-hosted runner disk
    runs-on: [self-hosted, Linux, X64, builds]
    env:
      # Match ci.yml: optional large-disk path via repo/org variable BLVM_RUNNER_BUILD_ROOT.
      BLVM_RUNNER_DATA_ROOT: ${{ vars.BLVM_RUNNER_BUILD_ROOT || format('{0}/.build/gh-blvm-node-build', github.workspace) }}
    steps:
      - uses: actions/checkout@v4

      - name: Report disk before
        run: df -h /

      - name: Prune old GitHub Actions runner diag logs (often on same volume as _work)
        run: |
          DRY="${{ github.event.inputs.dry_run }}"
          for d in /var/lib/github-runner-*/_diag/pages; do
            if [ -d "$d" ]; then
              echo "=== Diag logs in $d (prune *.log older than 3 days) ==="
              du -sh "$d" 2>/dev/null || true
              if [ "$DRY" != "true" ]; then
                find "$d" -type f -name '*.log' -mtime +3 -delete 2>/dev/null || true
              fi
            fi
          done

      - name: Remove CI per-run build dirs (same path as ci.yml BLVM_BUILD_TARGET)
        run: |
          DRY="${{ github.event.inputs.dry_run }}"
          BASE="${BLVM_RUNNER_DATA_ROOT}"
          if [ ! -d "$BASE" ]; then
            echo "No build dir at $BASE"
          else
            echo "=== ALL run dirs under $BASE ==="
            find "$BASE" -mindepth 1 -maxdepth 1 -type d | while read -r dir; do
              SIZE=$(du -sh "$dir" 2>/dev/null | cut -f1)
              echo "  $dir ($SIZE)"
              if [ "$DRY" != "true" ]; then
                rm -rf "$dir"
              fi
            done
          fi
          # Legacy path (older CI) — still remove if present
          LEGACY="/tmp/gh-blvm-node-build"
          if [ -d "$LEGACY" ]; then
            SIZE=$(du -sh "$LEGACY" 2>/dev/null | cut -f1)
            echo "=== Legacy $LEGACY ($SIZE) ==="
            if [ "$DRY" != "true" ]; then
              rm -rf "$LEGACY"
            fi
          fi
          # Fuzz dir next to .build (ci.yml rm -rf path)
          FUZZ="${{ github.workspace }}/.build/gh-fuzz-blvm-node"
          if [ -d "$FUZZ" ]; then
            SIZE=$(du -sh "$FUZZ" 2>/dev/null | cut -f1)
            echo "=== $FUZZ ($SIZE) ==="
            if [ "$DRY" != "true" ]; then
              rm -rf "$FUZZ"
            fi
          fi
          if [ -d /tmp/gh-fuzz-blvm-node ]; then
            SIZE=$(du -sh /tmp/gh-fuzz-blvm-node 2>/dev/null | cut -f1)
            echo "  /tmp/gh-fuzz-blvm-node ($SIZE)"
            if [ "$DRY" != "true" ]; then
              rm -rf /tmp/gh-fuzz-blvm-node
            fi
          fi

      - name: Remove stale test binaries from workspace target (older than 7 days)
        run: |
          DRY="${{ github.event.inputs.dry_run }}"
          TARGET="${{ github.workspace }}/target/debug"
          if [ ! -d "$TARGET" ]; then
            echo "No local target/debug found"
            exit 0
          fi
          echo "=== Large stale test executables in $TARGET ==="
          find "$TARGET" -maxdepth 1 -type f -executable \
            ! -name "*.so" ! -name "*.rlib" ! -name "*.d" \
            -mtime +7 -size +50M | while read -r f; do
            SIZE=$(du -sh "$f" 2>/dev/null | cut -f1)
            echo "  $f ($SIZE)"
            if [ "$DRY" != "true" ]; then
              rm -f "$f"
            fi
          done

      - name: Remove old incremental fingerprints and rlibs (older than 14 days)
        run: |
          DRY="${{ github.event.inputs.dry_run }}"
          TARGET="${{ github.workspace }}/target"
          if [ ! -d "$TARGET" ]; then exit 0; fi
          BYTES=0
          COUNT=0
          while IFS= read -r f; do
            BYTES=$((BYTES + $(stat -c%s "$f" 2>/dev/null || echo 0)))
            COUNT=$((COUNT + 1))
            if [ "$DRY" != "true" ]; then rm -f "$f"; fi
          done < <(find "$TARGET/debug/.fingerprint" "$TARGET/debug/incremental" \
            -type f -mtime +14 2>/dev/null)
          echo "Would remove / removed: $COUNT fingerprint/incremental files (~$((BYTES / 1048576)) MB)"

      - name: Report disk after
        run: df -h /