From dd7ae32230bb7af6de2c9112b67c44c8b538a3a1 Mon Sep 17 00:00:00 2001 From: Dmitriy Vasyura Date: Fri, 27 Nov 2026 04:14:22 -0800 Subject: [PATCH] Gate the DevDiv APIScan stage on the full source ref Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- azure-pipelines/README.md | 2 +- azure-pipelines/templates/rust-package.yml | 8 ++++++++ scripts/tests/test_azure_pipeline.py | 23 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/azure-pipelines/README.md b/azure-pipelines/README.md index 22dff880..c34dde7b 100644 --- a/azure-pipelines/README.md +++ b/azure-pipelines/README.md @@ -2,7 +2,7 @@ pre-release.yml: This should build from the `main` branch and publish to the Azu devdiv-pre-release.yml: DevDiv replacement for the MonacoTools `pre-release.yml` pipeline. It has the same triggers, build matrix, version suffix, and `bin-` artifacts. Like `pre-release.yml`, it only supplies parameters; the logic lives in `templates/rust-package.yml`, a DevDiv copy of `microsoft/vscode-engineering`'s `azure-pipelines/rust-package/pipeline.yml` that extends the MicroBuild 1ES template. Signing uses MicroBuild through `signing/sign.proj`: Windows `pet.exe` is signed with Microsoft400 in its build job, and all macOS `pet` binaries are signed with MacDeveloperHarden and notarized with 8020 in a single job. Linux binaries are not signed. -The DevDiv pipeline runs APIScan on the x64 Windows artifact and uploads results to TSA using `tsaoptions.json`. The `VSEng-APIScanSC` service connection must be authorized for the pipeline. Before disabling Monaco pipeline 591, merge this pipeline to `main`, set DevDiv definition 28980's default branch to `main`, verify a successful seven-target run, and migrate the Python Environments extension's pre-release consumer to the DevDiv artifacts. +After successful packaging, the DevDiv pipeline runs APIScan on the x64 Windows artifact and uploads results to TSA using `tsaoptions.json`. This stage runs for `main`, `release/*` branches, and release tags (`release/.` or the historical `v..` format). PR and feature refs skip the stage even when queued manually; packaging is unchanged. The `VSEng-APIScanSC` service connection must be authorized for the pipeline. Before disabling Monaco pipeline 591, merge this pipeline to `main`, set DevDiv definition 28980's default branch to `main`, verify a successful seven-target run, and migrate the Python Environments extension's pre-release consumer to the DevDiv artifacts. stable.yml: This builds tags matching `release/.`, where `` is four digits and `` is numeric, and publishes to the Azure Pipeline feed. The pipeline is triggered when a matching tag is pushed to GitHub. This will be consumed by extensions when publishing stable builds. Signing is required on this build. diff --git a/azure-pipelines/templates/rust-package.yml b/azure-pipelines/templates/rust-package.yml index bfdb39d0..a9346cad 100644 --- a/azure-pipelines/templates/rust-package.yml +++ b/azure-pipelines/templates/rust-package.yml @@ -134,6 +134,13 @@ extends: - checkout: self path: s + - ${{ if eq(platform.target, 'x86_64-pc-windows-msvc') }}: + - pwsh: | + $scanRef = $env:BUILD_SOURCEBRANCH -cmatch '^refs/(?:heads/(?:main|release/.+)|tags/(?:release/[0-9]{4}\.[0-9]+|v[0-9]{4}\.[0-9]+\.[0-9]+))$' + Write-Host "##vso[task.setvariable variable=scanRef;isOutput=true]$scanRef" + name: classifySource + displayName: Check APIScan source ref + - ${{ parameters.preBuildSteps }} - task: RustInstaller@1 @@ -390,6 +397,7 @@ extends: - stage: APIScan displayName: APIScan dependsOn: Package + condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'), eq(dependencies.Package.outputs['Package_x86_64_pc_windows_msvc.classifySource.scanRef'], 'True')) variables: # MicroBuild auto-injects a telemetry step that requires TeamName in every stage. TeamName: ${{ parameters.teamName }} diff --git a/scripts/tests/test_azure_pipeline.py b/scripts/tests/test_azure_pipeline.py index d711aff3..906b4cb5 100644 --- a/scripts/tests/test_azure_pipeline.py +++ b/scripts/tests/test_azure_pipeline.py @@ -53,6 +53,29 @@ def test_windows_notice_includes_unharvested_build_dependency(self): self.assertIn('Copyright 2016 Max Resch', additional) self.assertIn('Permission is hereby granted', additional) + def test_apiscan_source_ref_gate(self): + pattern = re.search(r"\$scanRef = \$env:BUILD_SOURCEBRANCH -cmatch '([^']+)'", self.template) + self.assertIsNotNone(pattern) + for ref, expected in ( + ('refs/heads/main', True), + ('refs/heads/release/latest', True), + ('refs/tags/release/2026.12', True), + ('refs/tags/v2024.16.0', True), + ('refs/pull/585/merge', False), + ('refs/heads/devdiv-prerelease', False), + ('refs/heads/feature/release/2026.12', False), + ('refs/heads/Main', False), + ('refs/tags/release/test', False), + ('refs/tags/release/2026.12-preview', False), + ('refs/tags/vnext', False), + ): + with self.subTest(ref=ref): + self.assertEqual(bool(re.search(pattern[1], ref)), expected) + + stage = self.template.split('- stage: APIScan\n', 1)[1].split('jobs:', 1)[0] + self.assertIn("condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'), " + "eq(dependencies.Package.outputs['Package_x86_64_pc_windows_msvc.classifySource.scanRef'], 'True'))", stage) + def test_apiscan_uses_workload_identity_service_connection(self): apiscan_start = self.template.index('- task: APIScan@2') tsa_start = self.template.index('- task: TSAUpload@2', apiscan_start)