name: Test netstandard

on: pull_request

jobs:
  test-netstandard:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        netstandard-version: ['netstandard2.0', 'netstandard2.1']

    steps:
    - uses: actions/checkout@v4

    - name: Setup .NET
      uses: actions/setup-dotnet@v4
      with:
        dotnet-version: |
          8.0.x
          10.0.x

    - name: Patch build to test ${{ matrix.netstandard-version }}
      run: |
        cd src
        sed -i 's/<TargetFrameworks>.*<\/TargetFrameworks>/<TargetFrameworks>${{ matrix.netstandard-version }}<\/TargetFrameworks>/' Markdig/Markdig.targets
        sed -i 's/<TargetFrameworks>.*<\/TargetFrameworks>/<TargetFrameworks>net8.0;net10.0<\/TargetFrameworks>/' Markdig.Tests/Markdig.Tests.csproj
        echo "Markdig.targets TFMs:"
        grep "TargetFrameworks" Markdig/Markdig.targets
        echo "Markdig.Tests.csproj TFMs:"
        grep "TargetFrameworks" Markdig.Tests/Markdig.Tests.csproj

    - name: Restore dependencies
      run: dotnet restore src/Markdig.Tests/Markdig.Tests.csproj

    - name: Test Debug
      run: |
        dotnet build src/Markdig.Tests/Markdig.Tests.csproj -c Debug --no-restore -p:MarkdigNoRuneTests=true
        dotnet test src/Markdig.Tests/Markdig.Tests.csproj -c Debug --no-build

    - name: Test Release
      run: |
        dotnet build src/Markdig.Tests/Markdig.Tests.csproj -c Release --no-restore -p:MarkdigNoRuneTests=true
        dotnet test src/Markdig.Tests/Markdig.Tests.csproj -c Release --no-build
