name: Unit-tests on Linux CPU

on:
  pull_request:
  push:
    branches:
      - nightly
      - main
      - release/*
  workflow_dispatch:

jobs:
  tests:
    strategy:
      matrix:
        python_version: ["3.8", "3.9", "3.10"]
      fail-fast: false
    uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
    with:
      runner: linux.12xlarge
      repository: pytorch/audio
      timeout: 120
      script: |
        echo '::group::Setup Environment Variables'
        # Mark Build Directory Safe
        git config --global --add safe.directory /__w/audio/audio

        # Set up Environment Variables
        export PYTHON_VERSION="${{ matrix.python_version }}"
        export CUDA_TESTS_ONLY="0"
        unset CUDA_VERSION

        # Set CHANNEL
        if [[(${GITHUB_EVENT_NAME} = 'pull_request' && (${GITHUB_BASE_REF} = 'release'*)) || (${GITHUB_REF} = 'refs/heads/release'*) ]]; then
          export UPLOAD_CHANNEL=test
        else
          export UPLOAD_CHANNEL=nightly
        fi

        export PATH="${PWD}/third_party/install/bin/:${PATH}"
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_CMD_APPLY_CMVN_SLIDING=true
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_CMD_COMPUTE_FBANK_FEATS=true
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_CMD_COMPUTE_KALDI_PITCH_FEATS=true
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_CMD_COMPUTE_MFCC_FEATS=true
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_CMD_COMPUTE_SPECTROGRAM_FEATS=true
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_KALDI=true
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_CUDA=true
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_HW_ACCEL=true
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_ON_PYTHON_310=true
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_AUDIO_OUT_DEVICE=true
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MACOS=true
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_TEMPORARY_DISABLED=true
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_DECODER=true
        export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER=true
        echo '::endgroup::'

        set -euxo pipefail

        echo '::group::Install PyTorch and Torchaudio'
        ./.github/scripts/unittest-linux/install.sh
        echo '::endgroup::'

        echo '::group::Run Tests'
        ./.github/scripts/unittest-linux/run_test.sh
        echo '::endgroup::'
