---
name: run-nightly-tests

on:
  workflow_dispatch:
  schedule:
    - cron: '0 01 * * *'

jobs:
  nightly-tests:
    runs-on: nvme-nvm
    container:
      image: ghcr.io/linux-nvme/debian.python:latest
      #Expose all devices to the container through the `privileged` flag.
      #
      #BDEV0 is an environment variable of the self-hosted runner instance
      #that contains a valid nvme ctrl name which is capable of the nvm
      #command set.
      options: '--privileged -v "/dev":"/dev":z -e BDEV0'
    steps:
      - name: Output kernel version
        run: |
          uname -a
      - uses: actions/checkout@v4
      - name: Install dependencies
        run: |
          PIPX_BIN_DIR=/usr/local/bin pipx install nose2 --force
      - name: Build and install nvme-cli
        run: |
          scripts/build.sh -b release -c gcc
      - name: Overwrite test config
        run: |
          CONTROLLER=$(echo /dev/${BDEV0} | sed 's/n[0-9]*$//')
          cat > tests/config.json << EOF
          {
            "controller" : "$CONTROLLER",
            "ns1": "/dev/${BDEV0}",
            "log_dir": "tests/nvmetests/",
            "nvme_bin": "$(pwd)/.build-ci/nvme"
          }
          EOF
          cat tests/config.json
      - name: Run on device tests
        run: |
          nose2 --verbose --start-dir tests \
          nvme_attach_detach_ns_test \
          nvme_compare_test \
          nvme_copy_test \
          nvme_create_max_ns_test \
          nvme_ctrl_reset_test \
          nvme_dsm_test \
          nvme_error_log_test \
          nvme_flush_test \
          nvme_format_test \
          nvme_fw_log_test \
          nvme_get_features_test \
          nvme_get_lba_status_test \
          nvme_id_ctrl_test \
          nvme_id_ns_test \
          nvme_lba_status_log_test \
          nvme_read_write_test \
          nvme_smart_log_test \
          nvme_verify_test \
          nvme_writeuncor_test \
          nvme_writezeros_test
      - name: Upload logs
        uses: actions/upload-artifact@v4
        if: always()
        with:
          name: nvme-cli-test-logs
          path: |
            ./tests/nvmetests/**/*.log