|
| 1 | +name: LinuxCommandNotFound-ModuleBuild-$(Build.BuildId) |
| 2 | +trigger: none |
| 3 | +pr: none |
| 4 | + |
| 5 | +variables: |
| 6 | + DOTNET_CLI_TELEMETRY_OPTOUT: 1 |
| 7 | + POWERSHELL_TELEMETRY_OPTOUT: 1 |
| 8 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 |
| 9 | + SBOMGenerator_Formats: 'spdx:2.2' |
| 10 | + |
| 11 | +resources: |
| 12 | + repositories: |
| 13 | + - repository: ComplianceRepo |
| 14 | + type: github |
| 15 | + endpoint: ComplianceGHRepo |
| 16 | + name: PowerShell/compliance |
| 17 | + |
| 18 | +stages: |
| 19 | +- stage: Build |
| 20 | + displayName: Build and Sign |
| 21 | + pool: |
| 22 | + name: 1ES |
| 23 | + demands: |
| 24 | + - ImageOverride -equals PSMMS2019-Secure |
| 25 | + jobs: |
| 26 | + - job: build_windows |
| 27 | + displayName: Build command-not-found |
| 28 | + variables: |
| 29 | + - group: ESRP |
| 30 | + |
| 31 | + steps: |
| 32 | + |
| 33 | + - checkout: self |
| 34 | + clean: true |
| 35 | + persistCredentials: true |
| 36 | + |
| 37 | + - pwsh: | |
| 38 | + function Send-VstsCommand ($vstsCommandString) { |
| 39 | + Write-Host ("sending: " + $vstsCommandString) |
| 40 | + Write-Host "##$vstsCommandString" |
| 41 | + } |
| 42 | + Write-Host "PS Version: $($($PSVersionTable.PSVersion))" |
| 43 | + Set-Location -Path '$(Build.SourcesDirectory)\command-not-found' |
| 44 | + .\build.ps1 -Bootstrap |
| 45 | + .\build.ps1 -Configuration Release |
| 46 | +
|
| 47 | + # Set target folder paths |
| 48 | + New-Item -Path .\bin\NuGetPackage -ItemType Directory > $null |
| 49 | + Send-VstsCommand "vso[task.setvariable variable=NuGetPackage]$(Build.SourcesDirectory)\command-not-found\bin\NuGetPackage" |
| 50 | + Send-VstsCommand "vso[task.setvariable variable=Module]$(Build.SourcesDirectory)\command-not-found\bin\command-not-found" |
| 51 | + Send-VstsCommand "vso[task.setvariable variable=Signed]$(Build.SourcesDirectory)\command-not-found\bin\Signed" |
| 52 | + displayName: Bootstrap & Build |
| 53 | +
|
| 54 | + - task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0 |
| 55 | + displayName: 'Component Governance Detection' |
| 56 | + inputs: |
| 57 | + sourceScanPath: '$(Build.SourcesDirectory)\command-not-found' |
| 58 | + snapshotForceEnabled: true |
| 59 | + scanType: 'Register' |
| 60 | + failOnAlert: true |
| 61 | + |
| 62 | + - checkout: ComplianceRepo |
| 63 | + |
| 64 | + # Sign the module files |
| 65 | + - template: EsrpSign.yml@ComplianceRepo |
| 66 | + parameters: |
| 67 | + # the folder which contains the binaries to sign |
| 68 | + buildOutputPath: $(Module) |
| 69 | + # the location to put the signed output |
| 70 | + signOutputPath: $(Signed) |
| 71 | + # the certificate ID to use |
| 72 | + certificateId: "CP-230012" |
| 73 | + pattern: | |
| 74 | + *.psd1 |
| 75 | + *.psm1 |
| 76 | + *.ps1 |
| 77 | + *.ps1xml |
| 78 | + **\*.dll |
| 79 | + useMinimatch: true |
| 80 | + |
| 81 | + # Replace the *.psm1, *.ps1, *.psd1, *.dll files with the signed ones |
| 82 | + - pwsh: | |
| 83 | + # Show the signed files |
| 84 | + Get-ChildItem -Path $(Signed) |
| 85 | + Copy-Item -Path $(Signed)\* -Destination $(Module) -Recurse -Force |
| 86 | + displayName: 'Replace unsigned files with signed ones' |
| 87 | +
|
| 88 | + # Verify the signatures |
| 89 | + - pwsh: | |
| 90 | + $HasInvalidFiles = $false |
| 91 | + $WrongCert = @{} |
| 92 | + Get-ChildItem -Path $(Module) -Recurse -Include "*.dll","*.ps*1*" | ` |
| 93 | + Get-AuthenticodeSignature | ForEach-Object { |
| 94 | + $_ | Select-Object Path, Status |
| 95 | + if ($_.Status -ne 'Valid') { $HasInvalidFiles = $true } |
| 96 | + if ($_.SignerCertificate.Subject -notmatch 'CN=Microsoft Corporation.*') { |
| 97 | + $WrongCert.Add($_.Path, $_.SignerCertificate.Subject) |
| 98 | + } |
| 99 | + } |
| 100 | +
|
| 101 | + if ($HasInvalidFiles) { throw "Authenticode verification failed. There is one or more invalid files." } |
| 102 | + if ($WrongCert.Count -gt 0) { |
| 103 | + $WrongCert |
| 104 | + throw "Certificate should have the subject starts with 'Microsoft Corporation'" |
| 105 | + } |
| 106 | + displayName: 'Verify the signed files' |
| 107 | +
|
| 108 | + # Generate a Software Bill of Materials (SBOM) |
| 109 | + - template: Sbom.yml@ComplianceRepo |
| 110 | + parameters: |
| 111 | + BuildDropPath: '$(Module)' |
| 112 | + Build_Repository_Uri: 'https://github.com/PowerShell/command-not-found.git' |
| 113 | + displayName: Generate SBOM |
| 114 | + |
| 115 | + - pwsh: | |
| 116 | + try { |
| 117 | + $RepoName = "LocalRepo" |
| 118 | + Register-PSRepository -Name $RepoName -SourceLocation $(NuGetPackage) -PublishLocation $(NuGetPackage) -InstallationPolicy Trusted |
| 119 | + Publish-Module -Repository $RepoName -Path $(Module) |
| 120 | + } finally { |
| 121 | + Unregister-PSRepository -Name $RepoName -ErrorAction SilentlyContinue |
| 122 | + } |
| 123 | + Get-ChildItem -Path $(NuGetPackage) |
| 124 | + displayName: 'Create the NuGet package' |
| 125 | +
|
| 126 | + - pwsh: | |
| 127 | + Get-ChildItem -Path $(Module), $(NuGetPackage) |
| 128 | + Write-Host "##vso[artifact.upload containerfolder=command-not-found;artifactname=command-not-found]$(Module)" |
| 129 | + Write-Host "##vso[artifact.upload containerfolder=NuGetPackage;artifactname=NuGetPackage]$(NuGetPackage)" |
| 130 | + displayName: 'Upload artifacts' |
| 131 | +
|
| 132 | +- stage: compliance |
| 133 | + displayName: Compliance |
| 134 | + dependsOn: Build |
| 135 | + pool: |
| 136 | + name: 1ES |
| 137 | + demands: |
| 138 | + - ImageOverride -equals PSMMS2019-Secure |
| 139 | + jobs: |
| 140 | + - job: Compliance_Job |
| 141 | + displayName: command-not-found Compliance |
| 142 | + variables: |
| 143 | + - group: APIScan |
| 144 | + # APIScan can take a long time |
| 145 | + timeoutInMinutes: 240 |
| 146 | + |
| 147 | + steps: |
| 148 | + - checkout: self |
| 149 | + - checkout: ComplianceRepo |
| 150 | + - download: current |
| 151 | + artifact: command-not-found |
| 152 | + |
| 153 | + - pwsh: | |
| 154 | + Get-ChildItem -Path "$(Pipeline.Workspace)\command-not-found" -Recurse |
| 155 | + displayName: Capture downloaded artifacts |
| 156 | +
|
| 157 | + - pwsh: | |
| 158 | + function Send-VstsCommand ($vstsCommandString) { |
| 159 | + Write-Host ("sending: " + $vstsCommandString) |
| 160 | + Write-Host "##$vstsCommandString" |
| 161 | + } |
| 162 | +
|
| 163 | + # Get module version |
| 164 | + $psd1Data = Import-PowerShellDataFile -Path "$(Pipeline.Workspace)\command-not-found\command-not-found.psd1" |
| 165 | + $moduleVersion = $psd1Data.ModuleVersion |
| 166 | + $prerelease = $psd1Data.PrivateData.PSData.Prerelease |
| 167 | + if ($prerelease) { $moduleVersion = "$moduleVersion-$prerelease" } |
| 168 | + Send-VstsCommand "vso[task.setvariable variable=ModuleVersion]$moduleVersion" |
| 169 | + displayName: Get Module Version |
| 170 | +
|
| 171 | + - template: assembly-module-compliance.yml@ComplianceRepo |
| 172 | + parameters: |
| 173 | + # binskim |
| 174 | + AnalyzeTarget: '$(Pipeline.Workspace)\command-not-found\*.dll' |
| 175 | + AnalyzeSymPath: 'SRV*' |
| 176 | + # component-governance |
| 177 | + sourceScanPath: '' |
| 178 | + # credscan |
| 179 | + suppressionsFile: '' |
| 180 | + # TermCheck |
| 181 | + optionsRulesDBPath: '' |
| 182 | + optionsFTPath: '' |
| 183 | + # tsa-upload |
| 184 | + codeBaseName: 'CompletionPredictor_20220322' |
| 185 | + # apiscan |
| 186 | + softwareFolder: '$(Pipeline.Workspace)\command-not-found' |
| 187 | + softwareName: 'command-not-found' |
| 188 | + softwareVersion: '$(ModuleVersion)' |
| 189 | + connectionString: 'RunAs=App;AppId=$(APIScanClient);TenantId=$(APIScanTenant);AppKey=$(APIScanSecret)' |
0 commit comments