name: WSL2

# spell-checker:ignore nextest noprofile norc

on:
  pull_request:
  push:
    branches:
      - '*'

permissions:
  contents: read # to fetch code (actions/checkout)

# End the current execution if there is a new changeset in the PR.
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
  test:
    name: Test
    runs-on: ${{ matrix.job.os }}
    timeout-minutes: 45
    strategy:
      fail-fast: false
      matrix:
        job:
          - { os: windows-latest, distribution: Ubuntu-24.04, features: feat_os_unix}
    steps:
    - uses: actions/checkout@v5
      with:
        persist-credentials: false
    - name: Install WSL2
      uses: Vampire/setup-wsl@v6.0.0
      with:
        additional-packages: build-essential
        distribution: ${{ matrix.job.distribution }}
        use-cache: 'true'
        wsl-version: 2
    - name: Set up WSL2 user
      shell: wsl-bash {0}
      run: |
        useradd -m -p password user
    - name: Set up WSL2 shell command
      uses: Vampire/setup-wsl@v6.0.0
      with:
        distribution: ${{ matrix.job.distribution }}
        wsl-shell-command: bash -c "sudo -u user bash --noprofile --norc -euo pipefail '{0}'"
    # it is required to use WSL2's linux file system, so we do a second checkout there
    - name: Checkout source in WSL2
      shell: wsl-bash {0}
      run: |
        git clone "$(pwd)" "$HOME/src"
    - name: Install rust and nextest
      shell: wsl-bash {0}
      run: |
        curl https://sh.rustup.rs -sSf --output rustup.sh
        sh rustup.sh -y --profile=minimal
        curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C "$HOME/.cargo/bin"
    - name: Test
      shell: wsl-bash {0}
      run: |
        cd "$HOME/src"
        # chmod tests expect umask 0022
        umask 0022
        . "$HOME/.cargo/env"
        export CARGO_TERM_COLOR=always
        export RUST_BACKTRACE=1
        cargo nextest run --hide-progress-bar --profile ci --features '${{ matrix.job.features }}'
