Skip to content

Commit

Permalink
Add NuGet packages (#2286)
Browse files Browse the repository at this point in the history
* Add NuGet packages

* Fix link to nuget.config

* Apply dotnet-format fixes

* Consistent emphasis-style on README.md

* Update docs/README.md

Co-authored-by: Fabrizio Ferri-Benedetti <[email protected]>

* Update docs/README.md

Co-authored-by: Fabrizio Ferri-Benedetti <[email protected]>

* Update docs/internal/using-the-nuget-packages.md

Co-authored-by: Fabrizio Ferri-Benedetti <[email protected]>

* Update docs/internal/using-the-nuget-packages.md

Co-authored-by: Fabrizio Ferri-Benedetti <[email protected]>

* Update docs/internal/using-the-nuget-packages.md

Co-authored-by: Fabrizio Ferri-Benedetti <[email protected]>

* Update docs/internal/using-the-nuget-packages.md

Co-authored-by: Fabrizio Ferri-Benedetti <[email protected]>

* Update docs/internal/using-the-nuget-packages.md

Co-authored-by: Fabrizio Ferri-Benedetti <[email protected]>

* Update docs/internal/using-the-nuget-packages.md

Co-authored-by: Fabrizio Ferri-Benedetti <[email protected]>

* Update docs/internal/using-the-nuget-packages.md

Co-authored-by: Fabrizio Ferri-Benedetti <[email protected]>

* Reduce the default timeout for tests going to the web

* Add instructions on how to setup bin/ci-artifacts

* Fix doc formatting

* PR review suggestion

* Use same as style as PR 2287

---------

Co-authored-by: Fabrizio Ferri-Benedetti <[email protected]>
Co-authored-by: Rajkumar Rangaraj <[email protected]>
  • Loading branch information
3 people authored Mar 11, 2023
1 parent 161574c commit 888e2cd
Show file tree
Hide file tree
Showing 37 changed files with 1,121 additions and 89 deletions.
55 changes: 41 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,44 +129,71 @@ jobs:
if: (${{ job.status }} != 'cancelled')
continue-on-error: true

pack:
needs: build
build-nuget-packages:
needs: [ build, build-container ]

runs-on: ubuntu-20.04
runs-on: windows-2022
steps:
- uses: actions/[email protected]
- uses: nuget/[email protected]

- name: Download Windows Artifacts from build job
uses: actions/[email protected]
with:
name: bin-windows-2022
path: nuget/bin-windows
path: bin/ci-artifacts/bin-windows-2022

- name: Download CentOS Artifacts from build job
uses: actions/[email protected]
with:
name: bin-centos
path: nuget/bin-linux-glibc
path: bin/ci-artifacts/bin-centos

- name: Download Alpine Artifacts from build job
uses: actions/[email protected]
with:
name: bin-alpine
path: nuget/bin-linux-musl
path: bin/ci-artifacts/bin-alpine

- name: Download Mac-OS Artifacts from build job
uses: actions/[email protected]
with:
name: bin-macos-11
path: nuget/bin-macos
path: bin/ci-artifacts/bin-macos-11

- name: Build NuGet Runtime Packages
run: ./build.cmd BuildNuGetPackages

- name: Build NuGet package
run: nuget pack OpenTelemetry.AutoInstrumentation.nuspec -Properties NoWarn=NU5100,NU5123,NU5128
working-directory: nuget
- name: Test NuGet Packages
run: ./build.cmd TestNuGetPackages

- name: Upload Nuget
- name: Upload Nuget Artifacts
uses: actions/[email protected]
with:
name: OpenTelemetry.AutoInstrumentation.Nuget
path: nuget/*.nupkg
name: OpenTelemetry.AutoInstrumentation.NuGet.Packages
path: bin/nuget-artifacts/

test-nuget-packages:
needs: build-nuget-packages
strategy:
fail-fast: false
matrix:
include:
- machine: ubuntu-20.04
- machine: macos-11
runs-on: ${{ matrix.machine }}
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
dotnet-version: |
6.0.x
7.0.x
- name: Download NuGet Artifacts from build-nuget-packages job
uses: actions/[email protected]
with:
name: OpenTelemetry.AutoInstrumentation.NuGet.Packages
path: bin/nuget-artifacts/

- name: Test NuGet Packages
run: ./build.cmd TestNuGetPackages
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ blog/
# exception to the ignore rule
!/**/.gitkeep

# ignore artifacts downloaded to build OpenTelemetry.AutoInstrumentation.Runtime package
nuget/OpenTelemetry.AutoInstrumentation.Runtime.Native/runtimes/

# profiler build files
src/OpenTelemetry.AutoInstrumentation.Native/build/
src/OpenTelemetry.AutoInstrumentation.Native/deps/
Expand Down
40 changes: 40 additions & 0 deletions OpenTelemetry.AutoInstrumentation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GacInstallTool", "tools\Gac
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryVersionsGenerator", "tools\LibraryVersionsGenerator\LibraryVersionsGenerator.csproj", "{119F5BAD-6A58-40EA-8E0A-666CADE3CAF8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{98868FAF-0854-4E66-8306-3EFA7F2E9A45}"
ProjectSection(SolutionItems) = preProject
nuget\OpenTelemetry.AutoInstrumentation.Dependencies\OpenTelemetry.AutoInstrumentation.Dependencies.nuspec = nuget\OpenTelemetry.AutoInstrumentation.Dependencies\OpenTelemetry.AutoInstrumentation.Dependencies.nuspec
nuget\OpenTelemetry.AutoInstrumentation\OpenTelemetry.AutoInstrumentation.nuspec = nuget\OpenTelemetry.AutoInstrumentation\OpenTelemetry.AutoInstrumentation.nuspec
nuget\OpenTelemetry.AutoInstrumentation.Runtime.Native\OpenTelemetry.AutoInstrumentation.Runtime.Native.nuspec = nuget\OpenTelemetry.AutoInstrumentation.Runtime.Native\OpenTelemetry.AutoInstrumentation.Runtime.Native.nuspec
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGetPackagesTests", "test\NuGetPackagesTests\NuGetPackagesTests.csproj", "{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget-packages", "nuget-packages", "{2EF2F7CE-E56F-4B81-A5A5-277693529D43}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication.SelfContained", "test\test-applications\nuget-packages\TestApplication.SelfContained\TestApplication.SelfContained.csproj", "{25ED93D0-A70C-4A07-84D9-EF94115259C9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -798,6 +811,30 @@ Global
{119F5BAD-6A58-40EA-8E0A-666CADE3CAF8}.Release|x64.Build.0 = Release|Any CPU
{119F5BAD-6A58-40EA-8E0A-666CADE3CAF8}.Release|x86.ActiveCfg = Release|Any CPU
{119F5BAD-6A58-40EA-8E0A-666CADE3CAF8}.Release|x86.Build.0 = Release|Any CPU
{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}.Debug|x64.ActiveCfg = Debug|Any CPU
{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}.Debug|x64.Build.0 = Debug|Any CPU
{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}.Debug|x86.ActiveCfg = Debug|Any CPU
{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}.Debug|x86.Build.0 = Debug|Any CPU
{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}.Release|Any CPU.Build.0 = Release|Any CPU
{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}.Release|x64.ActiveCfg = Release|Any CPU
{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}.Release|x64.Build.0 = Release|Any CPU
{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}.Release|x86.ActiveCfg = Release|Any CPU
{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}.Release|x86.Build.0 = Release|Any CPU
{25ED93D0-A70C-4A07-84D9-EF94115259C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{25ED93D0-A70C-4A07-84D9-EF94115259C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25ED93D0-A70C-4A07-84D9-EF94115259C9}.Debug|x64.ActiveCfg = Debug|Any CPU
{25ED93D0-A70C-4A07-84D9-EF94115259C9}.Debug|x64.Build.0 = Debug|Any CPU
{25ED93D0-A70C-4A07-84D9-EF94115259C9}.Debug|x86.ActiveCfg = Debug|Any CPU
{25ED93D0-A70C-4A07-84D9-EF94115259C9}.Debug|x86.Build.0 = Debug|Any CPU
{25ED93D0-A70C-4A07-84D9-EF94115259C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25ED93D0-A70C-4A07-84D9-EF94115259C9}.Release|Any CPU.Build.0 = Release|Any CPU
{25ED93D0-A70C-4A07-84D9-EF94115259C9}.Release|x64.ActiveCfg = Release|Any CPU
{25ED93D0-A70C-4A07-84D9-EF94115259C9}.Release|x64.Build.0 = Release|Any CPU
{25ED93D0-A70C-4A07-84D9-EF94115259C9}.Release|x86.ActiveCfg = Release|Any CPU
{25ED93D0-A70C-4A07-84D9-EF94115259C9}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -859,6 +896,9 @@ Global
{D6181786-C7F1-400D-A678-8DC300485429} = {00F4C92D-6652-4BD8-A334-B35D3E711BE6}
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD} = {00F4C92D-6652-4BD8-A334-B35D3E711BE6}
{119F5BAD-6A58-40EA-8E0A-666CADE3CAF8} = {00F4C92D-6652-4BD8-A334-B35D3E711BE6}
{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0} = {5C915382-C886-457D-8641-9E766D8E5A17}
{2EF2F7CE-E56F-4B81-A5A5-277693529D43} = {91A299AD-6C09-4B7F-BD8B-A705D9BFC672}
{25ED93D0-A70C-4A07-84D9-EF94115259C9} = {2EF2F7CE-E56F-4B81-A5A5-277693529D43}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {160A1D00-1F5B-40F8-A155-621B4459D78F}
Expand Down
163 changes: 163 additions & 0 deletions build/Build.NuGet.Steps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
using System.Runtime.InteropServices;
using Extensions;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.NuGet;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;

partial class Build
{
AbsolutePath NuGetArtifactsDirectory => NuGetArtifacts ?? (OutputDirectory / "nuget-artifacts");

Target BuildNuGetPackages => _ => _
.Description(
"Builds the NuGet packages of the project assuming that any necessary build artifacts were already downloaded.")
.DependsOn(BuildManagedSrcNuGetPackages)
.DependsOn(CopyIntegrationsJsonForNuGetPackage)
.DependsOn(SetupRuntimeNativeFolderForNuGetPackage)
.DependsOn(BuildNuSpecNuGetPackages);

Target TestNuGetPackages => _ => _
.Description(
"Test the NuGet packages of the project assuming that the packages are available at bin/nuget-artifacts.")
.DependsOn(BuildNuGetPackagesTests)
.DependsOn(BuildNuGetPackagesTestApplications)
.DependsOn(RunNuGetPackagesTests);

Target BuildManagedSrcNuGetPackages => _ => _
.Description("Build the NuGet packages that are generated directly from src/**/*.csproj files")
.Executes(() =>
{
foreach (var project in Solution.GetManagedSrcProjects().Where(p => !p.Name.EndsWith("AdditionalDeps")))
{
DotNetPack(x => x
.SetProject(project)
.SetConfiguration(BuildConfiguration)
.SetVersionSuffix(NuGetVersionSuffix)
.SetOutputDirectory(NuGetArtifactsDirectory));
}
});

Target CopyIntegrationsJsonForNuGetPackage => _ => _
.Unlisted()
.Executes(() =>
{
var source = RootDirectory / "integrations.json";
var dest = RootDirectory / "nuget" / "OpenTelemetry.AutoInstrumentation" /
"contentFiles" / "any" / "any";
CopyFileToDirectory(source, dest, FileExistsPolicy.Overwrite);
});

Target SetupRuntimeNativeFolderForNuGetPackage => _ => _
.Unlisted()
.Description("Setup the \"runtimes/{platform}-{architecture}/native\" folders under \"nuget/OpenTelemetry.AutoInstrumentation.Runtime.Native\".")
.Executes(() =>
{
const string ciArtifactsDirectory = "bin/ci-artifacts";
const string baseRuntimeNativePath = "./nuget/OpenTelemetry.AutoInstrumentation.Runtime.Native/";
var requiredArtifacts = new string[]
{
"bin-alpine/linux-musl-x64",
"bin-centos/linux-x64",
"bin-macos-11/osx-x64",
"bin-windows-2022/win-x64",
"bin-windows-2022/win-x86"
};
foreach (var artifactFolder in requiredArtifacts)
{
var sourcePath = Path.Combine(ciArtifactsDirectory, artifactFolder);
var platformAndArchitecture = Path.GetFileName(artifactFolder);
var destinationPath =
Path.Combine(baseRuntimeNativePath, "runtimes", platformAndArchitecture, "native");
DeleteDirectory(destinationPath);
CopyDirectoryRecursively(sourcePath, destinationPath);
}
});

Target BuildNuSpecNuGetPackages => _ => _
.Description("Build the NuGet packages specified by nuget/**/*.nuspec projects.")
.After(CopyIntegrationsJsonForNuGetPackage)
.After(SetupRuntimeNativeFolderForNuGetPackage)
.Executes(() =>
{
// .nuspec files don't support .props or another way to share properties.
// To avoid repeating these values on all .nuspec files they are going to
// be passed as properties.
// Keeping common values here and using them as properties
var nuspecCommonProperties = new Dictionary<string, object>
{
{ "NoWarn", "NU5128" },
{ "NuGetLicense", "Apache-2.0" },
{ "NuGetPackageVersion", $"{NuGetBaseVersionNumber}{NuGetVersionSuffix}" },
{ "NuGetRequiredLicenseAcceptance", "true" },
{ "OpenTelemetryAuthors", "OpenTelemetry Authors" }
};
var nuspecSolutionFolder = Solution.GetSolutionFolder("nuget")
?? throw new InvalidOperationException("Couldn't find the expected \"nuget\" solution folder.");
var nuspecProjects = nuspecSolutionFolder.Items.Keys.ToArray();
foreach (var nuspecProject in nuspecProjects)
{
NuGetTasks.NuGetPack(s => s
.SetTargetPath(nuspecProject)
.SetConfiguration(BuildConfiguration)
.SetProperties(nuspecCommonProperties)
.SetOutputDirectory(NuGetArtifactsDirectory));
}
});

Target BuildNuGetPackagesTests => _ => _
.Description("Builds the NuGetPackagesTests project")
.Executes(() =>
{
var nugetPackagesTestProject = Solution.GetProject("NuGetPackagesTests");
DotNetBuild(s => s
.SetProjectFile(nugetPackagesTestProject)
.SetConfiguration(BuildConfiguration));
});

Target BuildNuGetPackagesTestApplications => _ => _
.Description("Builds the TestApplications.* used by the NuGetPackagesTests")
.Executes(() =>
{
foreach (var packagesTestApplicationProject in Solution.GetNuGetPackagesTestApplications())
{
// Unlike the integration apps these require a restore step.
DotNetBuild(s => s
.SetProjectFile(packagesTestApplicationProject)
.SetProperty("NuGetPackageVersion", $"{NuGetBaseVersionNumber}{NuGetVersionSuffix}")
.SetRuntime(RuntimeInformation.RuntimeIdentifier)
.SetConfiguration(BuildConfiguration)
.SetPlatform(Platform));
}
});

Target RunNuGetPackagesTests => _ => _
.Description("Run the NuGetPackagesTests.")
.After(BuildNuGetPackagesTests)
.After(BuildNuGetPackagesTestApplications)
.Executes(() =>
{
var nugetPackagesTestProject = Solution.GetProject("NuGetPackagesTests");
for (var i = 0; i < TestCount; i++)
{
DotNetMSBuild(config => config
.SetConfiguration(BuildConfiguration)
.SetFilter(AndFilter(TestNameFilter(), ContainersFilter()))
.SetBlameHangTimeout("5m")
.EnableTrxLogOutput(GetResultsDirectory(nugetPackagesTestProject))
.SetTargetPath(nugetPackagesTestProject)
.DisableRestore()
.RunTests()
);
}
});
}
9 changes: 4 additions & 5 deletions build/Build.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ partial class Build
AbsolutePath TestsDirectory => RootDirectory / "test";

AbsolutePath TracerHomeDirectory => TracerHome ?? (OutputDirectory / "tracer-home");
AbsolutePath ArtifactsDirectory => Artifacts ?? (OutputDirectory / "artifacts");
AbsolutePath BuildDataDirectory => RootDirectory / "build_data";
AbsolutePath ProfilerTestLogs => BuildDataDirectory / "profiler-logs";
AbsolutePath AdditionalDepsDirectory => TracerHomeDirectory / "AdditionalDeps";
Expand Down Expand Up @@ -55,7 +54,7 @@ partial class Build
.Executes(() =>
{
EnsureExistingDirectory(TracerHomeDirectory);
EnsureExistingDirectory(ArtifactsDirectory);
EnsureExistingDirectory(NuGetArtifactsDirectory);
EnsureExistingDirectory(BuildDataDirectory);
EnsureExistingDirectory(ProfilerTestLogs);
});
Expand All @@ -79,7 +78,7 @@ DotNetRestoreSettings Restore(DotNetRestoreSettings s) =>
.SetVerbosity(DotNetVerbosity.Normal)
.SetProperty("configuration", BuildConfiguration.ToString())
.SetPlatform(Platform)
.When(!string.IsNullOrEmpty(NugetPackageDirectory), o => o.SetPackageDirectory(NugetPackageDirectory));
.When(!string.IsNullOrEmpty(NuGetPackagesDirectory), o => o.SetPackageDirectory(NuGetPackagesDirectory));
if (LibraryVersion.Versions.TryGetValue(project.Name, out var libraryVersions))
{
Expand Down Expand Up @@ -107,8 +106,8 @@ DotNetRestoreSettings Restore(DotNetRestoreSettings s) =>
.SetTargetPath(project)
.SetSolutionDirectory(Solution.Directory)
.SetVerbosity(NuGetVerbosity.Normal)
.When(!string.IsNullOrEmpty(NugetPackageDirectory), o =>
o.SetPackagesDirectory(NugetPackageDirectory)));
.When(!string.IsNullOrEmpty(NuGetPackagesDirectory), o =>
o.SetPackagesDirectory(NuGetPackagesDirectory)));
}
}
}));
Expand Down
17 changes: 12 additions & 5 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,18 @@ partial class Build : NukeBuild

