Reduce CI time (#2598)
* Cache Restore target
* Fix syntax
* Clean target should be run manually
* Add save NuGet cache action
* Fix restore for build-containers
* Legacy restore for native projects on Windows
* Merge fix
* --no-restore according if packages were cached or not
* Add condition to save the cache
* Separate Workflow target into build and test
* Dedicate one runner for Windows containers tests
* Change the literal to windows-container-tests-only
* Allow TestWorkflow to single TFM
* Separate build tests per TFM
* Remove Assert for invalid TFM
* Coalesce check to GAC install
* Put CI NuGet packages folder in a "typical" dir
* Sort integration test applications
* Revert "Sort integration test applications"
This reverts commit 63e16373f993d0515c02dc62affb162f4012c820.
* Only handle .NET Fx test apps if targeting .NET Fx
* Special case TestApplication.Wcf.Server.NetFramework
* Fix container build (no need to run the tests)
* Fix project selection
* Improve selection of skip for TestApps due to TPM
* Less work on test-build-windows-container-tests-only
* Use existing helper to the the WCF server project
* Measure docker images
* Revert "Measure docker images"
This reverts commit 3217f9c41d
.
* Dedicate runner for NativeTests
Fix test-build-native Nuke target
* Share env vars for all jobs in the workflow
* More precise version for actions/cache
* Clean up collection of test logs aka "./build_data/"
* Remove unused "log-dir"
* Improve --containers parameter description
Co-authored-by: Robert Pająk <pellared@hotmail.com>
* Change literal used to run only Windows containers tests
---------
Co-authored-by: Robert Pająk <pellared@hotmail.com>
This commit is contained in:
parent
2af4c9bc6e
commit
55ec192a11
|
@ -7,6 +7,10 @@ on:
|
|||
merge_group:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
NUGET_PACKAGES: ${{ github.workspace }}/packages
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
|
@ -14,13 +18,10 @@ jobs:
|
|||
matrix:
|
||||
include:
|
||||
- machine: windows-2022
|
||||
containers: windows
|
||||
log-dir: "/c/ProgramData/OpenTelemetry .NET AutoInstrumentation/logs"
|
||||
- machine: ubuntu-20.04
|
||||
containers: linux
|
||||
log-dir: "/var/log/opentelemetry/dotnet"
|
||||
- machine: macos-11
|
||||
containers: none
|
||||
log-dir: "/var/log/opentelemetry/dotnet"
|
||||
runs-on: ${{ matrix.machine }}
|
||||
steps:
|
||||
|
@ -30,18 +31,25 @@ jobs:
|
|||
dotnet-version: |
|
||||
6.0.408
|
||||
7.0.302
|
||||
- name: Install SQL Server (localdb)
|
||||
uses: potatoqualitee/mssqlsuite@v1.7
|
||||
if: ${{ runner.os == 'Windows' }}
|
||||
with:
|
||||
install: localdb
|
||||
- run: ./build.cmd Workflow --containers ${{ matrix.containers }}
|
||||
- name: Upload logs
|
||||
uses: actions/upload-artifact@v3.1.2
|
||||
if: always()
|
||||
- name: Check for NuGet packages cache
|
||||
uses: actions/cache@v3.3.1
|
||||
id: nuget-cache
|
||||
with:
|
||||
name: logs-${{ matrix.machine }}
|
||||
path: build_data/
|
||||
key: ${{ hashFiles('**/Directory.packages.props', './build/LibraryVersions.g.cs', '**/packages.config' ) }}
|
||||
path: ${{ env.NUGET_PACKAGES }}
|
||||
- if: ${{ steps.nuget-cache.outputs.cache-hit != 'true' }}
|
||||
name: Restore NuGet packages
|
||||
continue-on-error: false
|
||||
run: ./build.cmd Restore
|
||||
- if: ${{ steps.nuget-cache.outputs.cache-hit != 'true' }}
|
||||
name: Cache NuGet packages
|
||||
uses: actions/cache/save@v3
|
||||
with:
|
||||
key: ${{ hashFiles('**/Directory.packages.props', './build/LibraryVersions.g.cs', '**/packages.config' ) }}
|
||||
path: ${{ env.NUGET_PACKAGES }}
|
||||
|
||||
- run: ./build.cmd BuildWorkflow --no-restore ${{ steps.nuget-cache.outputs.cache-hit != 'true' }}
|
||||
|
||||
- run: brew install coreutils
|
||||
if: ${{ runner.os == 'macOS' }}
|
||||
- name: Create test directory
|
||||
|
@ -78,11 +86,6 @@ jobs:
|
|||
with:
|
||||
name: bin-${{ matrix.machine }}
|
||||
path: bin/tracer-home
|
||||
- name: Delete SQL Server MSI
|
||||
if: ${{ runner.os == 'Windows' }}
|
||||
shell: bash
|
||||
run: |
|
||||
rm SqlLocalDB.msi
|
||||
- name: Generated files unchanged
|
||||
shell: bash
|
||||
run: |
|
||||
|
@ -108,7 +111,7 @@ jobs:
|
|||
set -e
|
||||
docker build -t mybuildimage -f "./docker/${{ matrix.base-image }}.dockerfile" ./docker
|
||||
docker run -e OS_TYPE=${{ matrix.os-type }} --rm --mount type=bind,source="${GITHUB_WORKSPACE}",target=/project mybuildimage \
|
||||
./build.sh Workflow --containers none
|
||||
./build.sh BuildWorkflow
|
||||
- name: Test the Shell scripts from README.md in Docker container
|
||||
run: |
|
||||
set -e
|
||||
|
@ -136,6 +139,19 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v3.5.2
|
||||
|
||||
- uses: actions/setup-dotnet@v3.2.0
|
||||
with:
|
||||
dotnet-version: |
|
||||
6.0.408
|
||||
7.0.302
|
||||
|
||||
- name: Check for NuGet packages cache
|
||||
uses: actions/cache@v3.3.1
|
||||
id: nuget-cache
|
||||
with:
|
||||
key: ${{ hashFiles('**/Directory.packages.props', './build/LibraryVersions.g.cs', '**/packages.config' ) }}
|
||||
path: ${{ env.NUGET_PACKAGES }}
|
||||
|
||||
- name: Download Windows Artifacts from build job
|
||||
uses: actions/download-artifact@v3.0.2
|
||||
with:
|
||||
|
@ -172,6 +188,153 @@ jobs:
|
|||
name: OpenTelemetry.AutoInstrumentation.NuGet.Packages
|
||||
path: bin/nuget-artifacts/
|
||||
|
||||
test-build-managed:
|
||||
needs: build
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
test-tfm: [ net7.0, net6.0, net462 ]
|
||||
machine: [ windows-2022, ubuntu-20.04, macos-11 ]
|
||||
exclude:
|
||||
- test-tfm: net462
|
||||
machine: macos-11
|
||||
- test-tfm: net462
|
||||
machine: ubuntu-20.04
|
||||
include:
|
||||
- machine: windows-2022
|
||||
containers: none
|
||||
- machine: ubuntu-20.04
|
||||
containers: linux
|
||||
- machine: macos-11
|
||||
containers: none
|
||||
runs-on: ${{ matrix.machine }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3.5.2
|
||||
- uses: actions/setup-dotnet@v3.2.0
|
||||
with:
|
||||
dotnet-version: |
|
||||
6.0.408
|
||||
7.0.302
|
||||
- name: Check for NuGet packages cache
|
||||
uses: actions/cache@v3.3.1
|
||||
id: nuget-cache
|
||||
with:
|
||||
key: ${{ hashFiles('**/Directory.packages.props', './build/LibraryVersions.g.cs', '**/packages.config' ) }}
|
||||
path: ${{ env.NUGET_PACKAGES }}
|
||||
- name: Download Artifacts from build job
|
||||
uses: actions/download-artifact@v3.0.2
|
||||
with:
|
||||
name: bin-${{ matrix.machine }}
|
||||
path: bin/tracer-home
|
||||
- name: Install SQL Server (localdb)
|
||||
uses: potatoqualitee/mssqlsuite@v1.7
|
||||
if: ${{ runner.os == 'Windows' }}
|
||||
with:
|
||||
install: localdb
|
||||
- run: ./build.cmd --skip NativeTests --target TestWorkflow --test-target-framework ${{ matrix.test-tfm }} --containers ${{ matrix.containers }}
|
||||
- name: Upload test logs
|
||||
uses: actions/upload-artifact@v3.1.2
|
||||
if: always()
|
||||
with:
|
||||
name: test-logs-${{ matrix.machine }}-${{ matrix.test-tfm }}-containers-${{ matrix.containers }}
|
||||
path: build_data/
|
||||
- name: Delete SQL Server MSI
|
||||
if: ${{ runner.os == 'Windows' }}
|
||||
shell: bash
|
||||
run: |
|
||||
rm SqlLocalDB.msi
|
||||
|
||||
test-build-native:
|
||||
needs: build
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
machine: [ windows-2022 ]
|
||||
runs-on: ${{ matrix.machine }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3.5.2
|
||||
- uses: actions/setup-dotnet@v3.2.0
|
||||
with:
|
||||
dotnet-version: |
|
||||
6.0.408
|
||||
7.0.302
|
||||
- name: Check for NuGet packages cache
|
||||
uses: actions/cache@v3.3.1
|
||||
id: nuget-cache
|
||||
with:
|
||||
key: ${{ hashFiles('**/Directory.packages.props', './build/LibraryVersions.g.cs', '**/packages.config' ) }}
|
||||
path: ${{ env.NUGET_PACKAGES }}
|
||||
- name: Download Artifacts from build job
|
||||
uses: actions/download-artifact@v3.0.2
|
||||
with:
|
||||
name: bin-${{ matrix.machine }}
|
||||
path: bin/tracer-home
|
||||
- run: ./build.cmd NativeTests
|
||||
|
||||
test-build-windows-container-tests:
|
||||
needs: build
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- machine: windows-2022
|
||||
containers: windows-only
|
||||
runs-on: ${{ matrix.machine }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3.5.2
|
||||
- uses: actions/setup-dotnet@v3.2.0
|
||||
with:
|
||||
dotnet-version: |
|
||||
6.0.408
|
||||
7.0.302
|
||||
- name: Check for NuGet packages cache
|
||||
uses: actions/cache@v3.3.1
|
||||
id: nuget-cache
|
||||
with:
|
||||
key: ${{ hashFiles('**/Directory.packages.props', './build/LibraryVersions.g.cs', '**/packages.config' ) }}
|
||||
path: ${{ env.NUGET_PACKAGES }}
|
||||
- name: Download Artifacts from build job
|
||||
uses: actions/download-artifact@v3.0.2
|
||||
with:
|
||||
name: bin-${{ matrix.machine }}
|
||||
path: bin/tracer-home
|
||||
- name: Build artifacts required for the test (no native tests)
|
||||
run: ./build.cmd --skip RunManagedTests --target ManagedTests --containers ${{ matrix.containers }}
|
||||
- name: Run the integration tests
|
||||
run: ./build.cmd --target RunManagedIntegrationTests --containers ${{ matrix.containers }}
|
||||
- name: Upload test logs
|
||||
uses: actions/upload-artifact@v3.1.2
|
||||
if: always()
|
||||
with:
|
||||
name: test-logs-${{ matrix.machine }}-containers-${{ matrix.containers }}
|
||||
path: build_data/
|
||||
|
||||
test-build-container:
|
||||
needs: build-container
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- base-image: alpine
|
||||
os-type: linux-musl
|
||||
- base-image: centos
|
||||
os-type: linux-glibc
|
||||
runs-on: ubuntu-20.04
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- uses: actions/checkout@v3.5.2
|
||||
- name: Download Artifacts from build job
|
||||
uses: actions/download-artifact@v3.0.2
|
||||
with:
|
||||
name: bin-${{ matrix.base-image }}
|
||||
path: bin/tracer-home
|
||||
- name: Build in Docker container
|
||||
run: |
|
||||
set -e
|
||||
docker build -t mybuildimage -f "./docker/${{ matrix.base-image }}.dockerfile" ./docker
|
||||
docker run -e OS_TYPE=${{ matrix.os-type }} --rm --mount type=bind,source="${GITHUB_WORKSPACE}",target=/project mybuildimage \
|
||||
./build.sh TestWorkflow --containers none
|
||||
|
||||
test-nuget-packages:
|
||||
needs: build-nuget-packages
|
||||
strategy:
|
||||
|
@ -188,6 +351,12 @@ jobs:
|
|||
dotnet-version: |
|
||||
6.0.408
|
||||
7.0.302
|
||||
- name: Check for NuGet packages cache
|
||||
uses: actions/cache@v3.3.1
|
||||
id: nuget-cache
|
||||
with:
|
||||
key: ${{ hashFiles('**/Directory.packages.props', './build/LibraryVersions.g.cs', '**/packages.config' ) }}
|
||||
path: ${{ env.NUGET_PACKAGES }}
|
||||
|
||||
- name: Download NuGet Artifacts from build-nuget-packages job
|
||||
uses: actions/download-artifact@v3.0.2
|
||||
|
|
|
@ -142,7 +142,7 @@ partial class Build
|
|||
.SetBlameHangTimeout("5m")
|
||||
.EnableTrxLogOutput(GetResultsDirectory(nugetPackagesTestProject))
|
||||
.SetTargetPath(nugetPackagesTestProject)
|
||||
.DisableRestore()
|
||||
.SetRestore(!NoRestore)
|
||||
.RunTests()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -31,11 +31,13 @@ partial class Build
|
|||
|
||||
foreach (var project in Solution.GetNativeSrcProjects())
|
||||
{
|
||||
PerformLegacyRestoreIfNeeded(project);
|
||||
|
||||
// Can't use dotnet msbuild, as needs to use the VS version of MSBuild
|
||||
MSBuild(s => s
|
||||
.SetTargetPath(project)
|
||||
.SetConfiguration(BuildConfiguration)
|
||||
.DisableRestore()
|
||||
.SetRestore(!NoRestore)
|
||||
.SetMaxCpuCount(null)
|
||||
.CombineWith(platforms, (m, platform) => m
|
||||
.SetTargetPlatform(platform)));
|
||||
|
@ -54,11 +56,14 @@ partial class Build
|
|||
? new[] { MSBuildTargetPlatform.x64, MSBuildTargetPlatform.x86 }
|
||||
: new[] { MSBuildTargetPlatform.x86 };
|
||||
|
||||
var nativeTestProject = Solution.GetNativeTestProject();
|
||||
PerformLegacyRestoreIfNeeded(nativeTestProject);
|
||||
|
||||
// Can't use dotnet msbuild, as needs to use the VS version of MSBuild
|
||||
MSBuild(s => s
|
||||
.SetTargetPath(Solution.GetNativeTestProject())
|
||||
.SetTargetPath(nativeTestProject)
|
||||
.SetConfiguration(BuildConfiguration)
|
||||
.DisableRestore()
|
||||
.SetRestore(!NoRestore)
|
||||
.SetMaxCpuCount(null)
|
||||
.CombineWith(platforms, (m, platform) => m
|
||||
.SetTargetPlatform(platform)));
|
||||
|
@ -101,7 +106,7 @@ partial class Build
|
|||
Target PublishIisTestApplications => _ => _
|
||||
.Unlisted()
|
||||
.After(CompileManagedTests)
|
||||
.OnlyWhenStatic(() => IsWin && Containers == ContainersWindows)
|
||||
.OnlyWhenStatic(() => IsWin && (Containers == ContainersWindows || Containers == ContainersWindowsOnly))
|
||||
.Executes(() =>
|
||||
{
|
||||
var aspNetProject = Solution.GetProjectByName(Projects.Tests.Applications.AspNet);
|
||||
|
@ -115,7 +120,7 @@ partial class Build
|
|||
.SetProcessWorkingDirectory(aspNetProject.Directory)
|
||||
);
|
||||
|
||||
var wcfProject = Solution.GetProjectByName(Projects.Tests.Applications.Wcf);
|
||||
var wcfProject = Solution.GetProjectByName(Projects.Tests.Applications.WcfIis);
|
||||
BuildDockerImage(wcfProject);
|
||||
});
|
||||
|
||||
|
@ -131,6 +136,8 @@ partial class Build
|
|||
CopyFileToDirectory(sourceModulePath, localBinDirectory);
|
||||
TracerHomeDirectory.ZipTo(localTracerZip);
|
||||
|
||||
PerformLegacyRestoreIfNeeded(project);
|
||||
|
||||
MSBuild(x => x
|
||||
.SetConfiguration(BuildConfiguration)
|
||||
.SetTargetPlatform(Platform)
|
||||
|
@ -162,7 +169,11 @@ partial class Build
|
|||
.OnlyWhenStatic(() => IsWin)
|
||||
.Executes(() =>
|
||||
{
|
||||
var project = Solution.GetProjectByName(Projects.AutoInstrumentation).GetMSBuildProject();
|
||||
// The target project needs to have its NuGet packages restored prior to running the tool.
|
||||
var targetProject = Solution.GetProjectByName(Projects.AutoInstrumentation);
|
||||
DotNetRestore(s => s.SetProjectFile(targetProject));
|
||||
|
||||
var project = targetProject.GetMSBuildProject();
|
||||
var packages = Solution.Directory / "src" / "Directory.Packages.props";
|
||||
var commonExcludedAssets = Solution.Directory / "src" / "CommonExcludedAssets.props";
|
||||
|
||||
|
@ -223,7 +234,7 @@ partial class Build
|
|||
Target InstallNetFxAssembliesGAC => _ => _
|
||||
.Unlisted()
|
||||
.After(BuildTracer)
|
||||
.OnlyWhenStatic(() => IsWin)
|
||||
.OnlyWhenStatic(() => IsWin && (TestTargetFramework == TargetFramework.NET462 || TestTargetFramework == TargetFramework.NOT_SPECIFIED))
|
||||
.Executes(() => RunNetFxGacOperation("-i"));
|
||||
|
||||
/// <remarks>
|
||||
|
@ -245,4 +256,12 @@ partial class Build
|
|||
.SetConfiguration(BuildConfiguration)
|
||||
.SetApplicationArguments($"{operation} {netFxAssembliesFolder}"));
|
||||
}
|
||||
|
||||
private void PerformLegacyRestoreIfNeeded(Project project)
|
||||
{
|
||||
if (!NoRestore && project.Directory.ContainsFile("packages.config"))
|
||||
{
|
||||
RestoreLegacyNuGetPackagesConfig(new[] { project });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ using Nuke.Common.Tools.MSBuild;
|
|||
using Nuke.Common.Tools.Npm;
|
||||
using Nuke.Common.Tools.NuGet;
|
||||
using Nuke.Common.Utilities.Collections;
|
||||
using Serilog;
|
||||
using static Nuke.Common.EnvironmentInfo;
|
||||
using static Nuke.Common.IO.FileSystemTasks;
|
||||
using static Nuke.Common.Tools.DotNet.DotNetTasks;
|
||||
|
@ -70,7 +71,7 @@ partial class Build
|
|||
|
||||
if (IsWin)
|
||||
{
|
||||
projectsToRestore = projectsToRestore.Concat(Solution.GetWindowsOnlyTestApplications());
|
||||
projectsToRestore = projectsToRestore.Concat(Solution.GetNetFrameworkOnlyTestApplications());
|
||||
}
|
||||
|
||||
foreach (var project in projectsToRestore)
|
||||
|
@ -100,18 +101,9 @@ partial class Build
|
|||
// Projects using `packages.config` can't be restored via "dotnet restore", use a NuGet Task to restore these projects.
|
||||
var legacyRestoreProjects = Solution.GetNativeProjects()
|
||||
.Concat(new[] { Solution.GetProjectByName(Projects.Tests.Applications.AspNet) })
|
||||
.Concat(new[] { Solution.GetProjectByName(Projects.Tests.Applications.Wcf) });
|
||||
.Concat(new[] { Solution.GetProjectByName(Projects.Tests.Applications.WcfIis) });
|
||||
|
||||
foreach (var project in legacyRestoreProjects)
|
||||
{
|
||||
// Restore legacy projects
|
||||
NuGetTasks.NuGetRestore(s => s
|
||||
.SetTargetPath(project)
|
||||
.SetSolutionDirectory(Solution.Directory)
|
||||
.SetVerbosity(NuGetVerbosity.Normal)
|
||||
.When(!string.IsNullOrEmpty(NuGetPackagesDirectory), o =>
|
||||
o.SetPackagesDirectory(NuGetPackagesDirectory)));
|
||||
}
|
||||
RestoreLegacyNuGetPackagesConfig(legacyRestoreProjects);
|
||||
}
|
||||
}));
|
||||
|
||||
|
@ -128,7 +120,7 @@ partial class Build
|
|||
DotNetBuild(x => x
|
||||
.SetProjectFile(project)
|
||||
.SetConfiguration(BuildConfiguration)
|
||||
.EnableNoRestore());
|
||||
.SetNoRestore(NoRestore));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -140,16 +132,69 @@ partial class Build
|
|||
var testApps = Solution.GetCrossPlatformTestApplications();
|
||||
if (IsWin)
|
||||
{
|
||||
testApps = testApps.Concat(Solution.GetWindowsOnlyTestApplications());
|
||||
if (TestTargetFramework == TargetFramework.NET462 ||
|
||||
TestTargetFramework == TargetFramework.NOT_SPECIFIED)
|
||||
{
|
||||
testApps = Solution.GetNetFrameworkOnlyTestApplications().Concat(testApps);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Special case: some WCF .NET tests need a WCF server app that only builds for .NET Framework 4.6.2
|
||||
DotNetBuild(s => s
|
||||
.SetProjectFile(Solution.GetProjectByName(Projects.Tests.Applications.WcfServer))
|
||||
.SetConfiguration(BuildConfiguration)
|
||||
.SetPlatform(Platform)
|
||||
.SetNoRestore(NoRestore)
|
||||
.SetFramework(TargetFramework.NET462));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var app in testApps)
|
||||
{
|
||||
|
||||
// Special case: a test application using old packages.config needs special treatment.
|
||||
var legacyPackagesConfig = app.Directory.ContainsFile("packages.config");
|
||||
if (legacyPackagesConfig)
|
||||
{
|
||||
PerformLegacyRestoreIfNeeded(app);
|
||||
|
||||
DotNetBuild(s => s
|
||||
.SetProjectFile(app)
|
||||
.SetNoRestore(true) // project w/ packages.config can't do the restore via dotnet CLI
|
||||
.SetPlatform(Platform)
|
||||
.SetConfiguration(BuildConfiguration)
|
||||
.When(TestTargetFramework != TargetFramework.NOT_SPECIFIED,
|
||||
x => x.SetFramework(TestTargetFramework)));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
string actualTestTfm = TestTargetFramework;
|
||||
if (TestTargetFramework != TargetFramework.NOT_SPECIFIED &&
|
||||
!app.GetTargetFrameworks().Contains(actualTestTfm))
|
||||
{
|
||||
// Before skipping this app check if not a special case for .NET Framework
|
||||
actualTestTfm = null;
|
||||
if (TestTargetFramework == TargetFramework.NET462)
|
||||
{
|
||||
actualTestTfm = app.GetTargetFrameworks().FirstOrDefault(tfm => tfm.StartsWith("net4"));
|
||||
}
|
||||
|
||||
if (actualTestTfm is null)
|
||||
{
|
||||
// App doesn't support the select TFM, skip it.
|
||||
Log.Information("Skipping {0}: no suitable TFM for {1}", app.Name, TestTargetFramework);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
DotNetBuildSettings BuildTestApplication(DotNetBuildSettings x) =>
|
||||
x.SetProjectFile(app)
|
||||
.SetConfiguration(BuildConfiguration)
|
||||
.SetPlatform(Platform)
|
||||
.SetNoRestore(true);
|
||||
.SetNoRestore(NoRestore)
|
||||
.When(TestTargetFramework != TargetFramework.NOT_SPECIFIED,
|
||||
s => s.SetFramework(actualTestTfm));
|
||||
|
||||
if (LibraryVersion.Versions.TryGetValue(app.Name, out var libraryVersions))
|
||||
{
|
||||
|
@ -166,11 +211,20 @@ partial class Build
|
|||
|
||||
foreach (var project in Solution.GetManagedTestProjects())
|
||||
{
|
||||
if (TestTargetFramework != TargetFramework.NOT_SPECIFIED &&
|
||||
!project.GetTargetFrameworks().Contains(TestTargetFramework))
|
||||
{
|
||||
// Skip this test project if it doesn't support the selected test TFM.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Always AnyCPU
|
||||
DotNetBuild(x => x
|
||||
.SetProjectFile(project)
|
||||
.SetConfiguration(BuildConfiguration)
|
||||
.SetNoRestore(true));
|
||||
.SetNoRestore(NoRestore)
|
||||
.When(TestTargetFramework != TargetFramework.NOT_SPECIFIED,
|
||||
s => s.SetFramework(TestTargetFramework)));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -212,7 +266,7 @@ partial class Build
|
|||
.SetConfiguration(BuildConfiguration)
|
||||
.SetTargetPlatformAnyCPU()
|
||||
.EnableNoBuild()
|
||||
.EnableNoRestore()
|
||||
.SetNoRestore(NoRestore)
|
||||
.CombineWith(targetFrameworks, (p, framework) => p
|
||||
.SetFramework(framework)
|
||||
.SetOutput(TracerHomeDirectory / MapToFolderOutput(framework))));
|
||||
|
@ -225,7 +279,7 @@ partial class Build
|
|||
.SetConfiguration(BuildConfiguration)
|
||||
.SetTargetPlatformAnyCPU()
|
||||
.EnableNoBuild()
|
||||
.EnableNoRestore()
|
||||
.SetNoRestore(NoRestore)
|
||||
.SetFramework(TargetFramework.NETCore3_1)
|
||||
.SetOutput(TracerHomeDirectory / MapToFolderOutput(TargetFramework.NETCore3_1)));
|
||||
|
||||
|
@ -235,7 +289,7 @@ partial class Build
|
|||
.SetConfiguration(BuildConfiguration)
|
||||
.SetTargetPlatformAnyCPU()
|
||||
.EnableNoBuild()
|
||||
.EnableNoRestore()
|
||||
.SetNoRestore(NoRestore)
|
||||
.SetFramework(TargetFramework.NET6_0)
|
||||
.SetOutput(TracerHomeDirectory / MapToFolderOutput(TargetFramework.NET6_0)));
|
||||
|
||||
|
@ -244,7 +298,7 @@ partial class Build
|
|||
.SetConfiguration(BuildConfiguration)
|
||||
.SetTargetPlatformAnyCPU()
|
||||
.EnableNoBuild()
|
||||
.EnableNoRestore()
|
||||
.SetNoRestore(NoRestore)
|
||||
.SetFramework(TargetFramework.NET6_0)
|
||||
.SetOutput(TracerHomeDirectory / MapToFolderOutput(TargetFramework.NET6_0)));
|
||||
|
||||
|
@ -320,13 +374,23 @@ partial class Build
|
|||
var targetFrameworks = IsWin
|
||||
? TargetFrameworks
|
||||
: TargetFrameworks.ExceptNetFramework();
|
||||
if (TestTargetFramework != TargetFramework.NOT_SPECIFIED)
|
||||
{
|
||||
if (!targetFrameworks.Contains(TestTargetFramework))
|
||||
{
|
||||
// This test doesn't run for the selected test TFM, nothing to do.
|
||||
return;
|
||||
}
|
||||
|
||||
targetFrameworks = new[] { TestTargetFramework };
|
||||
}
|
||||
|
||||
DotNetPublish(s => s
|
||||
.SetProject(Solution.GetTestMock())
|
||||
.SetConfiguration(BuildConfiguration)
|
||||
.SetTargetPlatformAnyCPU()
|
||||
.EnableNoBuild()
|
||||
.EnableNoRestore()
|
||||
.SetNoRestore(NoRestore)
|
||||
.CombineWith(targetFrameworks, (p, framework) => p
|
||||
.SetFramework(framework)
|
||||
.SetOutput(TestsDirectory / Projects.Tests.AutoInstrumentationLoaderTests / "bin" / BuildConfiguration / "Profiler" / framework)));
|
||||
|
@ -339,7 +403,9 @@ partial class Build
|
|||
DotNetBuild(x => x
|
||||
.SetProjectFile(Solution.GetProjectByName(Projects.Mocks.AutoInstrumentationMock))
|
||||
.SetConfiguration(BuildConfiguration)
|
||||
.SetNoRestore(true)
|
||||
.SetNoRestore(NoRestore)
|
||||
.When(TestTargetFramework != TargetFramework.NOT_SPECIFIED,
|
||||
s => s.SetFramework(TestTargetFramework))
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -366,14 +432,25 @@ partial class Build
|
|||
}
|
||||
}
|
||||
|
||||
if (TestTargetFramework != TargetFramework.NOT_SPECIFIED)
|
||||
{
|
||||
unitTestProjects = unitTestProjects
|
||||
.Where(p =>
|
||||
p.GetTargetFrameworks().Contains(TestTargetFramework) &&
|
||||
(p.Name != Projects.Tests.AutoInstrumentationLoaderTests || TargetFrameworks.Contains(TestTargetFramework)))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
for (int i = 0; i < TestCount; i++)
|
||||
{
|
||||
DotNetTest(config => config
|
||||
.SetConfiguration(BuildConfiguration)
|
||||
.SetTargetPlatformAnyCPU()
|
||||
.SetFilter(TestNameFilter())
|
||||
.EnableNoRestore()
|
||||
.SetNoRestore(NoRestore)
|
||||
.EnableNoBuild()
|
||||
.When(TestTargetFramework != TargetFramework.NOT_SPECIFIED,
|
||||
x => x.SetFramework(TestTargetFramework))
|
||||
.CombineWith(unitTestProjects, (s, project) => s
|
||||
.EnableTrxLogOutput(GetResultsDirectory(project))
|
||||
.SetProjectFile(project)), degreeOfParallelism: 4);
|
||||
|
@ -392,8 +469,6 @@ partial class Build
|
|||
return;
|
||||
}
|
||||
|
||||
var frameworks = IsWin ? TestFrameworks : TestFrameworks.ExceptNetFramework();
|
||||
|
||||
for (int i = 0; i < TestCount; i++)
|
||||
{
|
||||
DotNetMSBuild(config => config
|
||||
|
@ -402,7 +477,9 @@ partial class Build
|
|||
.SetBlameHangTimeout("5m")
|
||||
.EnableTrxLogOutput(GetResultsDirectory(project))
|
||||
.SetTargetPath(project)
|
||||
.DisableRestore()
|
||||
.SetRestore(!NoRestore)
|
||||
.When(TestTargetFramework != TargetFramework.NOT_SPECIFIED,
|
||||
s => s.SetProperty("TargetFramework", TestTargetFramework.ToString()))
|
||||
.RunTests()
|
||||
);
|
||||
}
|
||||
|
@ -430,7 +507,7 @@ partial class Build
|
|||
.SetTargetPlatformAnyCPU()
|
||||
.SetProperty("TracerHomePath", TracerHomeDirectory)
|
||||
.EnableNoBuild()
|
||||
.EnableNoRestore()
|
||||
.SetNoRestore(NoRestore)
|
||||
.CombineWith(TestFrameworks.ExceptNetFramework(), (p, framework) => p
|
||||
.SetFramework(framework)
|
||||
// Additional-deps probes the directory using SemVer format.
|
||||
|
@ -568,11 +645,12 @@ partial class Build
|
|||
DotNetTest(config => config
|
||||
.SetConfiguration(BuildConfiguration)
|
||||
.SetTargetPlatformAnyCPU()
|
||||
.EnableNoRestore()
|
||||
.SetNoRestore(NoRestore)
|
||||
.EnableNoBuild()
|
||||
.EnableTrxLogOutput(GetResultsDirectory(project))
|
||||
.SetProjectFile(project)
|
||||
.SetFilter(AndFilter(TestNameFilter(), testName))
|
||||
.When(TestTargetFramework != TargetFramework.NOT_SPECIFIED, s => s.SetFramework(TestTargetFramework))
|
||||
.SetProcessEnvironmentVariable("BOOSTRAPPING_TESTS", "true"));
|
||||
}
|
||||
}
|
||||
|
@ -582,4 +660,18 @@ partial class Build
|
|||
{
|
||||
return targetFramework.ToString().StartsWith("net4") ? "netfx" : "net";
|
||||
}
|
||||
|
||||
private void RestoreLegacyNuGetPackagesConfig(IEnumerable<Project> legacyRestoreProjects)
|
||||
{
|
||||
foreach (var project in legacyRestoreProjects)
|
||||
{
|
||||
// Restore legacy projects
|
||||
NuGetTasks.NuGetRestore(s => s
|
||||
.SetTargetPath(project)
|
||||
.SetSolutionDirectory(Solution.Directory)
|
||||
.SetVerbosity(NuGetVerbosity.Normal)
|
||||
.When(!string.IsNullOrEmpty(NuGetPackagesDirectory), o =>
|
||||
o.SetPackagesDirectory(NuGetPackagesDirectory)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,13 +15,17 @@ partial class Build : NukeBuild
|
|||
[Parameter("Platform to build - x86 or x64. Default is 'x64'")]
|
||||
readonly MSBuildTargetPlatform Platform = MSBuildTargetPlatform.x64;
|
||||
|
||||
[Parameter($"Docker containers type to be used. One of '{ContainersNone}', '{ContainersLinux}', '{ContainersWindows}'. Default is '{ContainersLinux}'")]
|
||||
[Parameter($"Docker containers type to be used in tests. One of '{ContainersNone}', '{ContainersLinux}', '{ContainersWindows}', '{ContainersWindowsOnly}'. Default is '{ContainersLinux}'")]
|
||||
readonly string Containers = ContainersLinux;
|
||||
|
||||
[Parameter("TargetFramework to be tested. Default is empty, meaning all TFMs supported by each test")]
|
||||
readonly TargetFramework TestTargetFramework = TargetFramework.NOT_SPECIFIED;
|
||||
|
||||
const string ContainersNone = "none";
|
||||
const string ContainersAny = "any";
|
||||
const string ContainersLinux = "linux";
|
||||
const string ContainersWindows = "windows";
|
||||
const string ContainersWindowsOnly = "windows-only";
|
||||
|
||||
[Parameter("Test projects filter. Optional, default matches all test projects. The project will be selected if the string is part of its name.")]
|
||||
readonly string TestProject = "";
|
||||
|
@ -50,6 +54,9 @@ partial class Build : NukeBuild
|
|||
[Parameter("Version suffix added to the NuGet packages built from the project. Default is '-local.1'")]
|
||||
string NuGetVersionSuffix = "-local.1";
|
||||
|
||||
[Parameter("Do not restore the projects before building.")]
|
||||
readonly bool NoRestore;
|
||||
|
||||
Target Clean => _ => _
|
||||
.Description("Cleans all build output")
|
||||
.Executes(() =>
|
||||
|
@ -80,18 +87,26 @@ partial class Build : NukeBuild
|
|||
});
|
||||
|
||||
Target Workflow => _ => _
|
||||
.Description("GitHub workflow entry point")
|
||||
.DependsOn(Clean)
|
||||
.Description("Full workflow including build of deliverables (except NuGet packages) and run the respective tests")
|
||||
.DependsOn(BuildWorkflow)
|
||||
.DependsOn(TestWorkflow);
|
||||
|
||||
Target BuildWorkflow => _ => _
|
||||
.Description("Builds the project deliverables (except NuGet packages)")
|
||||
.DependsOn(BuildTracer)
|
||||
.DependsOn(CompileExamples)
|
||||
.DependsOn(CompileExamples);
|
||||
|
||||
Target TestWorkflow => _ => _
|
||||
.Description("Builds and run the tests against the local deliverables (except NuGet packages)")
|
||||
.After(BuildWorkflow)
|
||||
.DependsOn(NativeTests)
|
||||
.DependsOn(ManagedTests);
|
||||
|
||||
Target BuildTracer => _ => _
|
||||
.Description("Builds the native and managed src, and publishes the tracer home directory")
|
||||
.After(Clean)
|
||||
.After(Restore)
|
||||
.DependsOn(CreateRequiredDirectories)
|
||||
.DependsOn(Restore)
|
||||
.DependsOn(GenerateNetFxTransientDependencies)
|
||||
.DependsOn(CompileManagedSrc)
|
||||
.DependsOn(PublishManagedProfiler)
|
||||
|
@ -131,8 +146,10 @@ partial class Build : NukeBuild
|
|||
return "Containers!=Windows";
|
||||
case ContainersWindows:
|
||||
return "Containers!=Linux";
|
||||
case ContainersWindowsOnly:
|
||||
return "Containers=Windows";
|
||||
case ContainersAny:
|
||||
throw new InvalidOperationException($"Containers={ContainersAny} is not supported directly. Specify concrete value, either Containers={ContainersLinux} or Containers={ContainersWindows}.");
|
||||
throw new InvalidOperationException($"Containers={ContainersAny} is not supported directly. Specify concrete value, see help for options.");
|
||||
default:
|
||||
throw new InvalidOperationException($"Containers={Containers} is not supported");
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ public static class Projects
|
|||
public static class Applications
|
||||
{
|
||||
public const string AspNet = "TestApplication.AspNet.NetFramework";
|
||||
public const string Wcf = "TestApplication.Wcf.Server.IIS.NetFramework";
|
||||
public const string WcfIis = "TestApplication.Wcf.Server.IIS.NetFramework";
|
||||
public const string WcfServer = "TestApplication.Wcf.Server.NetFramework";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ public static class ProjectsHelper
|
|||
return solution.GetProjectByName(Projects.Mocks.AutoInstrumentationMock);
|
||||
}
|
||||
|
||||
public static IEnumerable<Project> GetWindowsOnlyTestApplications(this Solution solution)
|
||||
public static IEnumerable<Project> GetNetFrameworkOnlyTestApplications(this Solution solution)
|
||||
{
|
||||
return solution
|
||||
.GetIntegrationTestApplications()
|
||||
|
|
|
@ -3,10 +3,12 @@ using System.Globalization;
|
|||
using System.Reflection;
|
||||
using Nuke.Common;
|
||||
using Nuke.Common.Tooling;
|
||||
using Serilog;
|
||||
|
||||
[TypeConverter(typeof(TargetFrameworkTypeConverter))]
|
||||
public class TargetFramework : Enumeration
|
||||
{
|
||||
public static readonly TargetFramework NOT_SPECIFIED = new() { Value = string.Empty };
|
||||
public static readonly TargetFramework NET462 = new() { Value = "net462" };
|
||||
public static readonly TargetFramework NETCore3_1 = new() { Value = "netcoreapp3.1" };
|
||||
public static readonly TargetFramework NET6_0 = new() { Value = "net6.0" };
|
||||
|
@ -25,6 +27,7 @@ public class TargetFramework : Enumeration
|
|||
{
|
||||
private static readonly TargetFramework[] AllTargetFrameworks = typeof(TargetFramework)
|
||||
.GetFields(BindingFlags.Static | BindingFlags.Public)
|
||||
.Where(x => x.FieldType == typeof(TargetFramework))
|
||||
.Select(x => x.GetValue(null))
|
||||
.Cast<TargetFramework>()
|
||||
.ToArray();
|
||||
|
@ -36,8 +39,13 @@ public class TargetFramework : Enumeration
|
|||
var matchingFields = AllTargetFrameworks
|
||||
.Where(x => string.Equals(x.Value, stringValue, StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
Assert.True(matchingFields.Count == 1);
|
||||
return matchingFields.Single();
|
||||
if (matchingFields.Count == 1)
|
||||
{
|
||||
return matchingFields.Single();
|
||||
}
|
||||
|
||||
Log.Warning($"Invalid target framework '{stringValue}' falling back to the default value.");
|
||||
return NOT_SPECIFIED;
|
||||
}
|
||||
|
||||
return base.ConvertFrom(context, culture, value);
|
||||
|
|
Loading…
Reference in New Issue