-
Notifications
You must be signed in to change notification settings - Fork 330
Add symbol verification to OneBranch pipelines #4073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
paulmedynski
wants to merge
3
commits into
main
Choose a base branch
from
dev/paul/symchk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,13 +15,14 @@ steps: | |
| - task: PowerShell@2 | ||
| displayName: Add SNI Validation Feed in Nuget.config | ||
| inputs: | ||
| pwsh: true | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tweaks to make this more cross-OS friendly. |
||
| targetType: inline | ||
| script: | | ||
| Write-Host "SNI validation feed to use = ${{parameters.SNIValidationFeed}}" | ||
|
|
||
| # define file to update | ||
| $NugetCfg = Join-Path -Path '.' -ChildPath 'NuGet.config' | ||
| type $NugetCfg | ||
| Get-Content $NugetCfg | ||
|
|
||
| # load content of xml from file defined above | ||
| $xml = New-Object XML | ||
|
|
@@ -44,10 +45,11 @@ steps: | |
|
|
||
| # save the xml file | ||
| $xml.Save($NugetCfg) | ||
| type $NugetCfg | ||
| Get-Content $NugetCfg | ||
| - task: PowerShell@2 | ||
| displayName: Update SNI Version in Versions.props | ||
| inputs: | ||
| pwsh: true | ||
| targetType: inline | ||
| # TODO(https://sqlclientdrivers.visualstudio.com/ADO.Net/_workitems/edit/42204): | ||
| # Package dependency versions have moved to Directory.Packages.props, so the below script no | ||
|
|
@@ -57,7 +59,7 @@ steps: | |
|
|
||
| # define file to update | ||
| $PropsPath = Join-Path -Path '.' -ChildPath 'tools\props\Versions.props' | ||
| type $PropsPath | ||
| Get-Content $PropsPath | ||
|
|
||
| # load content of xml from file defined above | ||
| $xml = New-Object XML | ||
|
|
@@ -79,6 +81,6 @@ steps: | |
|
|
||
| # save the xml file | ||
| $xml.Save($PropsPath) | ||
| type $PropsPath | ||
| Get-Content $PropsPath | ||
| - task: NuGetAuthenticate@1 | ||
| displayName: 'NuGet Authenticate with SNI Validation Feed' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| ################################################################################# | ||
| # Licensed to the .NET Foundation under one or more agreements. # | ||
| # The .NET Foundation licenses this file to you under the MIT license. # | ||
| # See the LICENSE file in the project root for more information. # | ||
| ################################################################################# | ||
|
|
||
| # Validates that symbols (PDBs) for every published package DLL are available on each configured | ||
| # symbol server using the symchk tool. | ||
| # | ||
| # All packages specified in the 'packages' parameter will be checked against all symbol servers | ||
| # specified in the 'symbolServers' parameter. | ||
|
|
||
| parameters: | ||
| # True to enable debug information and steps. | ||
| - name: debug | ||
| type: boolean | ||
|
|
||
| # The list of symbol servers to verify against. Each entry has a 'name' (friendly display name) | ||
| # and 'url' (the symbol server URL that symchk can query). | ||
| - name: symbolServers | ||
| type: object | ||
| default: | ||
| - name: MSDL (Public) | ||
| url: https://msdl.microsoft.com/download/symbols | ||
| - name: SymWeb (Internal) | ||
| url: https://symweb.azurefd.net | ||
|
|
||
| # The packages whose symbols should be verified. Each entry has: | ||
| # artifactName — pipeline artifact name (from onebranch-variables.yml) | ||
| # packageName — NuGet package name prefix used to locate the .nupkg file | ||
| # dllPath — relative path to the DLL inside the extracted package | ||
| - name: packages | ||
| type: object | ||
| default: [] | ||
|
|
||
| jobs: | ||
| - job: validate_symbols | ||
| displayName: Verify symbols on symbol servers | ||
|
|
||
| # Pool schema docs (OneBranch): https://aka.ms/obpipelines/yaml/jobs | ||
| # Agent pool concepts (Azure Pipelines): | ||
| # https://learn.microsoft.com/azure/devops/pipelines/agents/pools-queues | ||
| pool: | ||
| type: windows | ||
| isCustom: true | ||
| name: ADO-1ES-Pool | ||
| vmImage: ADO-Win25 | ||
|
|
||
| variables: | ||
| extractRoot: $(Build.SourcesDirectory)\symchk_packages | ||
|
|
||
| steps: | ||
| - ${{ if parameters.debug }}: | ||
| - script: SET | ||
| displayName: Print Environment Variables | ||
|
|
||
| # ── Download, extract, and verify symbols for each package ────────────── | ||
|
|
||
| - ${{ each pkg in parameters.packages }}: | ||
| - download: current | ||
| artifact: ${{ pkg.artifactName }} | ||
| patterns: '**/*.nupkg' | ||
| displayName: Download ${{ pkg.packageName }} | ||
|
|
||
|
paulmedynski marked this conversation as resolved.
|
||
| - ${{ each server in parameters.symbolServers }}: | ||
| - task: PowerShell@2 | ||
| displayName: Verify ${{ pkg.packageName }} on ${{ server.name }} | ||
| inputs: | ||
| pwsh: true | ||
| filePath: eng/pipelines/onebranch/scripts/validate-symbols.ps1 | ||
| arguments: > | ||
| -ArtifactPath "$(Pipeline.Workspace)\${{ pkg.artifactName }}" | ||
| -ExtractPath "$(extractRoot)\${{ pkg.packageName }}" | ||
| -PackageName "${{ pkg.packageName }}" | ||
| -DllPath "${{ pkg.dllPath }}" | ||
| -SymbolServerUrl "${{ server.url }}" | ||
| -SymbolServerName "${{ server.name }}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,79 @@ | ||
| # Publish-Symbols Tests | ||
| # OneBranch Script Tests | ||
|
|
||
| Pester tests for the `publish-symbols.ps1` script used by the symbol publishing pipeline step. | ||
| This directory contains [Pester](https://pester.dev/) tests for PowerShell | ||
| scripts used by the OneBranch pipelines. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - PowerShell 5.1+ or PowerShell 7+ | ||
| - [Pester v5](https://pester.dev/) (`Install-Module Pester -MinimumVersion 5.0 -Scope CurrentUser`) | ||
| | Tool | Version | Install | | ||
| | ---- | ------- | ------- | | ||
| | PowerShell (pwsh) | 7.2+ | [Install PowerShell](https://learn.microsoft.com/powershell/scripting/install/installing-powershell) | | ||
| | Pester | 5.x | `Install-Module Pester -Force -Scope CurrentUser -SkipPublisherCheck` | | ||
|
|
||
| ## Running the Tests | ||
| ## Running tests | ||
|
|
||
| From this directory: | ||
| From the repository root: | ||
|
|
||
| ```powershell | ||
| Invoke-Pester ./publish-symbols.Tests.ps1 | ||
| pwsh -c "Invoke-Pester ./eng/pipelines/onebranch/scripts/tests/ -Output Detailed" | ||
| ``` | ||
|
|
||
| Or from the repository root: | ||
| Run a single test file: | ||
|
|
||
| ```powershell | ||
| Invoke-Pester ./eng/pipelines/onebranch/scripts/tests/ | ||
| pwsh -c "Invoke-Pester ./eng/pipelines/onebranch/scripts/tests/publish-symbols.Tests.ps1 -Output Detailed" | ||
| pwsh -c "Invoke-Pester ./eng/pipelines/onebranch/scripts/tests/validate-symbols.Tests.ps1 -Output Detailed" | ||
| ``` | ||
|
|
||
| For detailed output: | ||
| ## Writing tests | ||
|
|
||
| ### File naming | ||
|
|
||
| Test files must follow Pester naming conventions: | ||
|
|
||
| ```text | ||
| <ScriptUnderTest>.Tests.ps1 | ||
| ``` | ||
|
|
||
| ### Locating the script under test | ||
|
|
||
| When scripts and tests are siblings under `scripts/` and `scripts/tests/`, | ||
| reference scripts relative to `$PSScriptRoot`: | ||
|
|
||
| ```powershell | ||
| BeforeAll { | ||
| $Script:ScriptPath = Join-Path $PSScriptRoot '..' 'my-script.ps1' | ||
| } | ||
| ``` | ||
|
|
||
| ### Testing scripts that use `exit` | ||
|
|
||
| Pipeline scripts commonly use `exit` for control flow. To validate exit codes, | ||
| run scripts as child processes with `Start-Process`: | ||
|
|
||
| ```powershell | ||
| Invoke-Pester ./publish-symbols.Tests.ps1 -Output Detailed | ||
| $proc = Start-Process -FilePath 'pwsh' ` | ||
| -ArgumentList @('-NoProfile', '-NonInteractive', '-File', $scriptPath, <args...>) ` | ||
| -NoNewWindow -Wait -PassThru ` | ||
| -RedirectStandardOutput $stdoutFile ` | ||
| -RedirectStandardError $stderrFile | ||
|
|
||
| $proc.ExitCode | Should -Be 0 | ||
| ``` | ||
|
|
||
| ## Test Coverage | ||
| ### Mocking external tools | ||
|
|
||
| When a script calls external tools (for example `symchk.exe`, `az`, or | ||
| `Invoke-RestMethod`), mock those calls in tests. See | ||
| `validate-symbols.Tests.ps1` and `publish-symbols.Tests.ps1`. | ||
|
|
||
| ## Test inventory | ||
|
|
||
| | Area | What's tested | | ||
| | --------------------- | ---------------------------------------------------------------- | | ||
| | Parameter validation | Empty strings rejected for all mandatory parameters | | ||
| | URL construction | Base URL, register URL, request URL built from parameters | | ||
| | Request bodies | Registration body, default publish flags, flag overrides | | ||
| | Error handling | Token failure, registration failure, publish failure, status failure — all verify expanded URI in error message | | ||
| | Status validation | Detects Failed/Cancelled results, respects PublishToInternal/PublishToPublic flags, passes on Succeeded/Pending | | ||
| | Test file | Script under test | What it covers | | ||
| | --------- | ----------------- | -------------- | | ||
| | `publish-symbols.Tests.ps1` | `scripts/publish-symbols.ps1` | Parameter validation, URL construction, request bodies, status validation, error handling | | ||
| | `validate-symbols.Tests.ps1` | `scripts/validate-symbols.ps1` | Syntax validation, package discovery/extraction, symchk detection, retry logic | | ||
|
|
||
| ## Notes | ||
|
|
||
| - All external calls (`az`, `Invoke-RestMethod`) are mocked — no network access or Azure credentials are required. | ||
| - Tests validate the script at `../publish-symbols.ps1` relative to this directory. | ||
| - Tests for `publish-symbols.ps1` mock all external calls (`az`, `Invoke-RestMethod`), so no network access or Azure credentials are required. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot has some built-in settings that specify 80 chars max, and it stores it locally (i.e. somewhere in my user directory). It claims that this will ensure that it generates text with our desired line length.