Skip to content

Commit 7606e33

Browse files
authored
Add 1ES compliant pipeline (#19)
1 parent a5bcab2 commit 7606e33

File tree

4 files changed

+156
-75
lines changed

4 files changed

+156
-75
lines changed

build.ps1

Lines changed: 67 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -10,95 +10,87 @@ param(
1010
[string]
1111
$Configuration = 'Debug',
1212
[switch]
13-
$AddSBOM
13+
$NoBuild,
14+
[switch]
15+
$Test
1416
)
1517

1618
Import-Module "$PSScriptRoot\pipelineUtilities.psm1" -Force
1719

18-
$packageName = "AzureFunctions.PowerShell.OpenTelemetry.SDK"
19-
$shimPath = "$PSScriptRoot/src/AzureFunctions.PowerShell.OpenTelemetry.SDK"
20-
$otelEnginePath = "$PSScriptRoot/src/OpenTelemetryEngine"
21-
$otelAppPath = "$PSScriptRoot/test/E2E/app/Modules/$packageName"
22-
$powerShellModulePath = "$PSScriptRoot/src/$packageName.psm1"
23-
$manifestPath = "$PSScriptRoot/src/$packageName.psd1"
20+
if (!$NoBuild.IsPresent) {
2421

25-
# Publish to /out/ folder
26-
# When test app added, publish there instead
27-
$outputPath = $otelAppPath
22+
$packageName = "AzureFunctions.PowerShell.OpenTelemetry.SDK"
23+
$shimPath = "$PSScriptRoot/src/AzureFunctions.PowerShell.OpenTelemetry.SDK"
24+
$otelEnginePath = "$PSScriptRoot/src/OpenTelemetryEngine"
25+
$otelAppPath = "$PSScriptRoot/test/E2E/app/Modules/$packageName"
26+
$powerShellModulePath = "$PSScriptRoot/src/$packageName.psm1"
27+
$manifestPath = "$PSScriptRoot/src/$packageName.psd1"
2828

29-
$sharedDependenciesPath = "$outputPath/Dependencies/"
29+
# Publish to /out/ folder
30+
# When test app added, publish there instead
31+
$outputPath = $otelAppPath
3032

31-
$netCoreTFM = 'net6.0'
32-
$publishPathSuffix = "bin/$Configuration/$netCoreTFM/publish"
33+
$sharedDependenciesPath = "$outputPath/Dependencies/"
3334

34-
#region BUILD ARTIFACTS ===========================================================================
35-
Write-Log "Build started..."
36-
Write-Log "Configuration: '$Configuration'`nOutput folder '$outputPath'`nShared dependencies folder: '$sharedDependenciesPath'" "Gray"
35+
$netCoreTFM = 'net6.0'
36+
$publishPathSuffix = "bin/$Configuration/$netCoreTFM/publish"
3737

38-
# Map from project names to the folder containing the corresponding .csproj
39-
$projects = @{
40-
'OpenTelemetry SDK' = $shimPath
41-
'OpenTelemetry Engine' = $otelEnginePath
42-
}
38+
#region BUILD ARTIFACTS ===========================================================================
39+
Write-Log "Build started..."
40+
Write-Log "Configuration: '$Configuration'`nOutput folder '$outputPath'`nShared dependencies folder: '$sharedDependenciesPath'" "Gray"
4341

44-
# Remove previous build if it exists
45-
Write-Log "Removing previous build from $outputPath if it exists..." "Cyan"
46-
if (Test-Path $outputPath)
47-
{
48-
Remove-Item -Path $outputPath -Recurse -Force -ErrorAction Ignore
49-
}
50-
# Create output folder and its inner dependencies directory
51-
Write-Log "Creating a new output and shared dependencies folder at $outputPath and $sharedDependenciesPath..." "Cyan"
52-
[void](New-Item -Path $sharedDependenciesPath -ItemType Directory)
42+
# Map from project names to the folder containing the corresponding .csproj
43+
$projects = @{
44+
'OpenTelemetry SDK' = $shimPath
45+
'OpenTelemetry Engine' = $otelEnginePath
46+
}
5347

54-
# Build the OTel SDK project
55-
foreach ($project in $projects.GetEnumerator()) {
56-
Write-Log "Building $($project.Name) project with target framework $netCoreTFM...."
57-
Push-Location $project.Value
58-
try
48+
# Remove previous build if it exists
49+
Write-Log "Removing previous build from $outputPath if it exists..." "Cyan"
50+
if (Test-Path $outputPath)
5951
{
60-
dotnet publish -f $netCoreTFM -c $Configuration
52+
Remove-Item -Path $outputPath -Recurse -Force -ErrorAction Ignore
6153
}
62-
finally
63-
{
64-
Pop-Location
54+
# Create output folder and its inner dependencies directory
55+
Write-Log "Creating a new output and shared dependencies folder at $outputPath and $sharedDependenciesPath..." "Cyan"
56+
[void](New-Item -Path $sharedDependenciesPath -ItemType Directory)
57+
58+
# Build the OTel SDK project
59+
foreach ($project in $projects.GetEnumerator()) {
60+
Write-Log "Building $($project.Name) project with target framework $netCoreTFM...."
61+
Push-Location $project.Value
62+
try
63+
{
64+
dotnet publish -f $netCoreTFM -c $Configuration
65+
}
66+
finally
67+
{
68+
Pop-Location
69+
}
6570
}
66-
}
67-
68-
$commonFiles = [System.Collections.Generic.HashSet[string]]::new()
6971

70-
Write-Log "Copying assemblies from the OpenTelemetry Engine project into $sharedDependenciesPath" "Gray"
71-
Get-ChildItem -Path (Join-Path "$otelEnginePath" "$publishPathSuffix") |
72-
Where-Object { $_.Extension -in '.dll','.pdb' } |
73-
ForEach-Object { [void]$commonFiles.Add($_.Name); Copy-Item -LiteralPath $_.FullName -Destination $sharedDependenciesPath }
74-
75-
# Copy all *unique* assemblies from OTel SDK into output directory
76-
Write-Log "Copying unique assemblies from the OTel SDK project into $outputPath" "Gray"
77-
Get-ChildItem -Path (Join-Path "$shimPath" "$publishPathSuffix") |
78-
Where-Object { $_.Extension -in '.dll','.pdb' -and -not $commonFiles.Contains($_.Name) } |
79-
ForEach-Object { Copy-Item -LiteralPath $_.FullName -Destination $outputPath }
80-
81-
# Move OTel SDK manifest into the output directory
82-
Write-Log "Copying PowerShell module and manifest from the OTel SDK source code into $outputPath" "Gray"
83-
Copy-Item -Path $powerShellModulePath -Destination $outputPath
84-
Copy-Item -Path $manifestPath -Destination $outputPath
85-
Write-Log "Build succeeded!"
86-
#endregion
87-
88-
#region ADD SBOM ==================================================================================
89-
if ($AddSBOM) {
90-
# Install manifest tool
91-
$manifestToolPath = Install-SBOMUtil
92-
Write-Log "Manifest tool path: $manifestToolPath"
93-
94-
# Generate manifest
95-
$telemetryFilePath = Join-Path $PSScriptRoot ((New-Guid).Guid + ".json")
96-
$packageName = "AzureFunctions.PowerShell.OpenTelemetry.SDK"
97-
98-
Write-Log "Running: dotnet $manifestToolPath generate -BuildDropPath $outputPath -BuildComponentPath $outputPath -Verbosity Information -t $telemetryFilePath -PackageName $packageName"
99-
dotnet $manifestToolPath generate -BuildDropPath $outputPath -BuildComponentPath $outputPath -Verbosity Information -t $telemetryFilePath -PackageName $packageName
100-
101-
# Discard telemetry generated
102-
Remove-Item -Path $telemetryFilePath -ErrorAction Ignore
72+
$commonFiles = [System.Collections.Generic.HashSet[string]]::new()
73+
74+
Write-Log "Copying assemblies from the OpenTelemetry Engine project into $sharedDependenciesPath" "Gray"
75+
Get-ChildItem -Path (Join-Path "$otelEnginePath" "$publishPathSuffix") |
76+
Where-Object { $_.Extension -in '.dll','.pdb' } |
77+
ForEach-Object { [void]$commonFiles.Add($_.Name); Copy-Item -LiteralPath $_.FullName -Destination $sharedDependenciesPath }
78+
79+
# Copy all *unique* assemblies from OTel SDK into output directory
80+
Write-Log "Copying unique assemblies from the OTel SDK project into $outputPath" "Gray"
81+
Get-ChildItem -Path (Join-Path "$shimPath" "$publishPathSuffix") |
82+
Where-Object { $_.Extension -in '.dll','.pdb' -and -not $commonFiles.Contains($_.Name) } |
83+
ForEach-Object { Copy-Item -LiteralPath $_.FullName -Destination $outputPath }
84+
85+
# Move OTel SDK manifest into the output directory
86+
Write-Log "Copying PowerShell module and manifest from the OTel SDK source code into $outputPath" "Gray"
87+
Copy-Item -Path $powerShellModulePath -Destination $outputPath
88+
Copy-Item -Path $manifestPath -Destination $outputPath
89+
Write-Log "Build succeeded!"
90+
#endregion
91+
}
92+
#region Test ==================================================================================
93+
if ($Test.IsPresent) {
94+
Write-Log "There are no tests! Panic!"
10395
}
10496
#endregion

eng/ci/official.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
parameters:
2+
- name: IsPrerelease
3+
type: boolean
4+
default: true
5+
6+
trigger:
7+
batch: true
8+
branches:
9+
include:
10+
- main
11+
12+
# CI only, does not trigger on PRs.
13+
pr: none
14+
15+
resources:
16+
repositories:
17+
- repository: 1es
18+
type: git
19+
name: 1ESPipelineTemplates/1ESPipelineTemplates
20+
ref: refs/tags/release
21+
22+
# This variable will be needed when we automate uploading to PowerShell Gallery
23+
# We will have to modify build.ps1 to take this as input and append to end of module version
24+
# variables:
25+
# Configuration: Release
26+
# buildNumber: $[ counter('build', 1) ] # Start higher than our AppVeyor versions. Every build (pr or branch) will increment.
27+
28+
extends:
29+
template: v1/1ES.Official.PipelineTemplate.yml@1es
30+
parameters:
31+
pool:
32+
name: 1es-pool-azfunc
33+
image: 1es-windows-2022
34+
os: windows
35+
36+
stages:
37+
- stage: WindowsUnitTests
38+
dependsOn: []
39+
jobs:
40+
- template: /eng/ci/templates/test.yml@self
41+
42+
- stage: LinuxUnitTests
43+
dependsOn: []
44+
jobs:
45+
- template: /eng/ci/templates/test.yml@self
46+
pool:
47+
name: 1es-pool-azfunc
48+
image: 1es-ubuntu-22.04
49+
os: linux
50+
51+
- stage: Build
52+
dependsOn: [WindowsUnitTests, LinuxUnitTests]
53+
jobs:
54+
- template: /eng/ci/templates/build.yml@self
55+
parameters:
56+
IsPrerelease: ${{ parameters.IsPrerelease }}

eng/ci/templates/build.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
jobs:
2+
- job:
3+
templateContext:
4+
outputs:
5+
- output: pipelineArtifact
6+
path: $(Build.ArtifactStagingDirectory)/dropOutput
7+
artifact: drop
8+
sbomBuildDropPath: '$(Build.ArtifactStagingDirectory)/dropInput'
9+
sbomPackageName: 'Azure Functions PowerShell OpenTelemetry SDK'
10+
sbomBuildComponentPath: '$(Build.SourcesDirectory)'
11+
steps:
12+
- pwsh: ./build.ps1 -Configuration "Release"
13+
displayName: "Running ./build.ps1 -Configuration 'Release'"
14+
15+
- task: CopyFiles@2
16+
inputs:
17+
SourceFolder: "$(System.DefaultWorkingDirectory)/test/E2E/app/Modules"
18+
Contents: '**'
19+
TargetFolder: "$(Build.ArtifactStagingDirectory)/dropInput"
20+
displayName: "Copy package to artifacts directory"
21+
22+
- pwsh: |
23+
mkdir $(Build.ArtifactStagingDirectory)/dropOutput -Force | Out-Null
24+
Compress-Archive -Path $(Build.ArtifactStagingDirectory)/dropInput/AzureFunctions.PowerShell.OpenTelemetry.SDK/* -DestinationPath $(Build.ArtifactStagingDirectory)/dropOutput/AzureFunctions.PowerShell.OpenTelemetry.SDK.zip
25+
displayName: "Zip Module"

eng/ci/templates/test.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
jobs:
2+
- job: UnitTests
3+
steps:
4+
- pwsh: ./build.ps1 -Configuration "Release"
5+
displayName: ./build.ps1 -Configuration "Release"
6+
7+
- pwsh: ./build.ps1 -NoBuild -Test
8+
displayName: "Running UnitTest"

0 commit comments

Comments
 (0)