Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ jobs:
timeout-minutes: 60
steps:
- uses: actions/checkout@v3.5.3
with:
fetch-depth: 0 # fetching all, needed to correctly calculate version
- 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 BuildWorkflow
/bin/sh -c 'git config --global --add safe.directory /project && ./build.sh BuildWorkflow'
- name: Test the Shell scripts from README.md in Docker container
run: |
set -e
Expand Down
21 changes: 2 additions & 19 deletions .github/workflows/build-nuget-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ jobs:
runs-on: windows-2022
steps:
- uses: actions/checkout@v3.5.3

with:
fetch-depth: 0 # fetching all, needed to correctly calculate version
- uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: |
Expand Down Expand Up @@ -62,30 +63,12 @@ jobs:
name: bin-macos-11
path: bin/ci-artifacts/bin-macos-11

- name: Set NUKE_NUGET_VERSION_SUFFIX for build triggered by 'tag'
id: set-nuget-version-suffix-from-tag
if: github.ref_type == 'tag'
shell: bash
run: echo "NUKE_NUGET_VERSION_SUFFIX=$(echo ${{ github.ref_name }} | sed -n 's/.*v[0-9]\+\.[0-9]\+\.[0-9]\+\(.*\)/\1/p')" >> "$GITHUB_ENV"

- name: Set NUKE_NUGET_VERSION_SUFFIX for regular build
id: set-nuget-version-suffix-from-run-id
if: github.ref_type != 'tag'
shell: bash
# See https://semver.org/spec/v2.0.0.html#spec-item-9 for valid version suffix
run: echo "NUKE_NUGET_VERSION_SUFFIX=-run-id.${{ github.run_id }}" >> "$GITHUB_ENV"

- name: Build NuGet packages
run: ./build.cmd BuildNuGetPackages

- name: Test NuGet Packages
run: ./build.cmd TestNuGetPackages

- name: Set NuGet Version Suffix
id: set-nuget-version-suffix
shell: bash
run: echo "suffix=${{ env.NUKE_NUGET_VERSION_SUFFIX }}" >> $GITHUB_OUTPUT

- name: Upload Nuget Artifacts
uses: actions/upload-artifact@v3.1.2
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
runs-on: ${{ matrix.machine }}
steps:
- uses: actions/checkout@v3.5.3
with:
fetch-depth: 0 # fetching all, needed to correctly calculate version
- uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: |
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jobs:
runs-on: ${{ matrix.machine }}
steps:
- uses: actions/checkout@v3.5.3
with:
fetch-depth: 0 # fetching all, needed to correctly calculate version
- uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: |
Expand Down Expand Up @@ -87,6 +89,8 @@ jobs:
runs-on: ${{ matrix.machine }}
steps:
- uses: actions/checkout@v3.5.3
with:
fetch-depth: 0 # fetching all, needed to correctly calculate version
- uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: |
Expand Down Expand Up @@ -116,6 +120,8 @@ jobs:
runs-on: ${{ matrix.machine }}
steps:
- uses: actions/checkout@v3.5.3
with:
fetch-depth: 0 # fetching all, needed to correctly calculate version
- uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: |
Expand Down Expand Up @@ -162,6 +168,8 @@ jobs:
timeout-minutes: 60
steps:
- uses: actions/checkout@v3.5.3
with:
fetch-depth: 0 # fetching all, needed to correctly calculate version
- name: Download Artifacts from build job
uses: actions/download-artifact@v3.0.2
with:
Expand All @@ -172,7 +180,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 TestWorkflow --containers none
/bin/sh -c 'git config --global --add safe.directory /project && ./build.sh TestWorkflow --containers none'

test-nuget-packages:
needs: build-nuget-packages
Expand All @@ -185,6 +193,8 @@ jobs:
runs-on: ${{ matrix.machine }}
steps:
- uses: actions/checkout@v3.5.3
with:
fetch-depth: 0 # fetching all, needed to correctly calculate version
- uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: |
Expand All @@ -203,9 +213,5 @@ jobs:
name: bin-nuget-packages
path: bin/nuget-artifacts/

