|
| 1 | +# Trigger the build whenever `main` or `next` is updated |
| 2 | +trigger: |
| 3 | + - next |
| 4 | + - main |
| 5 | + |
| 6 | +# Disable PR trigger |
| 7 | +pr: none |
| 8 | + |
| 9 | +# Scheduled nightly build of `main` |
| 10 | +#schedules: |
| 11 | +# - cron: '0 0 * * *' |
| 12 | +# displayName: Nightly scheduled build |
| 13 | +# always: false # Don't rebuild if there haven't been changes |
| 14 | +# branches: |
| 15 | +# include: |
| 16 | +# - main |
| 17 | + |
| 18 | +parameters: |
| 19 | + - name: 'debug' |
| 20 | + displayName: 'Enable debug output' |
| 21 | + type: boolean |
| 22 | + default: false |
| 23 | + - name: isOfficialBuild |
| 24 | + displayName: 'Official Build + signing' |
| 25 | + type: boolean |
| 26 | + default: true |
| 27 | + |
| 28 | +variables: |
| 29 | + CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning |
| 30 | + system.debug: ${{ parameters.debug }} |
| 31 | + |
| 32 | + WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2022/vse2022:latest' # Docker image which is used to build the project https://aka.ms/obpipelines/containers |
| 33 | + |
| 34 | +resources: |
| 35 | + repositories: |
| 36 | + - repository: templates |
| 37 | + type: git |
| 38 | + name: OneBranch.Pipelines/GovernedTemplates |
| 39 | + ref: refs/heads/main |
| 40 | + |
| 41 | +extends: |
| 42 | + ${{ if eq(parameters.isOfficialBuild, true) }}: |
| 43 | + template: v2/OneBranch.Official.CrossPlat.yml@templates # https://aka.ms/obpipelines/templates |
| 44 | + ${{ else }}: |
| 45 | + template: v2/OneBranch.NonOfficial.CrossPlat.yml@templates # https://aka.ms/obpipelines/templates |
| 46 | + parameters: |
| 47 | + cloudvault: # https://aka.ms/obpipelines/cloudvault |
| 48 | + enabled: false |
| 49 | + globalSdl: # https://aka.ms/obpipelines/sdl |
| 50 | + asyncSdl: |
| 51 | + enabled: false |
| 52 | + tsa: |
| 53 | + enabled: false # onebranch publish all sdl results to TSA. If TSA is disabled all SDL tools will forced into'break' build mode. |
| 54 | + #configFile: '$(Build.SourcesDirectory)/.azure-pipelines/compliance/tsaoptions.json' |
| 55 | + credscan: |
| 56 | + suppressionsFile: $(Build.SourcesDirectory)/.azure-pipelines/compliance/CredScanSuppressions.json |
| 57 | + policheck: |
| 58 | + break: true # always break the build on policheck issues. You can disable it by setting to 'false' |
| 59 | + suppression: |
| 60 | + suppressionFile: $(Build.SourcesDirectory)/.config/guardian/.gdnsuppress |
| 61 | + codeql: |
| 62 | + excludePathPatterns: '**/.vscode-test, dist' # Exclude .vscode-test and dist directories from CodeQL alerting |
| 63 | + compiled: |
| 64 | + ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}: |
| 65 | + enabled: true |
| 66 | + ${{ else }}: |
| 67 | + enabled: false |
| 68 | + tsaEnabled: false # See 'Codeql.TSAEnabled' in the Addition Options section below |
| 69 | + componentgovernance: |
| 70 | + ignoreDirectories: $(Build.SourcesDirectory)/.vscode-test |
| 71 | + featureFlags: |
| 72 | + linuxEsrpSigning: true |
| 73 | + WindowsHostVersion: |
| 74 | + Version: 2022 |
| 75 | + |
| 76 | + stages: |
| 77 | + - stage: BuildStage |
| 78 | + jobs: |
| 79 | + - job: Main |
| 80 | + pool: |
| 81 | + type: windows |
| 82 | + variables: |
| 83 | + ob_outputDirectory: '$(Build.ArtifactStagingDirectory)\build' # this directory is uploaded to pipeline artifacts, reddog and cloudvault. More info at https://aka.ms/obpipelines/artifacts |
| 84 | + ob_sdl_binskim_break: true # https://aka.ms/obpipelines/sdl |
| 85 | + ob_sdl_codeSignValidation_excludes: '-|**\*.json;-|**\*.js;-|**\node_modules\**;' |
| 86 | + ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}: |
| 87 | + ob_sdl_codeql_compiled_enabled: true |
| 88 | + steps: |
| 89 | + - task: ComponentGovernanceComponentDetection@0 |
| 90 | + displayName: 'Component Governance - Component Detection' |
| 91 | + - task: notice@0 |
| 92 | + displayName: "\U0001F449 Generate NOTICE file" |
| 93 | + inputs: |
| 94 | + outputfile: $(Build.SourcesDirectory)/NOTICE.html |
| 95 | + outputformat: html |
| 96 | + |
| 97 | + - task: NodeTool@0 |
| 98 | + displayName: "\U0001F449 Using Node.js" |
| 99 | + inputs: |
| 100 | + versionSource: fromFile |
| 101 | + versionFilePath: .nvmrc |
| 102 | + |
| 103 | + - task: npmAuthenticate@0 |
| 104 | + displayName: "\U0001F449 Authenticate to npm registry" |
| 105 | + condition: succeeded() |
| 106 | + inputs: |
| 107 | + workingFile: '$(Build.SourcesDirectory)/.azure-pipelines/.npmrc' |
| 108 | + |
| 109 | + - task: Npm@1 |
| 110 | + displayName: "\U0001F449 Install Dependencies" |
| 111 | + condition: succeeded() |
| 112 | + inputs: |
| 113 | + command: custom |
| 114 | + customCommand: ci --userconfig $(Build.SourcesDirectory)/.azure-pipelines/.npmrc |
| 115 | + workingDir: $(Build.SourcesDirectory) |
| 116 | + |
| 117 | + - task: Npm@1 |
| 118 | + displayName: "\U0001F449 Build" |
| 119 | + condition: succeeded() |
| 120 | + inputs: |
| 121 | + command: custom |
| 122 | + customCommand: run build |
| 123 | + workingDir: $(Build.SourcesDirectory) |
| 124 | + |
| 125 | + - task: Npm@1 |
| 126 | + displayName: "\U0001F449 Package" |
| 127 | + condition: succeeded() |
| 128 | + inputs: |
| 129 | + command: custom |
| 130 | + customCommand: run package |
| 131 | + workingDir: $(Build.SourcesDirectory) |
| 132 | + |
| 133 | + - pwsh: npm i -g @vscode/vsce --userconfig $(Build.SourcesDirectory)/.azure-pipelines/.npmrc |
| 134 | + displayName: "\U0001F449 Install vsce" |
| 135 | + condition: succeeded() |
| 136 | + |
| 137 | + # Find the vsix and set the vsix file name variable |
| 138 | + # Fails with an error if more than one .vsix file is found, or if no .vsix file is found |
| 139 | + - task: PowerShell@2 |
| 140 | + displayName: "\U0001F50D Find VSIX File" |
| 141 | + inputs: |
| 142 | + targetType: 'inline' |
| 143 | + script: | |
| 144 | + # Get all .vsix files in the current directory |
| 145 | + Write-Output "Searching for .vsix files in: $(Build.SourcesDirectory)" |
| 146 | + $vsixFiles = Get-ChildItem -Path $(Build.SourcesDirectory) -Filter *.vsix -File |
| 147 | +
|
| 148 | + # Check if more than one .vsix file is found |
| 149 | + if ($vsixFiles.Count -gt 1) { |
| 150 | + Write-Error "[Error] More than one .vsix file found: $($vsixFiles.Name -join ', ')" |
| 151 | + exit 1 |
| 152 | + } elseif ($vsixFiles.Count -eq 0) { |
| 153 | + Write-Error "[Error] No .vsix files found in $(Build.SourcesDirectory)" |
| 154 | + exit 1 |
| 155 | + } else { |
| 156 | + # Set the pipeline variable |
| 157 | + $vsixFileName = $vsixFiles.Name |
| 158 | + $vsixFileSize = [math]::Round($vsixFiles.Length / 1MB, 2) |
| 159 | + Write-Output "##vso[task.setvariable variable=vsixFileName]$vsixFileName" |
| 160 | + Write-Output "Found .vsix file: $vsixFileName (${vsixFileSize} MB)" |
| 161 | + } |
| 162 | +
|
| 163 | + ## Sign the extension using OneBranch signing task |
| 164 | + ## see for VS Code specifics: https://aka.ms/vsm-ms-publisher-sign#cai-teams-sign-using-onebranch |
| 165 | + - script: vsce generate-manifest -i $(vsixFileName) -o extension.manifest |
| 166 | + displayName: "\U0001F5DD Generate extension manifest for signing" |
| 167 | + condition: and(succeeded(), ${{ eq(parameters.isOfficialBuild, true) }}) |
| 168 | + |
| 169 | + - task: PowerShell@2 |
| 170 | + displayName: "\U0001F408 Prepare manifest for signing" |
| 171 | + condition: and(succeeded(), ${{ eq(parameters.isOfficialBuild, true) }}) |
| 172 | + inputs: |
| 173 | + targetType: 'inline' |
| 174 | + script: | |
| 175 | + # Verify extension.manifest exists before proceeding |
| 176 | + if (-not (Test-Path "extension.manifest")) { |
| 177 | + Write-Error "[Error] extension.manifest file not found. Cannot proceed with signing." |
| 178 | + exit 1 |
| 179 | + } |
| 180 | +
|
| 181 | + Copy-Item -Path "extension.manifest" -Destination "extension.signature.p7s" |
| 182 | + Get-ChildItem -Path "$(Build.SourcesDirectory)" -Filter "extension.*" | ForEach-Object { Write-Output $_.FullName } |
| 183 | +
|
| 184 | + - task: onebranch.pipeline.signing@1 # https://aka.ms/obpipelines/signing |
| 185 | + displayName: "\U0001F5DD Sign VSIX package" |
| 186 | + # Only sign if isOfficialBuild is true |
| 187 | + condition: and(succeeded(), ${{ eq(parameters.isOfficialBuild, true) }}) |
| 188 | + inputs: |
| 189 | + command: 'sign' |
| 190 | + cp_code: CP-401405-VSCodePublisherSign |
| 191 | + files_to_sign: '**/extension.signature.p7s' |
| 192 | + search_root: '$(Build.SourcesDirectory)' |
| 193 | + #use_testsign: true # Set to true for test signing for development purposes, default is false |
| 194 | + |
| 195 | + - task: PowerShell@2 |
| 196 | + displayName: "\U0001F396 Verify VSIX signature" |
| 197 | + condition: and(succeeded(), ${{ eq(parameters.isOfficialBuild, true) }}) |
| 198 | + inputs: |
| 199 | + targetType: 'inline' |
| 200 | + failOnStderr: true |
| 201 | + script: | |
| 202 | + $output = vsce verify-signature -i $(vsixFileName) -m extension.manifest -s extension.signature.p7s 2>&1 |
| 203 | + Write-Output $output |
| 204 | +
|
| 205 | + # Check if the vsce command failed to execute |
| 206 | + if ($LastExitCode -ne 0) |
| 207 | + { |
| 208 | + Write-Error "[Error] VSIX signature verification command failed with exit code $LastExitCode." |
| 209 | + exit 1 |
| 210 | + } |
| 211 | +
|
| 212 | + # Parse the output to find the actual exit code line |
| 213 | + $exitCodeLine = $output | Where-Object { $_ -match "^Exit [Cc]ode:\s*(.+)$" } |
| 214 | + if ($exitCodeLine) { |
| 215 | + $exitCodeValue = $Matches[1].Trim() |
| 216 | + if ($exitCodeValue -eq "Success") { |
| 217 | + Write-Output "[Success] VSIX signature verification succeeded." |
| 218 | + } elseif ($exitCodeValue -eq "UnhandledException") { |
| 219 | + Write-Error "[Error] VSIX signature verification failed with UnhandledException." |
| 220 | + exit 1 |
| 221 | + } else { |
| 222 | + Write-Warning "[Warning] VSIX signature verification completed with unexpected exit code: $exitCodeValue" |
| 223 | + } |
| 224 | + } else { |
| 225 | + Write-Warning "[Warning] Could not parse exit code from vsce verify-signature output. Raw output: $output" |
| 226 | + } |
| 227 | +
|
| 228 | + - task: CopyFiles@2 |
| 229 | + displayName: "\U0001F449 Copy packages and vsix to staging directory" |
| 230 | + inputs: |
| 231 | + # Uploading the package.json so we can publish later without cloning the source |
| 232 | + # Files related to signing: |
| 233 | + # extension.manifest is the extension manifest generated by vsce |
| 234 | + # extension.signature.p7s is the signature file |
| 235 | + Contents: | |
| 236 | + *.vsix |
| 237 | + package.json |
| 238 | + extension.manifest |
| 239 | + extension.signature.p7s |
| 240 | + NOTICE.html |
| 241 | + **/*.tar.gz |
| 242 | + **/*.tgz |
| 243 | + !**/node_modules/** |
| 244 | + TargetFolder: $(ob_outputDirectory) |
| 245 | + condition: and(succeeded(), ne(variables['System.PullRequest.IsFork'], 'True')) |
| 246 | + |
| 247 | + - task: Npm@1 |
| 248 | + displayName: "\U0001F449 Test" |
| 249 | + inputs: |
| 250 | + command: custom |
| 251 | + customCommand: test |
| 252 | + workingDir: $(Build.SourcesDirectory) |
| 253 | + condition: succeeded() |
0 commit comments