[Parameter("The location to create the tracer home directory. Default is './bin/tracer-home'")]
readonly AbsolutePath TracerHome;
[Parameter("The location to place NuGet packages and other packages. Default is './bin/artifacts'")]
readonly AbsolutePath Artifacts;

[Parameter("The location to restore Nuget packages. Optional")]
readonly AbsolutePath NugetPackageDirectory;
[Parameter("The location to place the NuGet packages built from the project. Default is './bin/nuget-artifacts'")]
readonly AbsolutePath NuGetArtifacts;

[Parameter("The location to restore NuGet packages. Optional")]
readonly AbsolutePath NuGetPackagesDirectory;

[Parameter("Version number of the NuGet packages built from the project. Default is '0.6.0'")]
string NuGetBaseVersionNumber = "0.6.0";

[Parameter("Version suffix added to the NuGet packages built from the project. Default is '-local.1'")]
string NuGetVersionSuffix = "-local.1";

Target Clean => _ => _
.Description("Cleans all build output")
Expand All @@ -57,7 +64,7 @@ partial class Build : NukeBuild
TestsDirectory.GlobDirectories("**/bin", "**/obj").ForEach(x => DeleteDirectory(x));
EnsureCleanDirectory(OutputDirectory);
EnsureCleanDirectory(TracerHomeDirectory);
EnsureCleanDirectory(ArtifactsDirectory);
EnsureCleanDirectory(NuGetArtifactsDirectory);
EnsureCleanDirectory(NativeProfilerProject.Directory / "build");
EnsureCleanDirectory(NativeProfilerProject.Directory / "deps");
EnsureCleanDirectory(BuildDataDirectory);
Expand Down
Loading

0 comments on commit 888e2cd

Please sign in to comment.