Skip to content

Commit

Permalink
Load MSBuild from SDK. Run NET5.0 tests on CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich committed May 16, 2021
1 parent 88cea1e commit 84c3a47
Show file tree
Hide file tree
Showing 49 changed files with 498 additions and 450 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/tests-net5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

name: 'Tests net5.0'
env:
DotNetVersion: "5.0.104"
DotNetVersion2: "3.1.407"
NuGetVersion: "5.7.0"
MonoVersion: "6.12.0"
Artifacts: ${{ github.workspace }}/artifacts/
Coverage: ${{ github.workspace }}/coverage/
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "true"
defaults:
run:
shell: pwsh
on:
pull_request:
branches:
- master
- demo/*
tags:
- '*'
workflow_dispatch:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-18.04, windows-2019, macos-10.15]
testProjects:
- OmniSharp.MSBuild.Tests,OmniSharp.Roslyn.CSharp.Tests,OmniSharp.Script.Tests,OmniSharp.Stdio.Tests,OmniSharp.Http.Tests,OmniSharp.Tests,OmniSharp.Lsp.Tests
- OmniSharp.DotNetTest.Tests
name: 'Test'
steps:
- name: Checkout
uses: actions/checkout@v2
with:
clean: 'false'
fetch-depth: '0'

# TODO: Need to figure out the correct way to install mono on linux / mac
# Currently the latest image has mono 6.12
# https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu1804-README.md
# - name: 🔨 Use Mono ${{ env.MonoVersion }} SDK
# uses: maxim-lobanov/setup-xamarin@v1
# with:
# mono-version: ${{ env.MonoVersion }}

- name: Setup NuGet.exe
uses: nuget/setup-nuget@v1
with:
nuget-version: ${{ env.NuGetVersion }}

- name: 🔨 Use .NET Core 2.1 SDK
uses: actions/[email protected]
with:
dotnet-version: '2.1.x'

- name: 🔨 Use .NET Core ${{ env.DotNetVersion2 }} SDK
uses: actions/[email protected]
with:
dotnet-version: ${{ env.DotNetVersion2 }}

- name: 🔨 Use .NET Core ${{ env.DotNetVersion }} SDK
uses: actions/[email protected]
with:
dotnet-version: ${{ env.DotNetVersion }}

- name: 🎁 dotnet tool restore
run: |
dotnet tool restore
- name: 🎁 nuget install
run: |
nuget install tools/packages.config -ExcludeVersion -OutputDirectory tools
# - name: 🍰 Run Cake
# run: |
# dotnet cake --bootstrap
# dotnet cake --configuration=Debug --verbosity=Diagnostic --target=Test --test-project="${{ matrix.testProjects }}"

- name: 🍰 Run Cake
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
uses: nick-invision/retry@v2
with:
shell: bash
timeout_minutes: 40
max_attempts: 3
retry_on: error
command: |
echo $PATH
chmod 755 ./build.sh
./build.sh --configuration Release --verbosity Verbose --target Test --test-project="$TEST_PROJECT" --use-dotnet-test
env:
TEST_PROJECT: ${{ matrix.testProjects }}

- name: 🍰 Run Cake
if: ${{ runner.os == 'Windows' }}
uses: nick-invision/retry@v2
with:
shell: powershell
timeout_minutes: 40
max_attempts: 3
retry_on: error
command: |
.\build.ps1 -configuration Release -verbosity Verbose -target Test --test-project="$ENV:TEST_PROJECT" --use-dotnet-test
env:
TEST_PROJECT: ${{ matrix.testProjects }}

- name: ⬆ Publish Logs
uses: actions/upload-artifact@v2
continue-on-error: true
if: ${{ always() }}
with:
name: 'logs - ${{ github.workflow }} ${{ matrix.os }}'
path: '${{ env.Artifacts }}/logs/'
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
matrix:
os: [ubuntu-18.04, windows-2019, macos-10.15]
testProjects:
- OmniSharp.MSBuild.Tests,OmniSharp.Roslyn.CSharp.Tests,OmniSharp.Script.Tests,OmniSharp.Stdio.Tests,OmniSharp.Http.Tests,OmniSharp.Tests,OmniSharp.Lsp.Tests
- OmniSharp.MSBuild.Tests,OmniSharp.Roslyn.CSharp.Tests,OmniSharp.Cake.Tests,OmniSharp.Script.Tests,OmniSharp.Stdio.Tests,OmniSharp.Http.Tests,OmniSharp.Tests,OmniSharp.Lsp.Tests
- OmniSharp.DotNetTest.Tests
name: 'Test'
steps:
Expand Down
98 changes: 44 additions & 54 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var installFolder = Argument("install-path",
var publishAll = HasArgument("publish-all");
var useGlobalDotNetSdk = HasArgument("use-global-dotnet-sdk");
var testProjectArgument = Argument("test-project", "");
var useDotNetTest = HasArgument("use-dotnet-test");

Log.Context = Context;

Expand Down Expand Up @@ -338,25 +339,11 @@ Task("CreateMSBuildFolder")
foreach (var library in msbuildLibraries)
{
var libraryFileName = library + ".dll";

if (!TryCopyFromFramework("netcoreapp2.1") &&
!TryCopyFromFramework("netstandard2.0") &&
!TryCopyFromFramework("net472"))
var librarySourcePath = CombinePaths(env.Folders.Tools, library, "lib", "net472", libraryFileName);
var libraryTargetPath = CombinePaths(msbuildCurrentBinTargetFolder, libraryFileName);
if (FileHelper.Exists(librarySourcePath))
{
throw new Exception($"The '{library}' library could not be found.");
}

bool TryCopyFromFramework(string frameworkVersion)
{
var librarySourcePath = CombinePaths(env.Folders.Tools, library, "lib", frameworkVersion, libraryFileName);
var libraryTargetPath = CombinePaths(msbuildCurrentBinTargetFolder, libraryFileName);
if (FileHelper.Exists(librarySourcePath))
{
FileHelper.Copy(librarySourcePath, libraryTargetPath);
return true;
}

return false;
FileHelper.Copy(librarySourcePath, libraryTargetPath);
}
}

Expand Down Expand Up @@ -418,7 +405,7 @@ Task("CreateMSBuildFolder")
}

Information("Copying NuGet SDK resolver...");
var nugetSdkResolverSourceFolder = CombinePaths(env.Folders.Tools, "Microsoft.Build.NuGetSdkResolver", "lib", "netstandard2.0");
var nugetSdkResolverSourceFolder = CombinePaths(env.Folders.Tools, "Microsoft.Build.NuGetSdkResolver", "lib", "net472");
var nugetSdkResolverTargetFolder = CombinePaths(msbuildCurrentBinTargetFolder, "SdkResolvers", "Microsoft.Build.NuGetSdkResolver");
DirectoryHelper.ForceCreate(nugetSdkResolverTargetFolder);
FileHelper.Copy(
Expand All @@ -435,7 +422,7 @@ Task("CreateMSBuildFolder")

// Copy content of NuGet.Build.Tasks
var nugetBuildTasksFolder = CombinePaths(env.Folders.Tools, "NuGet.Build.Tasks");
var nugetBuildTasksBinariesFolder = CombinePaths(nugetBuildTasksFolder, "lib", "netstandard2.0");
var nugetBuildTasksBinariesFolder = CombinePaths(nugetBuildTasksFolder, "lib", "net472");
var nugetBuildTasksTargetsFolder = CombinePaths(nugetBuildTasksFolder, "runtimes", "any", "native");

FileHelper.Copy(
Expand All @@ -458,13 +445,13 @@ Task("CreateMSBuildFolder")
var binaryName = nugetPackage + ".dll";

FileHelper.Copy(
source: CombinePaths(env.Folders.Tools, nugetPackage, "lib", "netstandard2.0", binaryName),
source: CombinePaths(env.Folders.Tools, nugetPackage, "lib", "net472", binaryName),
destination: CombinePaths(msbuildCurrentBinTargetFolder, binaryName));
}

// Copy content of Microsoft.Net.Compilers.Toolset
Information("Copying Microsoft.Net.Compilers.Toolset...");
var compilersSourceFolder = CombinePaths(env.Folders.Tools, "Microsoft.Net.Compilers.Toolset", "tasks", "netcoreapp3.1");
var compilersSourceFolder = CombinePaths(env.Folders.Tools, "Microsoft.Net.Compilers.Toolset", "tasks", "net472");
var compilersTargetFolder = CombinePaths(msbuildCurrentBinTargetFolder, "Roslyn");

DirectoryHelper.Copy(compilersSourceFolder, compilersTargetFolder);
Expand All @@ -479,16 +466,6 @@ Task("CreateMSBuildFolder")
FileHelper.Delete(CombinePaths(compilersTargetFolder, "vbc.rsp"));

FileHelper.Copy(
source: CombinePaths(env.Folders.Tools, "System.CodeDom", "lib", "netstandard2.0", "System.CodeDom.dll"),
destination: CombinePaths(msbuildCurrentBinTargetFolder, "System.CodeDom.dll"),
overwrite: true);

FileHelper.Copy(
source: CombinePaths(env.Folders.Tools, "Microsoft.NET.HostModel", "lib", "netstandard2.0", "Microsoft.NET.HostModel.dll"),
destination: CombinePaths(msbuildCurrentBinTargetFolder, "Microsoft.NET.HostModel.dll"),
overwrite: true);

FileHelper.Copy(
source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.core", "lib", "netstandard2.0", "SQLitePCLRaw.core.dll"),
destination: CombinePaths(msbuildCurrentBinTargetFolder, "SQLitePCLRaw.core.dll"),
overwrite: true);
Expand Down Expand Up @@ -642,38 +619,51 @@ Task("Test")
.IsDependentOn("PrepareTestAssets")
.Does(() =>
{
var testTargetFramework = useDotNetTest ? "net5.0" : "net472";
var testProjects = string.IsNullOrEmpty(testProjectArgument) ? buildPlan.TestProjects : testProjectArgument.Split(',');
foreach (var testProject in testProjects)
{
PrintBlankLine();
var instanceFolder = CombinePaths(env.Folders.Bin, configuration, testProject, "net472");

// Copy xunit executable to test folder to solve path errors
var xunitToolsFolder = CombinePaths(env.Folders.Tools, "xunit.runner.console", "tools", "net452");
var xunitInstancePath = CombinePaths(instanceFolder, "xunit.console.exe");
FileHelper.Copy(CombinePaths(xunitToolsFolder, "xunit.console.exe"), xunitInstancePath, overwrite: true);
FileHelper.Copy(CombinePaths(xunitToolsFolder, "xunit.runner.utility.net452.dll"), CombinePaths(instanceFolder, "xunit.runner.utility.net452.dll"), overwrite: true);
var instanceFolder = CombinePaths(env.Folders.Bin, configuration, testProject, testTargetFramework);
var targetPath = CombinePaths(instanceFolder, $"{testProject}.dll");
var logFile = CombinePaths(env.Folders.ArtifactsLogs, $"{testProject}-desktop-result.xml");
var arguments = $"\"{targetPath}\" -noshadow -parallel none -xml \"{logFile}\" -notrait category=failing";
var logFile = CombinePaths(env.Folders.ArtifactsLogs, $"{testProject}-netsdk-result.xml");

if (Platform.Current.IsWindows)
if (useDotNetTest)
{
Run(xunitInstancePath, arguments, instanceFolder)
.ExceptionOnError($"Test {testProject} failed for net472");
var arguments = $"test \"{targetPath}\" --logger \"console;verbosity=normal\" --logger \"trx;LogFileName={logFile}\" --blame-hang-timeout 60sec";

Console.WriteLine($"Executing: dotnet {arguments}");

Run("dotnet", arguments, instanceFolder)
.ExceptionOnError($"Test {testProject} failed for {testTargetFramework}");
}
else
{
// Copy the Mono-built Microsoft.Build.* binaries to the test folder.
// This is necessary to work around a Mono bug that is exasperated by xUnit.
DirectoryHelper.Copy($"{env.Folders.MSBuild}/Current/Bin", instanceFolder);

var runScript = CombinePaths(env.Folders.Mono, "run");

// By default, the run script launches OmniSharp. To launch our Mono runtime
// with xUnit rather than OmniSharp, we pass '--no-omnisharp'
Run(runScript, $"--no-omnisharp \"{xunitInstancePath}\" {arguments}", instanceFolder)
.ExceptionOnError($"Test {testProject} failed for net472");
// Copy xunit executable to test folder to solve path errors
var xunitToolsFolder = CombinePaths(env.Folders.Tools, "xunit.runner.console", "tools", "net452");
var xunitInstancePath = CombinePaths(instanceFolder, "xunit.console.exe");
FileHelper.Copy(CombinePaths(xunitToolsFolder, "xunit.console.exe"), xunitInstancePath, overwrite: true);
FileHelper.Copy(CombinePaths(xunitToolsFolder, "xunit.runner.utility.net452.dll"), CombinePaths(instanceFolder, "xunit.runner.utility.net452.dll"), overwrite: true);
var arguments = $"\"{targetPath}\" -noshadow -parallel none -xml \"{logFile}\" -notrait category=failing";

if (Platform.Current.IsWindows)
{
Run(xunitInstancePath, arguments, instanceFolder)
.ExceptionOnError($"Test {testProject} failed for {testTargetFramework}");
}
else
{
// Copy the Mono-built Microsoft.Build.* binaries to the test folder.
// This is necessary to work around a Mono bug that is exasperated by xUnit.
DirectoryHelper.Copy($"{env.Folders.MSBuild}/Current/Bin", instanceFolder);

var runScript = CombinePaths(env.Folders.Mono, "run");

// By default, the run script launches OmniSharp. To launch our Mono runtime
// with xUnit rather than OmniSharp, we pass '--no-omnisharp'
Run(runScript, $"--no-omnisharp \"{xunitInstancePath}\" {arguments}", instanceFolder)
.ExceptionOnError($"Test {testProject} failed for net472");
}
}
}
});
Expand Down
1 change: 0 additions & 1 deletion build.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"OmniSharp.Stdio.Tests",
"OmniSharp.DotNetTest.Tests",
"OmniSharp.Tests",
"OmniSharp.Cake.Tests",
"OmniSharp.Script.Tests",
"OmniSharp.Lsp.Tests"
],
Expand Down
4 changes: 3 additions & 1 deletion build/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<AspNetCorePackageVersion>2.1.1</AspNetCorePackageVersion>
<AspNetCorePackageVersion>2.2.0</AspNetCorePackageVersion>
<MicrosoftExtensionPackageVersion>5.0.0</MicrosoftExtensionPackageVersion>
<MicrosoftTestPackageVersion>16.9.4</MicrosoftTestPackageVersion>
<MSBuildPackageVersion>16.9.0</MSBuildPackageVersion>
Expand Down Expand Up @@ -52,6 +52,8 @@
<PackageReference Update="Microsoft.Extensions.Options" Version="$(MicrosoftExtensionPackageVersion)" />
<PackageReference Update="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(MicrosoftExtensionPackageVersion)" />

<PackageReference Update="Microsoft.Build.Locator" Version="1.4.1" />

<PackageReference Update="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />

<PackageReference Update="Microsoft.NET.Test.Sdk" Version="$(MicrosoftTestPackageVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum DiscoveryType
DeveloperConsole = 1,
VisualStudioSetup = 2,
Mono = 3,
UserOverride = 4
UserOverride = 4,
DotNetSdk = 5
}
}
1 change: 1 addition & 0 deletions src/OmniSharp.Cake/Extensions/ResponseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using OmniSharp.Models.V2.CodeActions;
using OmniSharp.Models.V2.CodeStructure;
using OmniSharp.Utilities;
using Range = OmniSharp.Models.V2.Range;

namespace OmniSharp.Cake.Extensions
{
Expand Down
3 changes: 2 additions & 1 deletion src/OmniSharp.Cake/Utilities/LineIndexHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using OmniSharp.Models.V2;
using OmniSharp.Roslyn.Extensions;
using OmniSharp.Utilities;
using Range = OmniSharp.Models.V2.Range;

namespace OmniSharp.Cake.Utilities
{
Expand Down Expand Up @@ -44,7 +45,7 @@ public static async Task<int> TranslateToGenerated(string fileName, int index, O
continue;
}

var lineDirectiveValue = (int) lineDirective.Line.Value - 1;
var lineDirectiveValue = (int)lineDirective.Line.Value - 1;

if (index < lineDirectiveValue)
{
Expand Down
Loading

0 comments on commit 84c3a47

Please sign in to comment.