Skip to content

Commit e31019e

Browse files
[Azure Functions] Fix Azure Functions NuGet script for Linux and macOS (#7864)
## Summary of changes Fixed the `Build-AzureFunctionsNuget.ps1` script to work on Linux and macOS in addition to Windows. ## Reason for change The script only worked on only Windows. ## Implementation details - Added OS detection logic to select the appropriate Nuke build script (`build.ps1` for Windows, `build.sh` for Linux/macOS) - Changed all hardcoded backslash paths to forward slashes which work in all platforms - Updated paths in verbose output messages for consistency ## Test coverage Tested manually on Windows and Linux. This script is only used to build local dev versions of the nuget package, not production code. ## Other details n/a
1 parent 67c35ae commit e31019e

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

tracer/tools/Build-AzureFunctionsNuget.ps1

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,22 @@ param(
4242
$ErrorActionPreference = 'Stop'
4343
$ProgressPreference = 'SilentlyContinue'
4444

45+
# Detect OS and determine build script
46+
if ($PSVersionTable.PSVersion.Major -ge 6) {
47+
$buildScript = if ($IsWindows) { 'build.ps1' } else { 'build.sh' }
48+
} else {
49+
# PowerShell 5.x is Windows-only
50+
$buildScript = 'build.ps1'
51+
}
52+
4553
# Resolve paths relative to script location
4654
$scriptDir = Split-Path -Parent $PSCommandPath
4755
$tracerDir = Split-Path -Parent $scriptDir
4856
Write-Verbose "Tracer directory: $tracerDir"
4957

5058
# Clean up previous builds
51-
Write-Verbose "Cleaning up previous builds from: $tracerDir\bin\artifacts\nuget\azure-functions\"
52-
Remove-Item -Path "$tracerDir\bin\artifacts\nuget\azure-functions\*" -Force -ErrorAction SilentlyContinue
59+
Write-Verbose "Cleaning up previous builds from: $tracerDir/bin/artifacts/nuget/azure-functions/"
60+
Remove-Item -Path "$tracerDir/bin/artifacts/nuget/azure-functions/*" -Force -ErrorAction SilentlyContinue
5361

5462
# Remove package Datadog.AzureFunctions from NuGet cache
5563
Write-Verbose "Removing $packageId from NuGet cache..."
@@ -82,7 +90,7 @@ else
8290
if ($BuildId)
8391
{
8492
Write-Verbose "Downloading Datadog.Trace.Bundle from build: $BuildId"
85-
& "$tracerDir\build.ps1" DownloadBundleNugetFromBuild --build-id $BuildId
93+
& "$tracerDir/$buildScript" DownloadBundleNugetFromBuild --build-id $BuildId
8694
}
8795
else
8896
{
@@ -91,20 +99,20 @@ else
9199

92100
# Build Datadog.Trace and publish to bundle folder, replacing the files from the NuGet package
93101
Write-Verbose "Publishing Datadog.Trace (net6.0) to bundle folder..."
94-
dotnet publish "$tracerDir\src\Datadog.Trace" -c Release -o "$tracerDir\src\Datadog.Trace.Bundle\home\net6.0" -f 'net6.0'
102+
dotnet publish "$tracerDir/src/Datadog.Trace" -c Release -o "$tracerDir/src/Datadog.Trace.Bundle/home/net6.0" -f 'net6.0'
95103

96104
Write-Verbose "Publishing Datadog.Trace (net461) to bundle folder..."
97-
dotnet publish "$tracerDir\src\Datadog.Trace" -c Release -o "$tracerDir\src\Datadog.Trace.Bundle\home\net461" -f 'net461'
105+
dotnet publish "$tracerDir/src/Datadog.Trace" -c Release -o "$tracerDir/src/Datadog.Trace.Bundle/home/net461" -f 'net461'
98106

99107
# Build Azure Functions NuGet package
100108
Write-Verbose "Building Datadog.AzureFunctions NuGet package..."
101-
& "$tracerDir\build.ps1" BuildAzureFunctionsNuget
109+
& "$tracerDir/$buildScript" BuildAzureFunctionsNuget
102110

103111
# Copy package to destination if specified
104112
if ($CopyTo)
105113
{
106114
Write-Verbose "Copying package to: $CopyTo"
107-
Copy-Item "$tracerDir\bin\artifacts\nuget\azure-functions\Datadog.AzureFunctions.*.nupkg" $CopyTo -Force
115+
Copy-Item "$tracerDir/bin/artifacts/nuget/azure-functions/Datadog.AzureFunctions.*.nupkg" $CopyTo -Force
108116
}
109117

110118
Write-Verbose "Build complete!"

0 commit comments

Comments
 (0)