- name: Set NUKE_NUGET_VERSION_SUFFIX
id: set-nuget-version-suffix
run: echo "NUKE_NUGET_VERSION_SUFFIX=${{ needs.build-nuget-packages.outputs.nuget-version-suffix }}" >> "$GITHUB_ENV"

- name: Test NuGet Packages
run: ./build.cmd TestNuGetPackages
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="MinVer" Version="4.3.0" />
<PackageVersion Include="OpenTelemetry" Version="1.5.1" />
<PackageVersion Include="OpenTelemetry.Api" Version="1.5.1" />
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.5.1" />
Expand Down
14 changes: 13 additions & 1 deletion build/AssemblyRedirectionSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ private static string GenerateSourceContents(SortedDictionary<string, AssemblyNa
#include "cor_profiler.h"

#ifdef _WIN32
#define STR(Z1) #Z1
#define AUTO_MAJOR STR(OTEL_AUTO_VERSION_MAJOR)

namespace trace
{
void CorProfiler::InitNetFxAssemblyRedirectsMap()
{
const USHORT auto_major = atoi(AUTO_MAJOR);

assembly_version_redirect_map_.insert({
{{GenerateEntries(assemblies)}}
});
Expand All @@ -73,7 +78,14 @@ private static string GenerateEntries(SortedDictionary<string, AssemblyNameDefin
foreach (var kvp in assemblies)
{
var v = kvp.Value.Version!;
sb.AppendLine($" {{ L\"{kvp.Key}\", {{{v.Major}, {v.Minor}, {v.Build}, {v.Revision}}} }},");
if (kvp.Key != "OpenTelemetry.AutoInstrumentation")
{
sb.AppendLine($" {{ L\"{kvp.Key}\", {{{v.Major}, {v.Minor}, {v.Build}, {v.Revision}}} }},");
}
else
{
sb.AppendLine($" {{ L\"{kvp.Key}\", {{auto_major, 0, 0, 0}} }},");
}
}

return sb.ToString()
Expand Down
8 changes: 3 additions & 5 deletions build/Build.NuGet.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Extensions;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.NuGet;
using Nuke.Common.Utilities.Collections;
Expand Down Expand Up @@ -37,8 +36,7 @@ partial class Build
DotNetPack(x => x
.SetProject(project)
.SetConfiguration(BuildConfiguration)
.SetOutputDirectory(NuGetArtifactsDirectory)
.When(!string.IsNullOrWhiteSpace(NuGetVersionSuffix), s => s.SetVersionSuffix(NuGetVersionSuffix)));
.SetOutputDirectory(NuGetArtifactsDirectory));
}
});

Expand Down Expand Up @@ -117,7 +115,7 @@ partial class Build
// NU5128: "Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location."
{ "NoWarn", "NU5104;NU5128" },
{ "NuGetLicense", "Apache-2.0" },
{ "NuGetPackageVersion", $"{NuGetBaseVersionNumber}{NuGetVersionSuffix}" },
{ "NuGetPackageVersion", VersionHelper.GetVersion() },
{ "NuGetRequiredLicenseAcceptance", "true" },
{ "OpenTelemetryAuthors", "OpenTelemetry Authors" }
};
Expand Down Expand Up @@ -155,7 +153,7 @@ partial class Build
// Unlike the integration apps these require a restore step.
DotNetBuild(s => s
.SetProjectFile(packagesTestApplicationProject)
.SetProperty("NuGetPackageVersion", $"{NuGetBaseVersionNumber}{NuGetVersionSuffix}")
.SetProperty("NuGetPackageVersion", VersionHelper.GetVersion())
.SetRuntime(RuntimeInformation.RuntimeIdentifier)
.SetConfiguration(BuildConfiguration)
.SetPlatform(Platform));
Expand Down
5 changes: 3 additions & 2 deletions build/Build.Steps.Linux.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Serilog;
using static Nuke.Common.EnvironmentInfo;
using static Nuke.Common.IO.FileSystemTasks;
Expand All @@ -16,8 +15,10 @@ partial class Build
var buildDirectory = NativeProfilerProject.Directory / "build";
buildDirectory.CreateDirectory();

