diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..4e0a7fe --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,59 @@ +name: Build + +on: + push: + branches: + - master + pull_request: + branches: + - master + workflow_dispatch: + +env: + DOTNET_NOLOGO: true + DOTNET_CLI_TELEMETRY_OPTOUT: true + +jobs: + build: + name: Build and test + runs-on: windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup MSBuild + uses: microsoft/setup-msbuild@v2 + + - name: Setup NuGet + uses: NuGet/setup-nuget@v2 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: | + 5.0.x + + # The six games in the root solution are old-style .NET Framework projects, + # so they need MSBuild rather than the dotnet CLI. They target v4.5, whose + # targeting pack is no longer installed on the hosted runners, so the build + # retargets them to 4.8 (source-compatible for these console apps) instead + # of changing the projects. + - name: Build the .NET Framework games + run: | + nuget restore CSharpConsoleGames.sln + msbuild CSharpConsoleGames.sln -p:Configuration=Release -p:Platform="Any CPU" -p:TargetFrameworkVersion=v4.8 -m + + - name: Build and test TicTacToe + run: dotnet test TicTacToe/TicTacToe.sln -c Release --logger "trx;LogFileName=test-results.trx" + + - name: Build Tetris (.NET Core) + run: dotnet build "Tetris (.NET Core)/Tetris.sln" -c Release + + - name: Upload test results + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-results + path: '**/TestResults/*.trx' + if-no-files-found: ignore diff --git a/TicTacToe/TicTacToeTests/TicTacToeGameTests.cs b/TicTacToe/TicTacToeTests/TicTacToeGameTests.cs index cdae633..bc0d190 100644 --- a/TicTacToe/TicTacToeTests/TicTacToeGameTests.cs +++ b/TicTacToe/TicTacToeTests/TicTacToeGameTests.cs @@ -40,8 +40,8 @@ public void PlayShouldReturnCorrectWinner() .Returns((Board x, Symbol s) => new Index(1, player2CurrentCol++)); var game = new TicTacToeGame(player1.Object, player2.Object); - var winner = game.Play(); - Assert.AreEqual(Symbol.X, winner); + var result = game.Play(); + Assert.AreEqual(Symbol.X, result.Winner); } // TODO: Add more tests diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 6a9684e..0000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,33 +0,0 @@ -# .NET Desktop -# Build and run tests for .NET Desktop or Windows classic desktop solutions. -# Add steps that publish symbols, save build artifacts, and more: -# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net - -trigger: -- master - -pool: - vmImage: 'windows-latest' - -variables: - solution: '**/*.sln' - buildPlatform: 'Any CPU' - buildConfiguration: 'Release' - -steps: -- task: NuGetToolInstaller@1 - -- task: NuGetCommand@2 - inputs: - restoreSolution: '$(solution)' - -- task: VSBuild@1 - inputs: - solution: '$(solution)' - platform: '$(buildPlatform)' - configuration: '$(buildConfiguration)' - -- task: VSTest@2 - inputs: - platform: '$(buildPlatform)' - configuration: '$(buildConfiguration)'