From 3054debf5150f074d58c8f13aa264850da737e14 Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Wed, 19 Jun 2024 16:34:21 -0600 Subject: [PATCH 1/7] Convert build pipeline to 1ES --- azure-pipelines.yml | 127 ------------------ eng/ci/build.yml | 47 +++++++ eng/ci/official.yml | 55 ++++++++ eng/ci/test.yml | 34 +++++ .../OpenTelemetryControllerTests.cs | 11 +- 5 files changed, 143 insertions(+), 131 deletions(-) delete mode 100644 azure-pipelines.yml create mode 100644 eng/ci/build.yml create mode 100644 eng/ci/official.yml create mode 100644 eng/ci/test.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index cb3088be..00000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,127 +0,0 @@ -# Starter pipeline -# Start with a minimal pipeline that you can customize to build and deploy your code. -# Add steps that build, run tests, deploy, and more: -# https://aka.ms/yaml - -#trigger: -#- master -#- dev - -strategy: - matrix: - linux: - imageName: 'MMSUbuntu20.04TLS' - windows: - imageName: 'MMS2019TLS' - -pool: - name: '1ES-Hosted-AzFunc' - demands: - - ImageOverride -equals $(imageName) - -variables: - Configuration: Release - buildNumber: $[ counter('build', 001) ] # Start higher than our AppVeyor versions. Every build (pr or branch) will increment. - -steps: -- task: AzureKeyVault@2 - inputs: - azureSubscription: 'Simple Batch(0b894477-1614-4c8d-8a9b-a697a24596b8)' - KeyVaultName: 'powershell-worker' - SecretsFilter: '*' - RunAsPreJob: true - -- pwsh: | - $releaseBranches = @('v4.x/ps7.4', 'v4.x/ps7.2', 'v4.x/ps7.0', 'v3.x/ps7', 'v3.x/ps6', 'v2.x') - - Write-Host "BuildSourceBranch: $($env:BuildSourceBranch)" - $branchName = $env:BuildSourceBranch.Replace("refs/heads/", "") - Write-Host "BranchName: $branchName" - - $isReleaseBuild = ($releaseBranches -contains $branchName) - Write-Host "##vso[task.setvariable variable=IsReleaseBuild]$isReleaseBuild" - Write-Host "IsReleaseBuild: $isReleaseBuild" - displayName: 'Set IsReleaseBuild variable' - env: - BuildSourceBranch: $(Build.SourceBranch) - condition: eq(variables['UPLOADPACKAGETOPRERELEASEFEED'], 'false') - -- pwsh: ./build.ps1 -NoBuild -Bootstrap - displayName: 'Running ./build.ps1 -NoBuild -Bootstrap' - -- pwsh: ./Check-CsprojVulnerabilities.ps1 - displayName: 'Check for security vulnerabilities' - -- pwsh: | - $ErrorActionPreference = "Stop" - - $shouldAddSBOM = $null - if ([string]::IsNullOrEmpty($IsReleaseBuild)) - { - Write-Host "IsReleaseBuild is null or empty. Setting shouldAddSBOM to false" - $shouldAddSBOM = $false - } - else - { - Write-Host "IsReleaseBuild: $IsReleaseBuild" - $shouldAddSBOM = ($IsReleaseBuild -eq "true") - } - - Write-Host "shouldAddSBOM: $shouldAddSBOM" - - ./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)" -AddSBOM:$shouldAddSBOM -SBOMUtilSASUrl "$(SBOMUtilSASUrl)" - displayName: 'Build worker code' - -- pwsh: ./build.ps1 -NoBuild -Test - displayName: 'Running UnitTest' - -- pwsh: ./test/E2E/Start-E2ETest.ps1 - env: - AzureWebJobsStorage: $(AzureWebJobsStorage) - AzureWebJobsCosmosDBConnectionString: $(AzureWebJobsCosmosDBConnectionString) - AzureWebJobsServiceBus: $(AzureWebJobsServiceBus) - AzureWebJobsEventHubSender: $(AzureWebJobsEventHubSender) - FUNCTIONS_WORKER_RUNTIME : "powershell" - displayName: 'Running E2ETest' - -- task: PublishTestResults@2 - inputs: - testResultsFormat: 'VSTest' - testResultsFiles: '**/*.trx' - failTaskOnFailedTests: true - condition: succeededOrFailed() - displayName: 'Publish tests results' - -- task: CopyFiles@2 - inputs: - SourceFolder: '$(System.DefaultWorkingDirectory)/package' - Contents: '**/*.nupkg' - TargetFolder: '$(Build.ArtifactStagingDirectory)' - displayName: 'Copy package to artifacts directory' - -- task: NuGetCommand@2 - condition: and(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['IsReleaseBuild'], 'true'), eq(variables['UPLOADPACKAGETOPRERELEASEFEED'], 'false')) - inputs: - command: 'push' - packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg' - nuGetFeedType: 'internal' - publishVstsFeed: 'e6a70c92-4128-439f-8012-382fe78d6396/c0493cce-bc63-4e11-9fc9-e7c45291f151' - allowPackageConflicts: true - displayName: 'Push NuGet package' - -- task: NuGetCommand@2 - condition: eq(variables['UPLOADPACKAGETOPRERELEASEFEED'], 'true') - inputs: - command: 'push' - packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg' - nuGetFeedType: 'internal' - publishVstsFeed: 'e6a70c92-4128-439f-8012-382fe78d6396/f37f760c-aebd-443e-9714-ce725cd427df' - allowPackageConflicts: true - displayName: 'Push NuGet package to the AzureFunctionsPreRelease feed' - -- task: PublishBuildArtifacts@1 - inputs: - PathtoPublish: '$(Build.ArtifactStagingDirectory)' - ArtifactName: 'drop' - publishLocation: 'Container' - displayName: 'Publish build artifacts' diff --git a/eng/ci/build.yml b/eng/ci/build.yml new file mode 100644 index 00000000..09f8dc43 --- /dev/null +++ b/eng/ci/build.yml @@ -0,0 +1,47 @@ +jobs: + - job: + templateContext: + outputs: + # - output: pipelineArtifact + # path: $(Build.ArtifactStagingDirectory) + # artifact: drop + # sbomBuildDropPath: '$(System.DefaultWorkingDirectory)/package' + # sbomPackageName: 'Azure Functions PowerShell Worker' + # # The list of components can't be determined from the webpacked file in the staging dir, so reference the original sources folder + # sbomBuildComponentPath: '$(Build.SourcesDirectory)' + - output: nuget + packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' + packageParentPath: '$(Build.ArtifactStagingDirectory)' + nuGetFeedType: internal + publishVstsFeed: 'e6a70c92-4128-439f-8012-382fe78d6396/c0493cce-bc63-4e11-9fc9-e7c45291f151' + # sbomBuildDropPath: '$(System.DefaultWorkingDirectory)/package' + sbomPackageName: 'Azure Functions PowerShell Worker' + sbomBuildComponentPath: '$(Build.SourcesDirectory)' + allowPackageConflicts: true + # - output: nuget + # condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/dev'), eq(variables['UPLOADPACKAGETOPRERELEASEFEED'], true)) + # packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' + # packageParentPath: '$(Build.ArtifactStagingDirectory)' + # nuGetFeedType: 'internal' + # publishVstsFeed: 'e6a70c92-4128-439f-8012-382fe78d6396/f37f760c-aebd-443e-9714-ce725cd427df' # AzureFunctionsPreRelease feed + # allowPackageConflicts: true + steps: + + - pwsh: ./build.ps1 -NoBuild -Bootstrap + displayName: "Running ./build.ps1 -NoBuild -Bootstrap" + + - pwsh: | + $ErrorActionPreference = "Stop" + + ./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)" + displayName: "Build worker code" + + - task: CopyFiles@2 + inputs: + SourceFolder: '$(System.DefaultWorkingDirectory)/package' + Contents: | + **/*.nuspec + **/*.nupkg + TargetFolder: '$(Build.ArtifactStagingDirectory)' + flattenFolders: true + displayName: 'Copy package to artifacts directory' diff --git a/eng/ci/official.yml b/eng/ci/official.yml new file mode 100644 index 00000000..fda51c23 --- /dev/null +++ b/eng/ci/official.yml @@ -0,0 +1,55 @@ +parameters: + - name: IsPrerelease + type: boolean + default: true + +trigger: + batch: true + branches: + include: + - v4.x/* + - v3.x/* + +# CI only, does not trigger on PRs. +pr: none + +resources: + repositories: + - repository: 1es + type: git + name: 1ESPipelineTemplates/1ESPipelineTemplates + ref: refs/tags/release + +variables: + Configuration: Release + buildNumber: $[ counter('build', 4000) ] # Start higher than our AppVeyor versions. Every build (pr or branch) will increment. + +extends: + template: v1/1ES.Official.PipelineTemplate.yml@1es + parameters: + pool: + name: 1es-pool-azfunc + image: 1es-windows-2022 + os: windows + + stages: + - stage: WindowsUnitTests + dependsOn: [] + jobs: + - template: /eng/ci/test.yml@self + + - stage: LinuxUnitTests + dependsOn: [] + jobs: + - template: /eng/ci/test.yml@self + pool: + name: 1es-pool-azfunc + image: 1es-ubuntu-22.04 + os: linux + + - stage: Build + dependsOn: [WindowsUnitTests, LinuxUnitTests] + jobs: + - template: /eng/ci/build.yml@self + parameters: + IsPrerelease: ${{ parameters.IsPrerelease }} \ No newline at end of file diff --git a/eng/ci/test.yml b/eng/ci/test.yml new file mode 100644 index 00000000..07a36ebf --- /dev/null +++ b/eng/ci/test.yml @@ -0,0 +1,34 @@ +jobs: + - job: UnitTests + steps: + - pwsh: ./build.ps1 -NoBuild -Bootstrap + displayName: "Running ./build.ps1 -NoBuild -Bootstrap" + + - pwsh: ./Check-CsprojVulnerabilities.ps1 + displayName: "Check for security vulnerabilities" + + - pwsh: | + $ErrorActionPreference = "Stop" + + ./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)" + displayName: "Build worker code" + + - pwsh: ./build.ps1 -NoBuild -Test + displayName: "Running UnitTest" + + # - pwsh: ./test/E2E/Start-E2ETest.ps1 + # env: + # AzureWebJobsStorage: $(AzureWebJobsStorage) + # AzureWebJobsCosmosDBConnectionString: $(AzureWebJobsCosmosDBConnectionString) + # AzureWebJobsServiceBus: $(AzureWebJobsServiceBus) + # AzureWebJobsEventHubSender: $(AzureWebJobsEventHubSender) + # FUNCTIONS_WORKER_RUNTIME: "powershell" + # displayName: "Running E2ETest" + + - task: PublishTestResults@2 + inputs: + testResultsFormat: "VSTest" + testResultsFiles: "**/*.trx" + failTaskOnFailedTests: true + condition: succeededOrFailed() + displayName: "Publish tests results" diff --git a/test/Unit/OpenTelemetry/OpenTelemetryControllerTests.cs b/test/Unit/OpenTelemetry/OpenTelemetryControllerTests.cs index 3a9b2297..4a77f813 100644 --- a/test/Unit/OpenTelemetry/OpenTelemetryControllerTests.cs +++ b/test/Unit/OpenTelemetry/OpenTelemetryControllerTests.cs @@ -10,6 +10,7 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.Test.OpenTelemetry { using PowerShell = System.Management.Automation.PowerShell; + [Collection("Sequence")] public class OpenTelemetryControllerTests { // These constant values will work because they are not actually passed to the module @@ -17,6 +18,7 @@ public class OpenTelemetryControllerTests private const string FakeInvocationID = "Fake InvocationID"; private const string FakeTraceParent = "Fake TraceParent"; + private const string OTelEnabledEnvironmentVariableName = "OTEL_FUNCTIONS_WORKER_ENABLED"; private readonly Mock _mockLogger = new Mock(MockBehavior.Strict); private readonly Mock _mockOtelServices; @@ -26,22 +28,23 @@ public OpenTelemetryControllerTests() } [Theory] - [InlineData("true", true)] - [InlineData("false", false)] [InlineData("True", true)] [InlineData("False", false)] + [InlineData("true", true)] + [InlineData("false", false)] [InlineData(null, false)] internal void OpenTelemetryEnvironmentVariableCheckWorks(string? environmentVariableValue, bool desiredResult) { try { - Environment.SetEnvironmentVariable("OTEL_FUNCTIONS_WORKER_ENABLED", environmentVariableValue); + Environment.SetEnvironmentVariable(OTelEnabledEnvironmentVariableName, environmentVariableValue); + OpenTelemetryController.ResetOpenTelemetryModuleStatus(); Assert.Equal(desiredResult, OpenTelemetryController.IsOpenTelemetryEnvironmentEnabled()); } finally { - Environment.SetEnvironmentVariable("OTEL_FUNCTIONS_WORKER_ENABLED", null); + Environment.SetEnvironmentVariable(OTelEnabledEnvironmentVariableName, null); OpenTelemetryController.ResetOpenTelemetryModuleStatus(); } } From 7856aa74c28c04fa1d7f8ef893c75cbc7cbc8aa6 Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Wed, 19 Jun 2024 16:36:07 -0600 Subject: [PATCH 2/7] Remove unnecesary output --- eng/ci/build.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/eng/ci/build.yml b/eng/ci/build.yml index 09f8dc43..98593999 100644 --- a/eng/ci/build.yml +++ b/eng/ci/build.yml @@ -2,13 +2,6 @@ jobs: - job: templateContext: outputs: - # - output: pipelineArtifact - # path: $(Build.ArtifactStagingDirectory) - # artifact: drop - # sbomBuildDropPath: '$(System.DefaultWorkingDirectory)/package' - # sbomPackageName: 'Azure Functions PowerShell Worker' - # # The list of components can't be determined from the webpacked file in the staging dir, so reference the original sources folder - # sbomBuildComponentPath: '$(Build.SourcesDirectory)' - output: nuget packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' packageParentPath: '$(Build.ArtifactStagingDirectory)' From 2a52f18c22258999ab8249c72ff83a21a2962c15 Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Wed, 19 Jun 2024 16:52:10 -0600 Subject: [PATCH 3/7] Add public pipeline --- eng/ci/build.yml | 40 ----------------- eng/ci/official.yml | 80 ++++++++++++++++----------------- eng/ci/public.yml | 47 +++++++++++++++++++ eng/ci/templates/build.yml | 39 ++++++++++++++++ eng/ci/{ => templates}/test.yml | 0 5 files changed, 126 insertions(+), 80 deletions(-) delete mode 100644 eng/ci/build.yml create mode 100644 eng/ci/public.yml create mode 100644 eng/ci/templates/build.yml rename eng/ci/{ => templates}/test.yml (100%) diff --git a/eng/ci/build.yml b/eng/ci/build.yml deleted file mode 100644 index 98593999..00000000 --- a/eng/ci/build.yml +++ /dev/null @@ -1,40 +0,0 @@ -jobs: - - job: - templateContext: - outputs: - - output: nuget - packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' - packageParentPath: '$(Build.ArtifactStagingDirectory)' - nuGetFeedType: internal - publishVstsFeed: 'e6a70c92-4128-439f-8012-382fe78d6396/c0493cce-bc63-4e11-9fc9-e7c45291f151' - # sbomBuildDropPath: '$(System.DefaultWorkingDirectory)/package' - sbomPackageName: 'Azure Functions PowerShell Worker' - sbomBuildComponentPath: '$(Build.SourcesDirectory)' - allowPackageConflicts: true - # - output: nuget - # condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/dev'), eq(variables['UPLOADPACKAGETOPRERELEASEFEED'], true)) - # packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' - # packageParentPath: '$(Build.ArtifactStagingDirectory)' - # nuGetFeedType: 'internal' - # publishVstsFeed: 'e6a70c92-4128-439f-8012-382fe78d6396/f37f760c-aebd-443e-9714-ce725cd427df' # AzureFunctionsPreRelease feed - # allowPackageConflicts: true - steps: - - - pwsh: ./build.ps1 -NoBuild -Bootstrap - displayName: "Running ./build.ps1 -NoBuild -Bootstrap" - - - pwsh: | - $ErrorActionPreference = "Stop" - - ./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)" - displayName: "Build worker code" - - - task: CopyFiles@2 - inputs: - SourceFolder: '$(System.DefaultWorkingDirectory)/package' - Contents: | - **/*.nuspec - **/*.nupkg - TargetFolder: '$(Build.ArtifactStagingDirectory)' - flattenFolders: true - displayName: 'Copy package to artifacts directory' diff --git a/eng/ci/official.yml b/eng/ci/official.yml index fda51c23..fcd5eabb 100644 --- a/eng/ci/official.yml +++ b/eng/ci/official.yml @@ -1,55 +1,55 @@ parameters: - - name: IsPrerelease - type: boolean - default: true + - name: IsPrerelease + type: boolean + default: true trigger: - batch: true - branches: - include: - - v4.x/* - - v3.x/* + batch: true + branches: + include: + - v4.x/* + - v3.x/* # CI only, does not trigger on PRs. pr: none resources: - repositories: - - repository: 1es - type: git - name: 1ESPipelineTemplates/1ESPipelineTemplates - ref: refs/tags/release + repositories: + - repository: 1es + type: git + name: 1ESPipelineTemplates/1ESPipelineTemplates + ref: refs/tags/release variables: Configuration: Release buildNumber: $[ counter('build', 4000) ] # Start higher than our AppVeyor versions. Every build (pr or branch) will increment. extends: - template: v1/1ES.Official.PipelineTemplate.yml@1es - parameters: + template: v1/1ES.Official.PipelineTemplate.yml@1es + parameters: + pool: + name: 1es-pool-azfunc + image: 1es-windows-2022 + os: windows + + stages: + - stage: WindowsUnitTests + dependsOn: [] + jobs: + - template: /eng/ci/templates/test.yml@self + + - stage: LinuxUnitTests + dependsOn: [] + jobs: + - template: /eng/ci/templates/test.yml@self pool: - name: 1es-pool-azfunc - image: 1es-windows-2022 - os: windows - - stages: - - stage: WindowsUnitTests - dependsOn: [] - jobs: - - template: /eng/ci/test.yml@self - - - stage: LinuxUnitTests - dependsOn: [] - jobs: - - template: /eng/ci/test.yml@self - pool: - name: 1es-pool-azfunc - image: 1es-ubuntu-22.04 - os: linux - - - stage: Build - dependsOn: [WindowsUnitTests, LinuxUnitTests] - jobs: - - template: /eng/ci/build.yml@self - parameters: - IsPrerelease: ${{ parameters.IsPrerelease }} \ No newline at end of file + name: 1es-pool-azfunc + image: 1es-ubuntu-22.04 + os: linux + + - stage: Build + dependsOn: [WindowsUnitTests, LinuxUnitTests] + jobs: + - template: /eng/ci/templates/build.yml@self + parameters: + IsPrerelease: ${{ parameters.IsPrerelease }} diff --git a/eng/ci/public.yml b/eng/ci/public.yml new file mode 100644 index 00000000..1aaf32ba --- /dev/null +++ b/eng/ci/public.yml @@ -0,0 +1,47 @@ +trigger: + batch: true + branches: + include: + - dev + - v4.x/* + - v3.x/* + +# Only run the tests on PR to official branches - do we want to run them on all PRs? +pr: + branches: + include: + - dev + - v4.x/* + - v3.x/* + +resources: + repositories: + - repository: 1es + type: git + name: 1ESPipelineTemplates/1ESPipelineTemplates + ref: refs/tags/release + +extends: + template: v1/1ES.Unofficial.PipelineTemplate.yml + parameters: + pool: + name: 1es-pool-azfunc-public + image: 1es-windows-2022 + os: windows + + stages: + - stage: WindowsUnitTests + dependsOn: [] + jobs: + - template: /eng/ci/templates/test.yml@self + pool: + name: 1es-pool-azfunc-public + + - stage: LinuxUnitTests + dependsOn: [] + jobs: + - template: /eng/ci/templates/test.yml@self + pool: + name: 1es-pool-azfunc-public + image: 1es-ubuntu-22.04 + os: linux diff --git a/eng/ci/templates/build.yml b/eng/ci/templates/build.yml new file mode 100644 index 00000000..70b648d9 --- /dev/null +++ b/eng/ci/templates/build.yml @@ -0,0 +1,39 @@ +jobs: + - job: + templateContext: + outputs: + - output: nuget + packagesToPush: "$(Build.ArtifactStagingDirectory)/*.nupkg" + packageParentPath: "$(Build.ArtifactStagingDirectory)" + nuGetFeedType: internal + publishVstsFeed: "e6a70c92-4128-439f-8012-382fe78d6396/c0493cce-bc63-4e11-9fc9-e7c45291f151" + # sbomBuildDropPath: '$(System.DefaultWorkingDirectory)/package' + sbomPackageName: "Azure Functions PowerShell Worker" + sbomBuildComponentPath: "$(Build.SourcesDirectory)" + allowPackageConflicts: true + # - output: nuget + # condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/dev'), eq(variables['UPLOADPACKAGETOPRERELEASEFEED'], true)) + # packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' + # packageParentPath: '$(Build.ArtifactStagingDirectory)' + # nuGetFeedType: 'internal' + # publishVstsFeed: 'e6a70c92-4128-439f-8012-382fe78d6396/f37f760c-aebd-443e-9714-ce725cd427df' # AzureFunctionsPreRelease feed + # allowPackageConflicts: true + steps: + - pwsh: ./build.ps1 -NoBuild -Bootstrap + displayName: "Running ./build.ps1 -NoBuild -Bootstrap" + + - pwsh: | + $ErrorActionPreference = "Stop" + + ./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)" + displayName: "Build worker code" + + - task: CopyFiles@2 + inputs: + SourceFolder: "$(System.DefaultWorkingDirectory)/package" + Contents: | + **/*.nuspec + **/*.nupkg + TargetFolder: "$(Build.ArtifactStagingDirectory)" + flattenFolders: true + displayName: "Copy package to artifacts directory" diff --git a/eng/ci/test.yml b/eng/ci/templates/test.yml similarity index 100% rename from eng/ci/test.yml rename to eng/ci/templates/test.yml From 5d3e52fb030612fd79542529987fd0e582bcb9d2 Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Wed, 19 Jun 2024 17:04:25 -0600 Subject: [PATCH 4/7] Remove test changes - will add back in new PR --- .../OpenTelemetry/OpenTelemetryControllerTests.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/test/Unit/OpenTelemetry/OpenTelemetryControllerTests.cs b/test/Unit/OpenTelemetry/OpenTelemetryControllerTests.cs index 4a77f813..3a9b2297 100644 --- a/test/Unit/OpenTelemetry/OpenTelemetryControllerTests.cs +++ b/test/Unit/OpenTelemetry/OpenTelemetryControllerTests.cs @@ -10,7 +10,6 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.Test.OpenTelemetry { using PowerShell = System.Management.Automation.PowerShell; - [Collection("Sequence")] public class OpenTelemetryControllerTests { // These constant values will work because they are not actually passed to the module @@ -18,7 +17,6 @@ public class OpenTelemetryControllerTests private const string FakeInvocationID = "Fake InvocationID"; private const string FakeTraceParent = "Fake TraceParent"; - private const string OTelEnabledEnvironmentVariableName = "OTEL_FUNCTIONS_WORKER_ENABLED"; private readonly Mock _mockLogger = new Mock(MockBehavior.Strict); private readonly Mock _mockOtelServices; @@ -28,23 +26,22 @@ public OpenTelemetryControllerTests() } [Theory] - [InlineData("True", true)] - [InlineData("False", false)] [InlineData("true", true)] [InlineData("false", false)] + [InlineData("True", true)] + [InlineData("False", false)] [InlineData(null, false)] internal void OpenTelemetryEnvironmentVariableCheckWorks(string? environmentVariableValue, bool desiredResult) { try { - Environment.SetEnvironmentVariable(OTelEnabledEnvironmentVariableName, environmentVariableValue); - OpenTelemetryController.ResetOpenTelemetryModuleStatus(); + Environment.SetEnvironmentVariable("OTEL_FUNCTIONS_WORKER_ENABLED", environmentVariableValue); Assert.Equal(desiredResult, OpenTelemetryController.IsOpenTelemetryEnvironmentEnabled()); } finally { - Environment.SetEnvironmentVariable(OTelEnabledEnvironmentVariableName, null); + Environment.SetEnvironmentVariable("OTEL_FUNCTIONS_WORKER_ENABLED", null); OpenTelemetryController.ResetOpenTelemetryModuleStatus(); } } From b526b9abd8c6864c3d87582a6252136a48804a6b Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Thu, 20 Jun 2024 11:05:37 -0600 Subject: [PATCH 5/7] Remove SBOM logic from build.ps1 --- build.ps1 | 59 +------------------------------------------------------ 1 file changed, 1 insertion(+), 58 deletions(-) diff --git a/build.ps1 b/build.ps1 index 3d7615f2..9825950c 100644 --- a/build.ps1 +++ b/build.ps1 @@ -28,13 +28,7 @@ param( $Configuration = "Debug", [string] - $BuildNumber = '0', - - [switch] - $AddSBOM, - - [string] - $SBOMUtilSASUrl + $BuildNumber = '0' ) #Requires -Version 7.0 @@ -73,35 +67,6 @@ function Get-FunctionsCoreToolsDir { } } -function Install-SBOMUtil -{ - if ([string]::IsNullOrEmpty($SBOMUtilSASUrl)) - { - throw "The `$SBOMUtilSASUrl parameter cannot be null or empty when specifying the `$AddSBOM switch" - } - - $MANIFESTOOLNAME = "ManifestTool" - Write-Log "Installing $MANIFESTOOLNAME..." - - $MANIFESTOOL_DIRECTORY = Join-Path $PSScriptRoot $MANIFESTOOLNAME - Remove-Item -Recurse -Force $MANIFESTOOL_DIRECTORY -ErrorAction Ignore - - Invoke-RestMethod -Uri $SBOMUtilSASUrl -OutFile "$MANIFESTOOL_DIRECTORY.zip" - Expand-Archive "$MANIFESTOOL_DIRECTORY.zip" -DestinationPath $MANIFESTOOL_DIRECTORY - - $dllName = "Microsoft.ManifestTool.dll" - $manifestToolPath = "$MANIFESTOOL_DIRECTORY/$dllName" - - if (-not (Test-Path $manifestToolPath)) - { - throw "$MANIFESTOOL_DIRECTORY does not contain '$dllName'" - } - - Write-Log 'Done.' - - return $manifestToolPath -} - function Deploy-PowerShellWorker { $ErrorActionPreference = 'Stop' @@ -179,28 +144,6 @@ if (!$NoBuild.IsPresent) { dotnet publish -c $Configuration "/p:BuildNumber=$BuildNumber" $PSScriptRoot - if ($AddSBOM) - { - # Install manifest tool - $manifestTool = Install-SBOMUtil - Write-Log "manifestTool: $manifestTool " - - # Generate manifest - $buildPath = "$PSScriptRoot/src/bin/$Configuration/$TargetFramework/publish" - $telemetryFilePath = Join-Path $PSScriptRoot ((New-Guid).Guid + ".json") - $packageName = "Microsoft.Azure.Functions.PowerShellWorker.nuspec" - - # Delete the manifest folder if it exists - $manifestFolderPath = Join-Path $buildPath "_manifest" - if (Test-Path $manifestFolderPath) - { - Remove-Item $manifestFolderPath -Recurse -Force -ErrorAction Ignore - } - - Write-Log "Running: dotnet $manifestTool generate -BuildDropPath $buildPath -BuildComponentPath $buildPath -Verbosity Information -t $telemetryFilePath" - & { dotnet $manifestTool generate -BuildDropPath $buildPath -BuildComponentPath $buildPath -Verbosity Information -t $telemetryFilePath -PackageName $packageName } - } - dotnet pack -c $Configuration "/p:BuildNumber=$BuildNumber" "$PSScriptRoot/package" } From 738d183d4c297ae094075ea0014338196659e5bb Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Thu, 20 Jun 2024 11:19:59 -0600 Subject: [PATCH 6/7] Remove IsPrerelease flag --- eng/ci/official.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/eng/ci/official.yml b/eng/ci/official.yml index fcd5eabb..4de4bac9 100644 --- a/eng/ci/official.yml +++ b/eng/ci/official.yml @@ -1,8 +1,3 @@ -parameters: - - name: IsPrerelease - type: boolean - default: true - trigger: batch: true branches: @@ -51,5 +46,3 @@ extends: dependsOn: [WindowsUnitTests, LinuxUnitTests] jobs: - template: /eng/ci/templates/build.yml@self - parameters: - IsPrerelease: ${{ parameters.IsPrerelease }} From f55862dc510c63f4370216997379b7f324ae7b18 Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Thu, 20 Jun 2024 11:30:11 -0600 Subject: [PATCH 7/7] Address PR concerns --- eng/ci/official.yml | 2 +- eng/ci/public.yml | 4 +--- eng/ci/templates/build.yml | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/eng/ci/official.yml b/eng/ci/official.yml index 4de4bac9..4ff1b052 100644 --- a/eng/ci/official.yml +++ b/eng/ci/official.yml @@ -17,7 +17,7 @@ resources: variables: Configuration: Release - buildNumber: $[ counter('build', 4000) ] # Start higher than our AppVeyor versions. Every build (pr or branch) will increment. + buildNumber: $[ counter('build', 4000) ] # Start higher than the versions from the previous pipeline. Every build (pr or branch) will increment. extends: template: v1/1ES.Official.PipelineTemplate.yml@1es diff --git a/eng/ci/public.yml b/eng/ci/public.yml index 1aaf32ba..726f8db0 100644 --- a/eng/ci/public.yml +++ b/eng/ci/public.yml @@ -10,9 +10,7 @@ trigger: pr: branches: include: - - dev - - v4.x/* - - v3.x/* + - '*' resources: repositories: diff --git a/eng/ci/templates/build.yml b/eng/ci/templates/build.yml index 70b648d9..f40e066a 100644 --- a/eng/ci/templates/build.yml +++ b/eng/ci/templates/build.yml @@ -7,7 +7,6 @@ jobs: packageParentPath: "$(Build.ArtifactStagingDirectory)" nuGetFeedType: internal publishVstsFeed: "e6a70c92-4128-439f-8012-382fe78d6396/c0493cce-bc63-4e11-9fc9-e7c45291f151" - # sbomBuildDropPath: '$(System.DefaultWorkingDirectory)/package' sbomPackageName: "Azure Functions PowerShell Worker" sbomBuildComponentPath: "$(Build.SourcesDirectory)" allowPackageConflicts: true