var (major, minor, patch) = VersionHelper.GetVersionParts();

CMake.Value(
arguments: $"../ -DCMAKE_BUILD_TYPE=Release",
arguments: $"../ -DCMAKE_BUILD_TYPE=Release -DOTEL_AUTO_VERSION={VersionHelper.GetVersionWithoutSuffixes()} -DOTEL_AUTO_VERSION_MAJOR={major} -DOTEL_AUTO_VERSION_MINOR={minor} -DOTEL_AUTO_VERSION_PATCH={patch}",
workingDirectory: buildDirectory);
Make.Value(
arguments: $"",
Expand Down
11 changes: 9 additions & 2 deletions build/Build.Steps.MacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ partial class Build
.Executes(() =>
{
var nativeProjectDirectory = NativeProfilerProject.Directory;
CMake.Value(arguments: $".", workingDirectory: nativeProjectDirectory);
Make.Value(arguments: $"", workingDirectory: nativeProjectDirectory);

var (major, minor, patch) = VersionHelper.GetVersionParts();

CMake.Value(
arguments: $". -DOTEL_AUTO_VERSION={VersionHelper.GetVersionWithoutSuffixes()} -DOTEL_AUTO_VERSION_MAJOR={major} -DOTEL_AUTO_VERSION_MINOR={minor} -DOTEL_AUTO_VERSION_PATCH={patch}",
workingDirectory: nativeProjectDirectory);
Make.Value(
arguments: $"",
workingDirectory: nativeProjectDirectory);
});

Target PublishNativeProfilerMacOs => _ => _
Expand Down
5 changes: 5 additions & 0 deletions build/Build.Steps.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ partial class Build
{
PerformLegacyRestoreIfNeeded(project);

var (major, minor, patch) = VersionHelper.GetVersionParts();

// Can't use dotnet msbuild, as needs to use the VS version of MSBuild
MSBuild(s => s
.SetTargetPath(project)
.SetConfiguration(BuildConfiguration)
.SetRestore(!NoRestore)
.SetMaxCpuCount(null)
.SetProperty("OTEL_AUTO_VERSION_MAJOR", major)
.SetProperty("OTEL_AUTO_VERSION_MINOR", minor)
.SetProperty("OTEL_AUTO_VERSION_PATCH", patch)
.CombineWith(platforms, (m, platform) => m
.SetTargetPlatform(platform)));
}
Expand Down
8 changes: 0 additions & 8 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ partial class Build : NukeBuild
[Parameter("The location to restore NuGet packages. Optional")]
readonly AbsolutePath NuGetPackagesDirectory;

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

[Parameter("Version suffix added to the NuGet packages built from the project, see https://semver.org/spec/v2.0.0.html#spec-item-9 for details. Default is empty")]
// The default needs to be empty: there is no other way to make this parameter to accept an empty string, which will be required
// for releases like "v1.2.0".
readonly string NuGetVersionSuffix = string.Empty;

[Parameter("Do not restore the projects before building.")]
readonly bool NoRestore;

Expand Down
7 changes: 1 addition & 6 deletions build/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<Project>
<!-- This file prevents unintended imports of unrelated MSBuild files -->
<!-- Uncomment to include parent Directory.Packages.props file -->
<!--<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Packages.props', '$(MSBuildThisFileDirectory)../'))" />-->
<Import Project="..\Directory.Packages.props" />

<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Mono.Cecil" Version="0.11.5" />
<PackageVersion Include="Nuke.Common" Version="7.0.2" />
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
Comment thread
nrcventura marked this conversation as resolved.
{
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]);
}
}
9 changes: 9 additions & 0 deletions build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
<PackageReference Include="Nuke.Common" />
<PackageReference Include="Nuget.CommandLine" ExcludeAssets="all" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MinVer">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\tools\DependencyListGenerator\DependencyListGenerator.csproj" />
Expand Down
7 changes: 0 additions & 7 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
- [`OpenTelemetry.DotNet.Auto.psm1`](../OpenTelemetry.DotNet.Auto.psm1)
- [`otel-dotnet-auto-install.sh`](../otel-dotnet-auto-install.sh)
- [`docs/README.md`](./README.md)
- [`build/Build.cs`](../build/Build.cs)
- [`src/Directory.Build.props`](../src/Directory.Build.props)
- [`src/OpenTelemetry.AutoInstrumentation/Constants.cs`](../src/OpenTelemetry.AutoInstrumentation/Constants.cs)
- [`src/OpenTelemetry.AutoInstrumentation.Native/CMakeLists.txt`](../src/OpenTelemetry.AutoInstrumentation.Native/CMakeLists.txt)
- [`src/OpenTelemetry.AutoInstrumentation.Native/Resource.rc`](../src/OpenTelemetry.AutoInstrumentation.Native/Resource.rc)
- [`src/OpenTelemetry.AutoInstrumentation.Native/otel_profiler_constants.h`](../src/OpenTelemetry.AutoInstrumentation.Native/otel_profiler_constants.h)
- [`src/OpenTelemetry.AutoInstrumentation.Native/version.h`](../src/OpenTelemetry.AutoInstrumentation.Native/version.h)

