File size: 7,244 Bytes
8c763fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
parameters:
  Runtime: 'linux-x64'
  BuildConfiguration: 'release'
  JobName: 'build_linux'

jobs:
- job: build_${{ parameters.JobName }}
  displayName: Build_Linux_${{ parameters.Runtime }}_${{ parameters.BuildConfiguration }}
  condition: succeeded()
  pool:
    type: linux
  variables:
  - name: NugetSecurityAnalysisWarningLevel
    value: none
  - name: DOTNET_NOLOGO
    value: 1
  - group: DotNetPrivateBuildAccess
  - name: ob_outputDirectory
    value: '$(Build.ArtifactStagingDirectory)/ONEBRANCH_ARTIFACT'
  - name: ob_sdl_codeSignValidation_enabled
    value: false
  - name: ob_sdl_binskim_enabled
    value: true
  - name: ob_sdl_tsa_configFile
    value: $(Build.SourcesDirectory)\PowerShell\.config\tsaoptions.json
  - name: ob_sdl_credscan_suppressionsFile
    value: $(Build.SourcesDirectory)\PowerShell\.config\suppress.json
  - name: BUILDCONFIGURATION
    value: ${{ parameters.BuildConfiguration }}
  - name: Runtime
    value: ${{ parameters.Runtime }}
  - name: ob_sdl_sbom_packageName
    value: 'Microsoft.Powershell.Linux.${{ parameters.Runtime }}'
  # We add this manually, so we need it disabled the OneBranch auto-injected one.
  - name: ob_sdl_codeql_compiled_enabled
    value: false

  steps:
  - checkout: self
    clean: true
    env:
      ob_restore_phase: true # This ensures checkout is done at the beginning of the restore phase

  - template: /.pipelines/templates/SetVersionVariables.yml@self
    parameters:
      ReleaseTagVar: $(ReleaseTagVar)

  - template: /.pipelines/templates/cloneToOfficialPath.yml@self

  - template: /.pipelines/templates/insert-nuget-config-azfeed.yml@self
    parameters:
      repoRoot: $(PowerShellRoot)

  - task: CodeQL3000Init@0 # Add CodeQL Init task right before your 'Build' step.
    condition: eq(variables['CODEQL_ENABLED'], 'true')
    env:
      ob_restore_phase: true # Set ob_restore_phase to run this step before '๐Ÿ”’ Setup Signing' step.
    inputs:
      Enabled: true
      # AnalyzeInPipeline: false = upload results
      # AnalyzeInPipeline: true = do not upload results
      AnalyzeInPipeline: false
      Language: csharp

  - template: /.pipelines/templates/install-dotnet.yml@self

  - pwsh: |
      $runtime = $env:RUNTIME

      $params = @{}
      if ($env:BUILDCONFIGURATION -eq 'minSize') {
        Write-Verbose -Message "Building for minimal size"
        $params['ForMinimalSize'] = $true
      }

      Write-Verbose -Message "Building PowerShell with Runtime: $runtime"
      Import-Module -Name $(PowerShellRoot)/build.psm1 -Force
      $buildWithSymbolsPath = New-Item -ItemType Directory -Path $(Pipeline.Workspace)/Symbols_$(Runtime) -Force

      $null = New-Item -ItemType Directory -Path $buildWithSymbolsPath -Force -Verbose

      $ReleaseTagParam = @{}

      if ($env:RELEASETAGVAR) {
        $ReleaseTagParam['ReleaseTag'] = $env:RELEASETAGVAR
      }

      Start-PSBuild -Runtime $runtime -Configuration Release -Output $buildWithSymbolsPath @params -Clean -PSModuleRestore @ReleaseTagParam

      $outputPath = Join-Path '$(ob_outputDirectory)' 'psoptions'
      $null = New-Item -ItemType Directory -Path $outputPath -Force
      $psOptPath = "$outputPath/psoptions.json"
      Save-PSOptions -PSOptionsPath $psOptPath

      Write-Verbose -Verbose "Verifying pdbs exist in build folder"
      $pdbs = Get-ChildItem -Path $buildWithSymbolsPath -Recurse -Filter *.pdb
      if ($pdbs.Count -eq 0) {
        Write-Error -Message "No pdbs found in build folder"
      }
      else {
        Write-Verbose -Verbose "Found $($pdbs.Count) pdbs in build folder"
        $pdbs | ForEach-Object {
          Write-Verbose -Verbose "Pdb: $($_.FullName)"
        }
      }

      Write-Verbose -Verbose "Completed building PowerShell for '$env:BUILDCONFIGURATION' configuration"
    displayName: 'Build Linux - $(Runtime)'
    env:
      __DOTNET_RUNTIME_FEED_KEY: $(RUNTIME_SOURCEFEED_KEY)
      ob_restore_phase: true # Set ob_restore_phase to run this step before '๐Ÿ”’ Setup Signing' step.

  - task: CodeQL3000Finalize@0 # Add CodeQL Finalize task right after your 'Build' step.
    condition: eq(variables['CODEQL_ENABLED'], 'true')
    env:
      ob_restore_phase: true # Set ob_restore_phase to run this step before '๐Ÿ”’ Setup Signing' step.

  - pwsh: |
      $platform = 'linux'
      $vstsCommandString = "vso[task.setvariable variable=ArtifactPlatform]$platform"
      Write-Host ("sending " + $vstsCommandString)
      Write-Host "##$vstsCommandString"
    displayName: Set artifact platform

  - pwsh: |
      $pathForUpload = New-Item -ItemType Directory -Path '$(ob_outputDirectory)/Unsigned-$(Runtime)' -Force
      Write-Verbose -Verbose -Message "pathForUpload: $pathForUpload"
      Copy-Item -Path '$(Pipeline.Workspace)/Symbols_$(Runtime)/*' -Destination $pathForUpload -Recurse -Force -Verbose
    displayName: Copy unsigned files for upload

  - template: /.pipelines/templates/step/finalize.yml@self

