diff --git a/.github/workflows/build.yml b/.github/workflows/integrationtests.yml similarity index 67% rename from .github/workflows/build.yml rename to .github/workflows/integrationtests.yml index 329176c96..5dfa76aa6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/integrationtests.yml @@ -1,4 +1,4 @@ -name: Build and tests +name: Integration tests # Workflow Trigger on: @@ -36,6 +36,35 @@ jobs: with: name: NuGet Package path: ./BuildArtifacts/Packages/NuGet/ + # Integration Tests Cake.Issues.MsBuild Cake Scripting + IntegrationTestsMsBuildCakeScripting: + name: Integration Tests Cake.Issues.MsBuild Cake Scripting + needs: Build + strategy: + fail-fast: false + matrix: + os: [ + windows-2019, windows-2022, + ubuntu-20.04, ubuntu-22.04, + macos-11, macos-14] + dotnet: [6.x, 7.x, 8.x] + runs-on: ${{ matrix.os }} + steps: + - name: Get the sources + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - name: Download build artifact + uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4 + with: + name: NuGet Package + path: ./BuildArtifacts/Packages/NuGet + - name: Install .NET + uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4 + with: + dotnet-version: ${{ matrix.dotnet }} + - name: Run integration tests + run: ./build.sh --verbosity=diagnostic + working-directory: ./tests/Cake.Issues.MsBuild/script-runner/ + shell: bash # Integration Tests Cake.Issues.PullRequests.GitHubActions Cake Scripting IntegrationTestsPullRequestsGitHubActionsCakeScripting: name: Integration Tests Cake.Issues.PullRequests.GitHubActions Cake Scripting diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml new file mode 100644 index 000000000..096d3b73d --- /dev/null +++ b/.github/workflows/unittests.yml @@ -0,0 +1,40 @@ +name: Unit tests + +# Workflow Trigger +on: + # Trigger the workflow on a pull request to any branch + pull_request: + # Triggers the workflow in the event there is a push to master + push: + branches: + - master + +jobs: + Test: + name: Run unit tests + strategy: + fail-fast: false + matrix: + os: [ + windows-2019, windows-2022, + ubuntu-20.04, ubuntu-22.04, + # Cake.Recipe currently does not support macOS 14 (M1) + macos-11, macos-13] + runs-on: ${{ matrix.os }} + steps: + - name: Get the sources + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - name: Fetch all tags and branches + run: git fetch --prune --unshallow + - name: Install .NET + uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4 + with: + # .NET 5 required for GitVersion + dotnet-version: | + 5.x + 6.x + 7.x + 8.x + - name: Test + run: ./build.sh --target=Test + shell: bash \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 243e45f49..29c8e94a7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -99,6 +99,35 @@ stages: artifact: Integration Tests Cake.Issues.Markdownlint $(System.JobName) displayName: 'Publish generated reports as build artifact' +- stage: IntegrationTestsMsBuildStage + displayName: Integration Tests Cake.Issues.MsBuild + dependsOn: BuildStage + jobs: + - job: TestMsBuildJob + displayName: Test + strategy: + matrix: + Windows_Server_2019: + imageName: 'windows-2019' + Windows_Server_2022: + imageName: 'windows-2022' + macOS_11: + imageName: 'macOS-11' + macOS_13: + imageName: 'macOS-13' + Ubuntu_20_04: + imageName: 'ubuntu-20.04' + Ubuntu_22_04: + imageName: 'ubuntu-22.04' + pool: + vmImage: $(imageName) + steps: + - template: .azuredevops/pipelines/templates/steps/install-net6.yml + - template: .azuredevops/pipelines/templates/steps/provide-nuget-packages.yml + - powershell: ./build.ps1 --verbosity=diagnostic + workingDirectory: ./tests/Cake.Issues.MsBuild/script-runner + displayName: 'Run integration tests' + - stage: IntegrationTestsReportingConsoleStage displayName: Integration Tests Cake.Issues.Reporting.Console dependsOn: BuildStage diff --git a/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs b/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs index d14512be3..cb485d9bc 100644 --- a/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs +++ b/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; + using System.Runtime.InteropServices; using Cake.Core.Diagnostics; using Microsoft.Build.Framework; using Microsoft.Build.Logging.StructuredLogger; @@ -23,6 +24,13 @@ public override IEnumerable ReadIssues( repositorySettings.NotNull(nameof(repositorySettings)); issueProviderSettings.NotNull(nameof(issueProviderSettings)); + // Ensure that strings for MsBuild.StructuredLogger are initialized. + // See https://github.com/KirillOsenkov/MSBuildStructuredLog/issues/736 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Strings.Initialize(); + } + var result = new List(); var binLogReader = new BinLogReader(); diff --git a/tests/Cake.Issues.MsBuild/script-runner/.config/dotnet-tools.json b/tests/Cake.Issues.MsBuild/script-runner/.config/dotnet-tools.json new file mode 100644 index 000000000..da200cdae --- /dev/null +++ b/tests/Cake.Issues.MsBuild/script-runner/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "4.0.0", + "commands": [ + "dotnet-cake" + ] + } + } +} \ No newline at end of file diff --git a/tests/Cake.Issues.MsBuild/script-runner/.gitignore b/tests/Cake.Issues.MsBuild/script-runner/.gitignore new file mode 100644 index 000000000..e7c496290 --- /dev/null +++ b/tests/Cake.Issues.MsBuild/script-runner/.gitignore @@ -0,0 +1,379 @@ + +# Created by https://www.gitignore.io/api/cake,windows,visualstudio,visualstudiocode + +### Cake ### +tools/* +!tools/packages.config + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + + +# End of https://www.gitignore.io/api/cake,windows,visualstudio,visualstudiocode + + +# Project specific folders +BuildArtifacts diff --git a/tests/Cake.Issues.MsBuild/script-runner/build.cake b/tests/Cake.Issues.MsBuild/script-runner/build.cake new file mode 100644 index 000000000..2a33e6916 --- /dev/null +++ b/tests/Cake.Issues.MsBuild/script-runner/build.cake @@ -0,0 +1,72 @@ +#load "buildData.cake" + +#addin "Cake.Issues&prerelease" +#addin "Cake.Issues.MsBuild&prerelease" + +////////////////////////////////////////////////// +// ARGUMENTS +////////////////////////////////////////////////// + +var target = Argument("target", "Default"); + +////////////////////////////////////////////////// +// SETUP / TEARDOWN +////////////////////////////////////////////////// + +Setup(setupContext => +{ + return new BuildData(); +}); + +var repoRootFolder = MakeAbsolute(Directory("./")); +var logPath = repoRootFolder.Combine("BuildArtifacts").Combine("logs"); + +////////////////////////////////////////////////// +// TARGETS +////////////////////////////////////////////////// + +Task("Build") + .Does((data) => +{ + var msBuildLogPath = logPath.CombineWithFilePath("msbuild.binlog"); + var solutionFile = + repoRootFolder + .Combine("src") + .CombineWithFilePath("ClassLibrary1.sln"); + + DotNetRestore(solutionFile.FullPath); + + var settings = + new DotNetMSBuildSettings() + .WithTarget("Rebuild") + .WithLogger( + "BinaryLogger," + Context.Tools.Resolve("Cake.Issues.MsBuild*/**/StructuredLogger.dll"), + "", + msBuildLogPath.FullPath + ); + + DotNetBuild( + solutionFile.FullPath, + new DotNetBuildSettings + { + MSBuildSettings = settings + }); + + data.AddIssues( + ReadIssues( + MsBuildIssuesFromFilePath( + msBuildLogPath, + MsBuildBinaryLogFileFormat), + repoRootFolder) + ); +}); + +// Run Build task by default. +Task("Default") + .IsDependentOn("Build"); + +////////////////////////////////////////////////// +// EXECUTION +////////////////////////////////////////////////// + +RunTarget(target); \ No newline at end of file diff --git a/tests/Cake.Issues.MsBuild/script-runner/build.ps1 b/tests/Cake.Issues.MsBuild/script-runner/build.ps1 new file mode 100644 index 000000000..fe6027689 --- /dev/null +++ b/tests/Cake.Issues.MsBuild/script-runner/build.ps1 @@ -0,0 +1,15 @@ +$ErrorActionPreference = 'Stop' + +$SCRIPT_NAME = "build.cake" + +Write-Host "Restoring .NET Core tools" +dotnet tool restore +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + +Write-Host "Bootstrapping Cake" +dotnet cake $SCRIPT_NAME --bootstrap +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + +Write-Host "Running Build" +dotnet cake $SCRIPT_NAME @args +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } \ No newline at end of file diff --git a/tests/Cake.Issues.MsBuild/script-runner/build.sh b/tests/Cake.Issues.MsBuild/script-runner/build.sh new file mode 100755 index 000000000..921a3241b --- /dev/null +++ b/tests/Cake.Issues.MsBuild/script-runner/build.sh @@ -0,0 +1,11 @@ +#!/bin/bash +SCRIPT_NAME="build.cake" + +echo "Restoring .NET Core tools" +dotnet tool restore + +echo "Bootstrapping Cake" +dotnet cake $SCRIPT_NAME --bootstrap + +echo "Running Build" +dotnet cake $SCRIPT_NAME "$@" \ No newline at end of file diff --git a/tests/Cake.Issues.MsBuild/script-runner/buildData.cake b/tests/Cake.Issues.MsBuild/script-runner/buildData.cake new file mode 100644 index 000000000..8a22d4145 --- /dev/null +++ b/tests/Cake.Issues.MsBuild/script-runner/buildData.cake @@ -0,0 +1,29 @@ +public class BuildData +{ + private readonly List issues = new List(); + + /// + /// Gets issues determined during building. + /// + public IEnumerable Issues + { + get + { + return issues.AsReadOnly(); + } + } + + /// + /// Add issues to . + /// + /// List of issues which should be added. + public void AddIssues(IEnumerable issues) + { + if (issues == null) + { + throw new NullReferenceException(nameof(issues)); + } + + this.issues.AddRange(issues); + } +} \ No newline at end of file diff --git a/tests/Cake.Issues.MsBuild/script-runner/nuget.config b/tests/Cake.Issues.MsBuild/script-runner/nuget.config new file mode 100644 index 000000000..62768c3d3 --- /dev/null +++ b/tests/Cake.Issues.MsBuild/script-runner/nuget.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Cake.Issues.MsBuild/script-runner/src/ClassLibrary1.sln b/tests/Cake.Issues.MsBuild/script-runner/src/ClassLibrary1.sln new file mode 100644 index 000000000..62df92e3d --- /dev/null +++ b/tests/Cake.Issues.MsBuild/script-runner/src/ClassLibrary1.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{9B73BB5B-06A3-46F3-9068-E3607A8217B0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9B73BB5B-06A3-46F3-9068-E3607A8217B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B73BB5B-06A3-46F3-9068-E3607A8217B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B73BB5B-06A3-46F3-9068-E3607A8217B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B73BB5B-06A3-46F3-9068-E3607A8217B0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/tests/Cake.Issues.MsBuild/script-runner/src/ClassLibrary1/Class1.cs b/tests/Cake.Issues.MsBuild/script-runner/src/ClassLibrary1/Class1.cs new file mode 100644 index 000000000..4ea00049a --- /dev/null +++ b/tests/Cake.Issues.MsBuild/script-runner/src/ClassLibrary1/Class1.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClassLibrary1 +{ + public class Class1 + { + public void Foo() + { + var foo = "foo"; + var bar = "bar"; + if (!string.IsNullOrEmpty(foo) && !string.IsNullOrEmpty(bar)) + { + var foobar = foo + bar; + } + } + + public void Bar() + { + var foo = "foo"; + var bar = "bar"; + if (!string.IsNullOrEmpty(foo) && !string.IsNullOrEmpty(bar)) + { + var foobar = foo + bar; + } + } + } +} diff --git a/tests/Cake.Issues.MsBuild/script-runner/src/ClassLibrary1/ClassLibrary1.csproj b/tests/Cake.Issues.MsBuild/script-runner/src/ClassLibrary1/ClassLibrary1.csproj new file mode 100644 index 000000000..9ec4dd90e --- /dev/null +++ b/tests/Cake.Issues.MsBuild/script-runner/src/ClassLibrary1/ClassLibrary1.csproj @@ -0,0 +1,21 @@ + + + + netstandard2.0 + + + + + all + 3.0.0 + + + all + 1.1.118 + + + + + + + \ No newline at end of file