name: Validate dotnet

on:
  pull_request:
    paths-ignore:
      - '**.md'
  push:
    branches:
      - main
      - releases/*
    paths-ignore:
      - '**.md'

jobs:
  setup-version:
    runs-on: ${{ matrix.operating-system }}
    strategy:
      fail-fast: false
      matrix:
        operating-system: [ubuntu-22.04, windows-latest, macOS-latest]
        dotnet-version: ['2.1', '2.2', '3.0', '3.1', '5.0']
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Clear toolcache
        shell: pwsh
        run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
      - name: Setup dotnet ${{ matrix.dotnet-version }}
        uses: ./
        with:
          dotnet-version: ${{ matrix.dotnet-version }}
      - name: Check installed version
        shell: pwsh
        run: |
          $version = & dotnet --version
          Write-Host "Installed version: $version"
          if (-not $version.StartsWith("${{ matrix.dotnet-version }}")) { throw "Unexpected version" }