- job: sign_${{ parameters.JobName }}
  displayName: Sign_Linux_${{ parameters.Runtime }}_${{ parameters.BuildConfiguration }}
  condition: succeeded()
  dependsOn: build_${{ parameters.JobName }}
  pool:
    type: windows
  variables:
  - name: NugetSecurityAnalysisWarningLevel
    value: none
  - name: DOTNET_NOLOGO
    value: 1
  - group: DotNetPrivateBuildAccess
  - group: certificate_logical_to_actual
  - name: ob_outputDirectory
    value: '$(Build.ArtifactStagingDirectory)/ONEBRANCH_ARTIFACT'
  - name: ob_sdl_codeSignValidation_enabled
    value: false
  - name: ob_sdl_binskim_enabled
    value: false
  - name: ob_sdl_tsa_configFile
    value: $(Build.SourcesDirectory)\PowerShell\.config\tsaoptions.json
  - name: ob_sdl_credscan_suppressionsFile
    value: $(Build.SourcesDirectory)\PowerShell\.config\suppress.json
  - name: BuildConfiguration
    value: ${{ parameters.BuildConfiguration }}
  - name: Runtime
    value: ${{ parameters.Runtime }}
  - name: ob_sdl_codeql_compiled_enabled
    value: false

  steps:
  - checkout: self
    clean: true
    env:
      ob_restore_phase: true # This ensures checkout is done at the beginning of the restore phase

  - template: /.pipelines/templates/SetVersionVariables.yml@self
    parameters:
      ReleaseTagVar: $(ReleaseTagVar)

  - template: /.pipelines/templates/cloneToOfficialPath.yml@self

  - task: DownloadPipelineArtifact@2
    inputs:
      artifact: drop_linux_build_${{ parameters.JobName }}
      path: $(Pipeline.Workspace)/drop_linux_build
    displayName: Download build

  - pwsh: |
      Get-ChildItem -Path $(Pipeline.Workspace)/drop_linux_build -Recurse
    displayName: Capture downloaded files

  - pwsh: |
      $pwshPath = Get-ChildItem -Path $(Pipeline.Workspace)/drop_linux_build -File -Recurse | Where-Object { $_.Name -eq 'pwsh' }
      $rootPath = Split-Path -Path $pwshPath.FullName -Parent
      Write-Verbose -Verbose "Setting vso[task.setvariable variable=DropRootPath]$rootPath"
      Write-Host "##vso[task.setvariable variable=DropRootPath]$rootPath"
    displayName: Set drop root path

  - template: /.pipelines/templates/obp-file-signing.yml@self
    parameters:
      binPath: $(DropRootPath)
      OfficialBuild: $(ps_official_build)

  - template: /.pipelines/templates/step/finalize.yml@self