name: 'Gigabyte Cuttlefish installer check preseed after install script'

inputs:
  emulate-nvidia:
    required: false
    default: "false"
  emulate-amd:
    required: false
    default: "false"

runs:
  using: "composite"
  steps:
  - name: Prepare test environment
    shell: bash
    run: |
      apt-get update
      apt-get upgrade -y
      apt-get install -y sudo
      apt-get install -y ca-certificates
      apt-get install -y initramfs-tools
      apt-get install -y grub-efi-arm64
      apt-get install -y lsb-release
      apt-get install -y pciutils
      apt-get install -y apt-show-versions
  - name: Setup base and non-free repository
    shell: bash
    run: |
      echo "deb http://deb.debian.org/debian $(lsb_release -c -s) main contrib non-free non-free-firmware" | tee /etc/apt/sources.list
      apt -o Apt::Get::Assume-Yes=true -o APT::Color=0 -o DPkgPM::Progress-Fancy=0 update
  - name: Setup backports repository
    shell: bash
    run: |
      if grep "apt-setup/services-select" preseed/preseed.cfg  | grep backports  | egrep '^[^#]'; then
        echo "deb http://deb.debian.org/debian $(lsb_release -c -s)-backports main contrib non-free non-free-firmware" | tee /etc/apt/sources.list.d/debian-backports-1.list
        apt -o Apt::Get::Assume-Yes=true -o APT::Color=0 -o DPkgPM::Progress-Fancy=0 update
      fi
  - name: Setup pinned snapshot source
    working-directory: ./gigabyte-ampere-cuttlefish-installer
    shell: bash
    run: |
      mkdir -p /root/debian-snapshot
      cp -f preseed/debian-snapshot.list /root/debian-snapshot/
  - name: Check nVidia GPU emulation
    shell: bash
    run: echo "EMULATE_NVIDIA_GPU=${{ inputs.emulate-nvidia }}" >> $GITHUB_ENV
  - name: Check AMD GPU emulation
    shell: bash
    run: echo "EMULATE_AMD_GPU=${{ inputs.emulate-amd }}" >> $GITHUB_ENV
  - name: Running tests
    working-directory: ./gigabyte-ampere-cuttlefish-installer
    shell: bash
    run: |
      ./tests/test-after-install-script-kernel.sh
      sh after_install_1_kernel.sh
      apt-show-versions linux-image-arm64
      apt-show-versions linux-headers-arm64
      apt-show-versions firmware-amd-graphics
      apt-show-versions nvidia-open-kernel-dkms
      apt-show-versions nvidia-kernel-dkms
      apt-show-versions nvidia-driver
      apt-show-versions firmware-misc-nonfree
