Skip to content

Commit

Permalink
Build NuGet package (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanotti authored Aug 7, 2023
1 parent e413b56 commit 5f52507
Show file tree
Hide file tree
Showing 28 changed files with 587 additions and 59 deletions.
23 changes: 13 additions & 10 deletions .cspell/other.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
wontfix
autoinstrumentation
Bson
buildtasks
Configurator
coreutils
dylib
mktemp
myapp
opentelemetry
opentracing
OTLP
proto
protos
tracecontext
dylib
myapp
TMPDIR
mktemp
coreutils
signalfx
Bson
opentracing
Configurator
TMPDIR
tracecontext
wontfix
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/Splunk.OpenTelemetry.AutoInstrumentation/splunk-launch.sh eol=lf
49 changes: 46 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,54 @@ jobs:
name: bin-${{ matrix.base-image }}
path: bin/splunk-*.zip

build-nuget-package:
runs-on: windows-2022
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0 # fetching all, needed to correctly calculate version
- uses: actions/[email protected]
with:
dotnet-version: |
6.0.410
7.0.304
- run: ./build.cmd NuGetWorkflow
- uses: actions/[email protected]
with:
name: nuget-package
path: NuGetPackage/

test-nuget-package:
needs: build-nuget-package
strategy:
fail-fast: false
matrix:
include:
- machine: ubuntu-20.04
- machine: macos-11
runs-on: ${{ matrix.machine }}
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0 # fetching all, needed to correctly calculate version
- uses: actions/[email protected]
with:
dotnet-version: |
6.0.410
7.0.304
- name: Download NuGet Artifacts from build-nuget-package job
uses: actions/[email protected]
with:
name: nuget-package
path: NuGetPackage/
- name: Test NuGet Package
run: ./build.cmd TestNuGetPackage

create-release:
if: github.ref_type == 'tag'
name: Create GitHub release
runs-on: ubuntu-20.04
needs: [ build, container-build ]
needs: [ build, container-build, build-nuget-package, test-nuget-package ]
permissions:
contents: write
timeout-minutes: 10
Expand All @@ -123,8 +166,8 @@ jobs:
- run: cp bin-windows-2022/splunk-*.zip ./splunk-opentelemetry-dotnet-windows.zip
- run: cp bin-macos-11/splunk-*.zip ./splunk-opentelemetry-dotnet-macos.zip
- name: Calculate checksum
run: sha256sum ./*.zip ./splunk-otel-dotnet-install.sh ./Splunk.OTel.DotNet.psm1 >> checksum.txt
run: sha256sum ./*.zip ./nuget-package/*.nupkg ./splunk-otel-dotnet-install.sh ./Splunk.OTel.DotNet.psm1 >> checksum.txt
- name: Create Release
run: gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --verify-tag --draft ./*.zip ./splunk-otel-dotnet-install.sh ./Splunk.OTel.DotNet.psm1 checksum.txt
run: gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --verify-tag --draft ./*.zip ./nuget-package/*.nupkg ./splunk-otel-dotnet-install.sh ./Splunk.OTel.DotNet.psm1 checksum.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
dotnet-version: 7.0.304

- name: dotnet format
run: dotnet format ./Splunk.OpenTelemetry.AutoInstrumentation.sln --verify-no-changes
run: dotnet format ./Splunk.OpenTelemetry.AutoInstrumentation.sln --no-restore --verify-no-changes
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,5 @@ $RECYCLE.BIN/
.nuke/temp/*
.nuke/build.schema.json

NuGetPackage/
OpenTelemetryDistribution/*
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ built on top of [OpenTelemetry .NET Auto Instrumentation v1.0.0-rc.2](https://gi

### Added

- Added NuGet package `Splunk.OpenTelemetry.AutoInstrumentation`.

### Changed

- Updated [OpenTelemetry .NET Auto Instrumentation](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation):
Expand Down
18 changes: 18 additions & 0 deletions Splunk.OpenTelemetry.AutoInstrumentation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.Shared", "t
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.HttpServer", "test\test-applications\integrations\TestApplication.HttpServer\TestApplication.HttpServer.csproj", "{4E4BA0EE-4732-4FEF-BD8D-F11174063B65}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget-package", "nuget-package", "{E07BEE03-BD3C-4D31-A295-4FFEB5174FCE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.SelfContained", "test\test-applications\nuget-package\TestApplication.SelfContained\TestApplication.SelfContained.csproj", "{31F05A53-FEEC-4080-97E0-AFAC80767B86}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -142,6 +146,18 @@ Global
{4E4BA0EE-4732-4FEF-BD8D-F11174063B65}.Release|x64.Build.0 = Release|x64
{4E4BA0EE-4732-4FEF-BD8D-F11174063B65}.Release|x86.ActiveCfg = Release|x86
{4E4BA0EE-4732-4FEF-BD8D-F11174063B65}.Release|x86.Build.0 = Release|x86
{31F05A53-FEEC-4080-97E0-AFAC80767B86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31F05A53-FEEC-4080-97E0-AFAC80767B86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31F05A53-FEEC-4080-97E0-AFAC80767B86}.Debug|x64.ActiveCfg = Debug|Any CPU
{31F05A53-FEEC-4080-97E0-AFAC80767B86}.Debug|x64.Build.0 = Debug|Any CPU
{31F05A53-FEEC-4080-97E0-AFAC80767B86}.Debug|x86.ActiveCfg = Debug|Any CPU
{31F05A53-FEEC-4080-97E0-AFAC80767B86}.Debug|x86.Build.0 = Debug|Any CPU
{31F05A53-FEEC-4080-97E0-AFAC80767B86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31F05A53-FEEC-4080-97E0-AFAC80767B86}.Release|Any CPU.Build.0 = Release|Any CPU
{31F05A53-FEEC-4080-97E0-AFAC80767B86}.Release|x64.ActiveCfg = Release|Any CPU
{31F05A53-FEEC-4080-97E0-AFAC80767B86}.Release|x64.Build.0 = Release|Any CPU
{31F05A53-FEEC-4080-97E0-AFAC80767B86}.Release|x86.ActiveCfg = Release|Any CPU
{31F05A53-FEEC-4080-97E0-AFAC80767B86}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -158,6 +174,8 @@ Global
{A7C478E4-30A8-4B00-8BA2-9D7DD8384625} = {52FAD8BC-5D9B-4379-82F7-114C41B3ACEB}
{1CEC4875-ED16-4EDF-919F-5700B868C5A5} = {A7C478E4-30A8-4B00-8BA2-9D7DD8384625}
{4E4BA0EE-4732-4FEF-BD8D-F11174063B65} = {52FAD8BC-5D9B-4379-82F7-114C41B3ACEB}
{E07BEE03-BD3C-4D31-A295-4FFEB5174FCE} = {A6DD239C-1359-4B04-844B-3DAD486AA370}
{31F05A53-FEEC-4080-97E0-AFAC80767B86} = {E07BEE03-BD3C-4D31-A295-4FFEB5174FCE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B0A9D043-A771-45B1-AC87-0FFF14CD89D0}
Expand Down
62 changes: 62 additions & 0 deletions build/Build.NuGet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Runtime.InteropServices;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.MSBuild;

using static Nuke.Common.Tools.DotNet.DotNetTasks;

partial class Build : NukeBuild
{
readonly AbsolutePath NuGetPackageFolder = RootDirectory / "NuGetPackage";

Target BuildNuGetPackage => _ => _
.Executes(() =>
{
var project = Solution.AllProjects.First(project => project.Name == "Splunk.OpenTelemetry.AutoInstrumentation");
DotNetPack(s => s
.SetProject(project)
.SetConfiguration(Configuration)
.SetOutputDirectory(NuGetPackageFolder));
});


Target BuildNuGetPackageTestApplication => _ => _
.After(BuildNuGetPackage)
.Executes(() =>
{
var project = Solution.AllProjects.First(project => project.Name == "TestApplication.SelfContained");
DotNetBuild(s => s
.SetProjectFile(project)
.SetProperty("NuGetPackageVersion", VersionHelper.GetVersion())
.SetRuntime(RuntimeInformation.RuntimeIdentifier)
.SetSelfContained(true)
.SetConfiguration(Configuration)
.SetPlatform(Platform));
});

Target RunNuGetPackageIntegrationTests => _ => _
.After(BuildNuGetPackageTestApplication)
.Executes(() =>
{
var project = Solution.AllProjects.First(project => project.Name == "Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests");
DotNetTest(s => s
.SetProjectFile(project)
.SetFilter("Category=NuGetPackage")
.SetConfiguration(Configuration));
});

Target TestNuGetPackage => _ => _
.DependsOn(BuildNuGetPackageTestApplication)
.DependsOn(RunNuGetPackageIntegrationTests)
.Executes(() =>
{
});

Target NuGetWorkflow => _ => _
.DependsOn(BuildNuGetPackage)
.DependsOn(TestNuGetPackage);
}
37 changes: 27 additions & 10 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

using static Nuke.Common.Tools.DotNet.DotNetTasks;

class Build : NukeBuild
partial class Build : NukeBuild
{
private readonly static AbsolutePath TestNuGetPackageApps = NukeBuild.RootDirectory / "test" / "test-applications" / "nuget-package";

[Solution("Splunk.OpenTelemetry.AutoInstrumentation.sln")] readonly Solution Solution;
public static int Main() => Execute<Build>(x => x.Workflow);

Expand All @@ -24,10 +26,13 @@ class Build : NukeBuild

readonly AbsolutePath OpenTelemetryDistributionFolder = RootDirectory / "OpenTelemetryDistribution";

private IEnumerable<Project> AllProjectsExceptNuGetTestApps() => Solution.AllProjects.Where(project => !TestNuGetPackageApps.Contains(project.Directory));

Target Clean => _ => _
.Executes(() =>
{
DotNetClean();
NuGetPackageFolder.DeleteDirectory();
OpenTelemetryDistributionFolder.DeleteDirectory();
(RootDirectory / GetOTelAutoInstrumentationFileName()).DeleteDirectory();
});
Expand All @@ -36,7 +41,12 @@ class Build : NukeBuild
.After(Clean)
.Executes(() =>
{
DotNetRestore();
foreach (var project in AllProjectsExceptNuGetTestApps())
{
DotNetRestore(s => s
.SetProjectFile(project)
.SetPlatform(Platform));
}
});

Target DownloadAutoInstrumentationDistribution => _ => _
Expand Down Expand Up @@ -95,14 +105,14 @@ static string GetOTelAutoInstrumentationFileName()
.Executes(() =>
{
FileSystemTasks.CopyFileToDirectory(
RootDirectory / "src" / "Splunk.OpenTelemetry.AutoInstrumentation" / "bin" / Configuration /
RootDirectory / "src" / "Splunk.OpenTelemetry.AutoInstrumentation" / "bin" / ((string)Platform).ToLower() / Configuration /
"net6.0" / "Splunk.OpenTelemetry.AutoInstrumentation.dll",
OpenTelemetryDistributionFolder / "net");
if (EnvironmentInfo.IsWin)
{
FileSystemTasks.CopyFileToDirectory(
RootDirectory / "src" / "Splunk.OpenTelemetry.AutoInstrumentation" / "bin" / Configuration /
RootDirectory / "src" / "Splunk.OpenTelemetry.AutoInstrumentation" / "bin" / ((string)Platform).ToLower() / Configuration /
"net462" / "Splunk.OpenTelemetry.AutoInstrumentation.dll",
OpenTelemetryDistributionFolder / "netfx");
}
Expand Down Expand Up @@ -158,10 +168,14 @@ Copyright The OpenTelemetry Authors under Apache License Version 2.0
.After(UnpackAutoInstrumentationDistribution)
.Executes(() =>
{
DotNetBuild(s => s
.SetNoRestore(true)
.SetConfiguration(Configuration)
.SetPlatform(Platform));
foreach (var project in AllProjectsExceptNuGetTestApps())
{
DotNetBuild(s => s
.SetProjectFile(project)
.SetNoRestore(true)
.SetConfiguration(Configuration)
.SetPlatform(Platform));
}
});

Target RunUnitTests => _ => _
Expand All @@ -173,7 +187,8 @@ Copyright The OpenTelemetry Authors under Apache License Version 2.0
DotNetTest(s => s
.SetNoBuild(true)
.SetProjectFile(project)
.SetConfiguration(Configuration));
.SetConfiguration(Configuration)
.SetProperty("Platform", Platform));
});

Target RunIntegrationTests => _ => _
Expand All @@ -186,7 +201,9 @@ Copyright The OpenTelemetry Authors under Apache License Version 2.0
DotNetTest(s => s
.SetNoBuild(true)
.SetProjectFile(project)
.SetConfiguration(Configuration));
.SetFilter("Category!=NuGetPackage")
.SetConfiguration(Configuration)
.SetProperty("Platform", Platform));
});

Target Workflow => _ => _
Expand Down
24 changes: 24 additions & 0 deletions build/VersionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Reflection;

public static class VersionHelper
{
static Lazy<string> Version = new Lazy<string>(() =>
typeof(VersionHelper).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion
.Split('+')[0]);

public static string GetVersion()
{
return Version.Value;
}

public static string GetVersionWithoutSuffixes()
{
return Version.Value.Split('-')[0];
}

public static (string Major, string Minor, string Patch) GetVersionParts()
{
var split = GetVersionWithoutSuffixes().Split(".");
return (split[0], split[1], split[2]);
}
}
11 changes: 11 additions & 0 deletions build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,15 @@
<PackageReference Include="Nuke.Common" Version="7.0.2" />
</ItemGroup>

<!-- Reference MinVer so the locally built NuGet version is available when building test applications -->
<ItemGroup>
<PackageReference Include="MinVer" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>

</Project>
16 changes: 0 additions & 16 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@
<PropertyGroup>
<TargetFrameworks>net6.0;net462</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<!-- NuGet packages -->
<!-- <IsPackable>true</IsPackable>
<PackageIconUrl></PackageIconUrl>
<PackageIcon>packageIcon.png</PackageIcon>
<PackageProjectUrl>https://github.com/signalfx/splunk-otel-dotnet/</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>See release notes at https://github.com/signalfx/splunk-otel-dotnet/releases</PackageReleaseNotes>
<PackageTags>OpenTelemetry;OTEL;APM;tracing;profiling;instrumentation;Splunk</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/signalfx/splunk-otel-dotnet.git</RepositoryUrl>
<Copyright>Copyright 2022 Splunk Inc.</Copyright>
<Company>Splunk Inc.</Company>
<Authors>Splunk Inc.</Authors>
-->
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 5f52507

Please sign in to comment.