|
| 1 | +name: Build and Test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - 'pr/**' |
| 8 | + paths-ignore: |
| 9 | + - '**/*.md' |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + paths-ignore: |
| 14 | + - '**/*.md' |
| 15 | + |
| 16 | +env: |
| 17 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true |
| 18 | + DOTNET_CLI_TELEMETRY_OPTOUT: 1 |
| 19 | + DOTNET_NOLOGO: true |
| 20 | + VERSION: '5.14.0' |
| 21 | + |
| 22 | +jobs: |
| 23 | + |
| 24 | + build-linux: |
| 25 | + name: Build and Test (Linux) |
| 26 | + runs-on: ubuntu-22.04 # ubuntu-24.04 does not include mono needed for net4x tests |
| 27 | + defaults: |
| 28 | + run: |
| 29 | + working-directory: Src |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout |
| 33 | + uses: actions/checkout@v6 |
| 34 | + |
| 35 | + - name: Setup .NET |
| 36 | + uses: actions/setup-dotnet@v5 |
| 37 | + with: |
| 38 | + dotnet-version: | |
| 39 | + 10.0.x |
| 40 | +
|
| 41 | + - name: Display .NET version |
| 42 | + run: dotnet --version |
| 43 | + |
| 44 | + - name: Restore dependencies |
| 45 | + run: dotnet restore --verbosity quiet |
| 46 | + |
| 47 | + - name: Add AltCover package |
| 48 | + run: dotnet add ./MailMergeLib.Tests/MailMergeLib.Tests.csproj package AltCover |
| 49 | + |
| 50 | + - name: Build solution |
| 51 | + run: dotnet build MailMergeLib.sln /verbosity:minimal /t:rebuild /p:configuration=release /nowarn:CS1591,CS0618 |
| 52 | + |
| 53 | + - name: Run tests |
| 54 | + run: dotnet test --framework net10.0 --no-build --configuration release MailMergeLib.sln /p:AltCover=true /p:AltCoverXmlReport="coverage.xml" /p:AltCoverStrongNameKey="../MailMergeLib/MailMergeLib.snk" /p:AltCoverAssemblyExcludeFilter="MailMergeLib.Tests|NUnit3.TestAdapter" /p:AltCoverLineCover="true" |
| 55 | + |
| 56 | + - name: Upload coverage to Codecov |
| 57 | + uses: codecov/codecov-action@v5 |
| 58 | + with: |
| 59 | + files: ./MailMergeLib.Tests/coverage.net10.0.xml |
| 60 | + flags: net10.0-linux |
| 61 | + name: net10.0-linux |
| 62 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 63 | + |
| 64 | + |
| 65 | + build-windows: |
| 66 | + name: Build and Test (Windows) |
| 67 | + runs-on: windows-2022 |
| 68 | + defaults: |
| 69 | + run: |
| 70 | + working-directory: Src |
| 71 | + |
| 72 | + steps: |
| 73 | + - name: Checkout |
| 74 | + uses: actions/checkout@v6 |
| 75 | + |
| 76 | + - name: Configure Git line endings |
| 77 | + run: git config --global core.autocrlf true |
| 78 | + |
| 79 | + - name: Setup .NET |
| 80 | + uses: actions/setup-dotnet@v5 |
| 81 | + with: |
| 82 | + dotnet-version: | |
| 83 | + 10.0.x |
| 84 | +
|
| 85 | + - name: Display .NET version |
| 86 | + run: dotnet --version |
| 87 | + |
| 88 | + - name: Restore dependencies |
| 89 | + run: dotnet restore --verbosity quiet |
| 90 | + |
| 91 | + - name: Add AltCover package |
| 92 | + run: dotnet add .\MailMergeLib.Tests\MailMergeLib.Tests.csproj package AltCover |
| 93 | + |
| 94 | + - name: Determine version |
| 95 | + id: version |
| 96 | + shell: pwsh |
| 97 | + run: | |
| 98 | + $version = "${{ env.VERSION }}" |
| 99 | + $versionFile = "$version.${{ github.run_number }}" |
| 100 | + |
| 101 | + if ("${{ github.event_name }}" -eq "pull_request") { |
| 102 | + $version = "$version-PR${{ github.event.pull_request.number }}" |
| 103 | + } |
| 104 | + |
| 105 | + echo "VERSION=$version" >> $env:GITHUB_OUTPUT |
| 106 | + echo "FILE_VERSION=$versionFile" >> $env:GITHUB_OUTPUT |
| 107 | + echo "Package version: $version" |
| 108 | + echo "File version: $versionFile" |
| 109 | + |
| 110 | + - name: Build solution |
| 111 | + run: dotnet build MailMergeLib.sln /verbosity:minimal /t:rebuild /p:configuration=release /p:IncludeSymbols=true /p:ContinuousIntegrationBuild=true /p:Version=${{ steps.version.outputs.VERSION }} /p:FileVersion=${{ steps.version.outputs.FILE_VERSION }} |
| 112 | + |
| 113 | + - name: Run tests (net462) |
| 114 | + run: dotnet test --framework net462 --no-build --configuration release MailMergeLib.sln /p:AltCover=true /p:AltCoverXmlReport="coverage.xml" /p:AltCoverStrongNameKey="..\MailMergeLib\MailMergeLib.snk" /p:AltCoverAssemblyExcludeFilter="MailMergeLib.Tests|NUnit3.TestAdapter" /p:AltCoverLineCover="true" |
| 115 | + |
| 116 | + - name: Run tests (net10.0) |
| 117 | + run: dotnet test --framework net10.0 --no-build --configuration release MailMergeLib.sln /p:AltCover=true /p:AltCoverXmlReport="coverage.xml" /p:AltCoverStrongNameKey="..\MailMergeLib\MailMergeLib.snk" /p:AltCoverAssemblyExcludeFilter="MailMergeLib.Tests|NUnit3.TestAdapter" /p:AltCoverLineCover="true" |
| 118 | + |
| 119 | + - name: Upload coverage to Codecov |
| 120 | + uses: codecov/codecov-action@v5 |
| 121 | + with: |
| 122 | + files: ./Src/MailMergeLib.Tests/coverage.net10.0.xml |
| 123 | + flags: net10.0-windows |
| 124 | + name: net10.0-windows |
| 125 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 126 | + |
| 127 | + - name: Pack NuGet packages |
| 128 | + run: dotnet pack MailMergeLib.sln --verbosity minimal --no-build --configuration release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=${{ github.workspace }}/artifacts /p:ContinuousIntegrationBuild=true |
| 129 | + |
| 130 | + - name: Upload NuGet packages as artifacts |
| 131 | + uses: actions/upload-artifact@v7 |
| 132 | + with: |
| 133 | + name: nuget-packages |
| 134 | + path: | |
| 135 | + artifacts/*.nupkg |
| 136 | + artifacts/*.snupkg |
| 137 | + retention-days: 30 |
| 138 | + |
| 139 | + - name: Publish to NuGet |
| 140 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 141 | + run: dotnet nuget push "artifacts/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate |
0 commit comments