name: Manny the Manager

on:
  workflow_dispatch:
    inputs:
      checkout:
        required: true
        type: boolean
      cleanup:
        required: true
        type: boolean
      peek:
        required: true
        type: boolean

jobs:
  inventory:
    runs-on: ubuntu-latest
    steps:
      - name: Disk usage ...
        run: |
          cd
          du -hs .[^.]*
      - name: Disk inventory (1/2) ...
        run: |
          echo "df -h ========================================================================="
          df -h
          echo "mounts ========================================================================"
          mount
      - name: File inventory (1/2) ...
        run: |
          echo "Current directory: $(pwd)"
          echo "Files in $HOME ================================================================"
          ls $HOME
          echo "Find $HOME ===================================================================="
          find $HOME
      - name: Container inventory ...
        run: |
          echo "Available container images: ==================================================="
          docker images
          echo "Available containers: ========================================================="
          docker ps -a

  checkout:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/actions/cache-restore
        with:
          target: x86_64
          dl-prefix: dl-netconf
      - name: Disk inventory (2/2) ...
        run: |
          echo "df -h ========================================================================="
          df -h
          echo "mounts ========================================================================"
          mount
      - name: File inventory (2/2) ...
        run: |
          echo "Current directory: $(pwd)"
          echo "Files in $HOME ================================================================"
          ls $HOME
          echo "Find $HOME ===================================================================="
          find $HOME

  peeky:
    if: ${{ inputs.peek }}
    runs-on: ubuntu-latest
    steps:
      - name: Peek & Poke ...
        run: |
          whoami
          ls -l /mnt/
          cat /mnt/DATALOSS_WARNING_README.txt
          sudo mkdir /mnt/x-aarch64
          sudo chown $(id -un):$(id -gn) /mnt/x-aarch64
          ls -l /mnt/

  cleanup:
    if: ${{ inputs.cleanup }}
    needs: [inventory, peeky]
    runs-on: ubuntu-latest
    steps:
      - name: Cleaning up cruft ...
        run: |
          docker image prune -af
          docker volume prune -f
          docker container prune -f
