Skip to content

Commit 6e5563f

Browse files
committed
Use a dedicated APIScan pipeline with 'NonOfficial' pipeline template
1 parent 007383b commit 6e5563f

File tree

3 files changed

+170
-66
lines changed

3 files changed

+170
-66
lines changed

.pipelines/APIScan.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
name: apiscan-$(BUILD.SOURCEBRANCHNAME)-$(Build.BuildId)
5+
trigger: none
6+
7+
parameters:
8+
- name: FORCE_CODEQL
9+
displayName: Debugging - Enable CodeQL and set cadence to 1 hour
10+
type: boolean
11+
default: false
12+
- name: SkipVerifyPackages
13+
type: boolean
14+
default: false
15+
16+
variables:
17+
# PAT permissions NOTE: Declare a SymbolServerPAT variable in this group with a 'microsoft' organizanization scoped PAT with 'Symbols' Read permission.
18+
# A PAT in the wrong org will give a single Error 203. No PAT will give a single Error 401, and individual pdbs may be missing even if permissions are correct.
19+
- group: symbols
20+
- name: ob_outputDirectory
21+
value: '$(Build.ArtifactStagingDirectory)/ONEBRANCH_ARTIFACT'
22+
- name: CDP_DEFINITION_BUILD_COUNT
23+
value: $[counter('', 0)]
24+
# Defines the variables CgPat, CgOrganization, and CgProject
25+
- group: 'ComponentGovernance'
26+
- group: 'PoolNames'
27+
- name: LinuxContainerImage
28+
value: mcr.microsoft.com/onebranch/azurelinux/build:3.0
29+
- name: WindowsContainerImage
30+
value: onebranch.azurecr.io/windows/ltsc2022/vse2022:latest
31+
- ${{ if eq(parameters['FORCE_CODEQL'],'true') }}:
32+
# Cadence is hours before CodeQL will allow a re-upload of the database
33+
- name: CodeQL.Cadence
34+
value: 0
35+
- name: CODEQL_ENABLED
36+
${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/main'), eq(parameters['FORCE_CODEQL'],'true')) }}:
37+
value: true
38+
${{ else }}:
39+
value: false
40+
- name: Codeql.TSAEnabled
41+
value: $(CODEQL_ENABLED)
42+
# AnalyzeInPipeline: false = upload results
43+
# AnalyzeInPipeline: true = do not upload results
44+
- name: Codeql.AnalyzeInPipeline
45+
value: $(CODEQL_ENABLED)
46+
47+
resources:
48+
repositories:
49+
- repository: templates
50+
type: git
51+
name: OneBranch.Pipelines/GovernedTemplates
52+
ref: refs/heads/main
53+
54+
extends:
55+
template: v2/OneBranch.NonOfficial.CrossPlat.yml@templates
56+
parameters:
57+
featureFlags:
58+
WindowsHostVersion:
59+
Version: 2022
60+
globalSdl:
61+
codeql:
62+
compiled:
63+
enabled: $(CODEQL_ENABLED)
64+
tsaEnabled: $(CODEQL_ENABLED) # This enables TSA bug filing only for CodeQL 3000
65+
armory:
66+
enabled: false
67+
sbom:
68+
enabled: false
69+
cg:
70+
enabled: true
71+
ignoreDirectories: 'docs,shell,tools'
72+
tsa:
73+
enabled: true # onebranch publish all SDL results to TSA. If TSA is disabled all SDL tools will forced into 'break' build mode.
74+
credscan:
75+
enabled: true
76+
scanFolder: $(Build.SourcesDirectory)
77+
binskim:
78+
break: true # always break the build on binskim issues in addition to TSA upload
79+
policheck:
80+
break: true # always break the build on policheck issues. You can disable it by setting to 'false'
81+
# APIScan requires a non-Ready-To-Run build
82+
apiscan:
83+
enabled: true
84+
softwareName: 'AIShell' # Default is repo name
85+
versionNumber: '1.0' # Default is build number
86+
isLargeApp: false # Default: false.
87+
symbolsFolder: $(SymbolsServerUrl);$(ob_outputDirectory)
88+
tsaOptionsFile: .config\tsaoptions.json
89+
psscriptanalyzer:
90+
enabled: true
91+
policyName: Microsoft
92+
break: false
93+
94+
stages:
95+
- stage: APIScan
96+
displayName: 'ApiScan'
97+
dependsOn: []
98+
jobs:
99+
- template: /.pipelines/templates/compliance/apiscan-build.yaml@self
100+
parameters:
101+
parentJobs: []

.pipelines/Build-Official.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,3 @@ extends:
112112
displayName: module - build and sign
113113
jobs:
114114
- template: /.pipelines/templates/module-build.yml@self
115-
116-
- stage: APIScan
117-
displayName: 'ApiScan'
118-
jobs:
119-
- template: /.pipelines/templates/apiscan.yaml@self

.pipelines/templates/apiscan.yaml renamed to .pipelines/templates/compliance/apiscan-build.yaml

Lines changed: 69 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,17 @@ jobs:
1212
value : false
1313
- name: NugetSecurityAnalysisWarningLevel
1414
value: none
15-
# PAT permissions NOTE: Declare a SymbolServerPAT variable in this group with a 'microsoft' organizanization scoped PAT with 'Symbols' Read permission.
16-
# A PAT in the wrong org will give a single Error 203. No PAT will give a single Error 401, and individual pdbs may be missing even if permissions are correct.
17-
- group: symbols
1815
# Defines the variables APIScanClient, APIScanTenant and APIScanSecret
1916
- group: PS-PS-APIScan
20-
- group: DotNetPrivateBuildAccess
2117
- group: 'Azure Blob variable group'
22-
- group: ReleasePipelineSecrets
2318
- group: mscodehub-feed-read-general
2419
- group: mscodehub-feed-read-akv
2520
- name: ob_outputDirectory
26-
value: '$(Build.ArtifactStagingDirectory)/ONEBRANCH_ARTIFACT'
21+
value: '$(Build.ArtifactStagingDirectory)\ONEBRANCH_ARTIFACT'
2722
- name: repoRoot
2823
value: $(Build.SourcesDirectory)\AIShell
2924
- name: ob_sdl_tsa_configFile
3025
value: $(repoRoot)\.config\tsaoptions.json
31-
- name: ob_sdl_apiscan_enabled
32-
value: true
33-
- name: ob_sdl_apiscan_softwareName
34-
value: 'AIShell'
35-
- name: ob_sdl_apiscan_versionNumber
36-
value: '1.0'
37-
- name: ob_sdl_apiscan_isLargeApp
38-
value: false
39-
- name: ob_sdl_apiscan_symbolsFolder
40-
value: $(SymbolsServerUrl);$(ob_outputDirectory)
4126
- name: Codeql.SourceRoot
4227
value: $(repoRoot)
4328

@@ -54,7 +39,7 @@ jobs:
5439
env:
5540
ob_restore_phase: true # This ensures checkout is done at the beginning of the restore phase
5641

57-
- template: update-nuget-config.yml@self
42+
- template: ..\update-nuget-config.yml@self
5843
parameters:
5944
repoRoot: $(repoRoot)
6045

@@ -65,13 +50,13 @@ jobs:
6550
packageType: 'sdk'
6651
workingDirectory: $(Build.SourcesDirectory)"
6752

68-
- pwsh: |
69-
dotnet tool install dotnet-symbol --tool-path $(Agent.ToolsDirectory)\tools\dotnet-symbol
70-
$symbolToolPath = Get-ChildItem -Path $(Agent.ToolsDirectory)\tools\dotnet-symbol\dotnet-symbol.exe | Select-Object -First 1 -ExpandProperty FullName
71-
Write-Host "##vso[task.setvariable variable=symbolToolPath]$symbolToolPath"
72-
displayName: Install dotnet-symbol
73-
workingDirectory: '$(repoRoot)'
74-
retryCountOnTaskFailure: 2
53+
# - pwsh: |
54+
# dotnet tool install dotnet-symbol --tool-path $(Agent.ToolsDirectory)\tools\dotnet-symbol
55+
# $symbolToolPath = Get-ChildItem -Path $(Agent.ToolsDirectory)\tools\dotnet-symbol\dotnet-symbol.exe | Select-Object -First 1 -ExpandProperty FullName
56+
# Write-Host "##vso[task.setvariable variable=symbolToolPath]$symbolToolPath"
57+
# displayName: Install dotnet-symbol
58+
# workingDirectory: '$(repoRoot)'
59+
# retryCountOnTaskFailure: 2
7560

7661
- task: AzurePowerShell@5
7762
displayName: Download winverify-private Artifacts
@@ -85,15 +70,15 @@ jobs:
8570
# download smybols for getfilesiginforedist.dll
8671
$storageAccountName = "pscoretestdata"
8772
$containerName = 'winverify-private'
88-
$winverifySymbolsPath = New-Item -ItemType Directory -Path '$(System.ArtifactsDirectory)/winverify-symbols' -Force
73+
$winverifySymbolsPath = New-Item -ItemType Directory -Path '$(System.ArtifactsDirectory)\winverify-symbols' -Force
8974
$dllName = 'getfilesiginforedist.dll'
9075
$winverifySymbolsDllPath = Join-Path $winverifySymbolsPath $dllName
9176
9277
$context = New-AzStorageContext -StorageAccountName $storageAccountName -UseConnectedAccount
9378
Get-AzStorageBlobContent -Container $containerName -Blob $dllName -Destination $winverifySymbolsDllPath -Context $context
9479
9580
- pwsh: |
96-
Get-ChildItem -Path '$(System.ArtifactsDirectory)/winverify-symbols'
81+
Get-ChildItem -Path '$(System.ArtifactsDirectory)\winverify-symbols'
9782
displayName: Capture winverify-private Artifacts
9883
workingDirectory: '$(repoRoot)'
9984
condition: succeededOrFailed()
@@ -105,42 +90,70 @@ jobs:
10590
Language: csharp
10691

10792
- pwsh: |
108-
Import-Module $(repoRoot)/build.psm1 -Force
93+
Import-Module '$(repoRoot)\build.psm1' -Force
10994
Start-Build -Configuration StaticAnalysis -Runtime fxdependent -Clean -Verbose
11095
111-
$outputJson = '$(repoRoot)/_build_output_.json'
96+
$outputJson = '$(repoRoot)\_build_output_.json'
11297
if (-not (Test-Path $outputJson)) {
11398
throw "'_build_output_.json' was not produced."
11499
}
115100
116101
$result = Get-Content $outputJson | ConvertFrom-Json
117-
Write-Verbose "App path: $($result.App)" -Verbose
118102
$OutputFolder = $result.App
103+
Write-Verbose "App path: $OutputFolder" -Verbose
104+
105+
Write-Verbose -Verbose -Message "Deleting the 'ref' folder ..."
106+
if (Test-Path $OutputFolder\ref) {
107+
Remove-Item -Recurse -Force $OutputFolder\ref
108+
}
119109
120-
Write-Verbose -Verbose -Message "Deleting ref folder from output folder"
121-
if (Test-Path $OutputFolder/ref) {
122-
Remove-Item -Recurse -Force $OutputFolder/ref
110+
# Only keep windows runtimes
111+
Write-Verbose -Verbose -Message "Deleting non-win-x64 runtimes ..."
112+
Get-ChildItem -Path "$OutputFolder\runtimes\*" | Where-Object {$_.FullName -notmatch '.*\\runtimes\\win'} | Foreach-Object {
113+
Write-Verbose -Verbose -Message "Deleting $($_.FullName)"
114+
Remove-Item -Path $_.FullName -Recurse -Force
123115
}
124116
125-
Copy-Item -Path "$OutputFolder\*" -Destination '$(ob_outputDirectory)' -Recurse -Verbose
117+
# Remove win-x86/arm/arm64 runtimes due to issues with those runtimes
118+
Write-Verbose -Verbose -Message "Temporarily deleting win-x86/arm/arm64 runtimes ..."
119+
Get-ChildItem -Path "$OutputFolder\runtimes\*" | Where-Object {$_.FullName -match '.*\\runtimes\\win-(x86|arm)'} | Foreach-Object {
120+
Write-Verbose -Verbose -Message "Deleting $($_.FullName)"
121+
Remove-Item -Path $_.FullName -Recurse -Force
122+
}
123+
124+
Write-Host
125+
Write-Verbose -Verbose -Message "Show content in 'runtimes' folder:"
126+
Get-ChildItem -Path "$OutputFolder\runtimes"
127+
Write-Host
128+
129+
# Replace 'getfilesiginforedist.dll' from the 'runtimes\win-x64' folder
130+
Write-Verbose -Verbose -Message "Replace 'getfilesiginforedist.dll':"
131+
$targetFile = Get-ChildItem -Path "$OutputFolder\runtimes\*" -Recurse | Where-Object {$_.Name -eq 'getfilesiginforedist.dll'}
132+
Remove-Item -Path $targetFile.FullName -Verbose
133+
Copy-Item -Path '$(System.ArtifactsDirectory)\winverify-symbols\getfilesiginforedist.dll' -Destination $targetFile.FullName -Verbose
134+
135+
Write-Host "##vso[task.setvariable variable=appPath]$OutputFolder"
126136
workingDirectory: '$(repoRoot)'
127137
displayName: 'Build AIShell Source'
128138
129139
- pwsh: |
130-
# Only key windows runtimes
131-
Get-ChildItem -Path '$(ob_outputDirectory)\runtimes\*' -File -Recurse | Where-Object {$_.FullName -notmatch '.*\/runtimes\/win'} | Foreach-Object {
132-
Write-Verbose -Verbose -Message "Deleting $($_.FullName)"
133-
Remove-Item -Force -Verbose -Path $_.FullName
140+
$Destination = '$(ob_outputDirectory)'
141+
if (-not (Test-Path $Destination)) {
142+
Write-Verbose -Verbose -Message "Creating destination folder '$Destination'"
143+
$null = mkdir $Destination
134144
}
135145
136-
# Temporarily remove runtimes/win-x86 due to issues with that runtime
137-
Get-ChildItem -Path '$(ob_outputDirectory)\runtimes\*' -File -Recurse | Where-Object {$_.FullName -match '.*\/runtimes\/win-x86\/'} | Foreach-Object {
138-
Write-Verbose -Verbose -Message "Deleting $($_.FullName)"
139-
Remove-Item -Force -Verbose -Path $_.FullName
140-
}
146+
Write-Verbose -Verbose -Message "Copy AIShell app to '$Destination':"
147+
Copy-Item -Path '$(appPath)\*' -Destination $Destination -Recurse -Verbose
141148
149+
Write-Host
150+
Write-Verbose -Verbose -Message "Show content in '$Destination':"
151+
Get-ChildItem -Path $Destination | Out-String -width 150
152+
Write-Host
153+
Write-Verbose -Verbose -Message "Show content in '$Destination\runtimes':"
154+
Get-ChildItem -Path "$Destination\runtimes" -Recurse | Out-String -width 150
142155
workingDirectory: '$(repoRoot)'
143-
displayName: 'Remove unused runtimes'
156+
displayName: 'Copy AIShell to ob_outputDirectory'
144157
145158
- task: CodeQL3000Finalize@0 # Add CodeQL Finalize task right after your 'Build' step.
146159
displayName: 🔏 CodeQL 3000 Finalize
@@ -153,16 +166,17 @@ jobs:
153166
condition: succeededOrFailed()
154167
155168
# Explicitly download symbols for the drop since the SDL image doesn't have http://SymWeb access and APIScan cannot handle https yet.
156-
- pwsh: |
157-
$pat = '$(SymbolServerPAT)'
158-
if ($pat -like '*PAT*' -or $pat -eq '') {
159-
throw 'No PAT defined'
160-
}
161-
$url = 'https://microsoft.artifacts.visualstudio.com/defaultcollection/_apis/symbol/symsrv'
162-
$(symbolToolPath) --authenticated-server-path $(SymbolServerPAT) $url --symbols -d "$env:ob_outputDirectory\*" --recurse-subdirectories
163-
displayName: 'Download Symbols for binaries'
164-
retryCountOnTaskFailure: 2
165-
workingDirectory: '$(repoRoot)'
169+
# - pwsh: |
170+
# $pat = '$(SymbolServerPAT)'
171+
# if ($pat -like '*PAT*' -or $pat -eq '')
172+
# {
173+
# throw 'No PAT defined'
174+
# }
175+
# $url = 'https://microsoft.artifacts.visualstudio.com/defaultcollection/_apis/symbol/symsrv'
176+
# $(symbolToolPath) --authenticated-server-path $(SymbolServerPAT) $url --symbols -d "$env:ob_outputDirectory\*" --recurse-subdirectories
177+
# displayName: 'Download Symbols for binaries'
178+
# retryCountOnTaskFailure: 2
179+
# workingDirectory: '$(repoRoot)'
166180

167181
- pwsh: |
168182
Get-ChildItem '$(ob_outputDirectory)' -File -Recurse |
@@ -173,16 +187,10 @@ jobs:
173187
Md5Hash = (Get-FileHash -Algorithm MD5 -Path $_.FullName).Hash
174188
Sha512Hash = (Get-FileHash -Algorithm SHA512 -Path $_.FullName).Hash
175189
}
176-
} | Export-Csv -Path '$(Build.SourcesDirectory)/ReleaseFileHash.csv'
190+
} | Export-Csv -Path '$(Build.SourcesDirectory)\ReleaseFileHash.csv'
177191
workingDirectory: '$(repoRoot)'
178192
displayName: 'Create release file hash artifact'
179193
180194
- pwsh: |
181-
Copy-Item -Path '$(Build.SourcesDirectory)/ReleaseFileHash.csv' -Destination '$(ob_outputDirectory)' -Verbose
195+
Copy-Item -Path '$(Build.SourcesDirectory)\ReleaseFileHash.csv' -Destination '$(ob_outputDirectory)' -Verbose
182196
displayName: 'Publish Build File Hash artifact'
183-
184-
- pwsh: |
185-
Get-ChildItem -Path env: | Out-String -width 150 -Stream | write-Verbose -Verbose
186-
displayName: Capture Environment
187-
condition: succeededOrFailed()
188-
workingDirectory: '$(repoRoot)'

0 commit comments

Comments
 (0)