1. Update the [CHANGELOG.md](../CHANGELOG.md) with the new release.

Expand Down
11 changes: 10 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<EnablePublicApi>true</EnablePublicApi>

<!-- NuGet packages -->
<Version>1.0.0$(VersionSuffix)</Version>
<IsPackable>true</IsPackable>
<PackageIcon>opentelemetry-icon-color.png</PackageIcon>
<PackageProjectUrl>https://opentelemetry.io</PackageProjectUrl>
Expand All @@ -25,6 +24,16 @@
<NoWarn>$(NoWarn);NU5104</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MinVer">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>

<ItemGroup>
<!-- NuGet -->
<None Include="$(MSBuildThisFileDirectory)\..\opentelemetry-icon-color.png" Pack="true" Visible="false" PackagePath="opentelemetry-icon-color.png" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cmake_policy(SET CMP0015 NEW)
# Project definition
# ******************************************************

project("OpenTelemetry.AutoInstrumentation.Native" VERSION 1.0.0)
project("OpenTelemetry.AutoInstrumentation.Native" VERSION ${OTEL_AUTO_VERSION})

# ******************************************************
# Environment detection
Expand Down Expand Up @@ -144,6 +144,10 @@ elseif (ISARM)
add_compile_options(-DARM)
endif()

add_compile_definitions(OTEL_AUTO_VERSION_MAJOR=${OTEL_AUTO_VERSION_MAJOR})
add_compile_definitions(OTEL_AUTO_VERSION_MINOR=${OTEL_AUTO_VERSION_MINOR})
add_compile_definitions(OTEL_AUTO_VERSION_PATCH=${OTEL_AUTO_VERSION_PATCH})

# ******************************************************
# Suppress Warning on MacOS
# ******************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Resource.rc" />
<ResourceCompile Include="Resource.rc">
<AdditionalOptions>/dOTEL_AUTO_VERSION_MAJOR="$(OTEL_AUTO_VERSION_MAJOR)" /dOTEL_AUTO_VERSION_MINOR="$(OTEL_AUTO_VERSION_MINOR)" /dOTEL_AUTO_VERSION_PATCH="$(OTEL_AUTO_VERSION_PATCH)"</AdditionalOptions>
</ResourceCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
Loading