22# and some ref (branch, tag, etc.) or commit hash. Only runs on PRs.
33# ContinueOnError - true: Pipeline warns on spelling error
44# false: Pipeline fails on spelling error
5- # TargetBranch - Target ref (e.g. main) to compare to create file change
6- # list.
75# CspellConfigPath - Path to cspell.json config location
86#
97# This check recognizes the setting of variable "Skip.SpellCheck"
108# if set to 'true', spellchecking will not be invoked.
119
1210parameters :
13- ContinueOnError : true
14- CspellConfigPath : ./.vscode/cspell.json
11+ - name : ContinueOnError
12+ type : string
13+ default : true
14+ - name : CspellConfigPath
15+ type : string
16+ default : ./.vscode/cspell.json
17+ - name : EnableCspellUpgradeVerification
18+ type : boolean
19+ default : false
20+ - name : CspellUpgradePublicApiCheckoutExpression
21+ type : string
22+ default : /sdk/**
23+ - name : CspellUpgradeArtifactDirectory
24+ type : string
25+ default : $(Build.ArtifactStagingDirectory)/spelling-upgrade-check
1526
1627steps :
1728 - ${{ if eq(variables['Build.Reason'], 'PullRequest') }} :
@@ -26,3 +37,83 @@ steps:
2637 -CspellConfigPath ${{ parameters.CspellConfigPath }}
2738 -ExitWithError:(!$${{ parameters.ContinueOnError }})
2839 pwsh : true
40+
41+ - ${{ if eq(parameters.EnableCspellUpgradeVerification, true) }} :
42+ # If the repo has a spell-check-public-api.ps1 script and there is a change
43+ # to the cspell package-lock.json, verify the upgrade.
44+ - pwsh : |
45+ if ('true' -eq '$(Skip.SpellCheck)') {
46+ Write-Host "Spell check is skipped in this build. Skipping cspell upgrade verification."
47+ Write-Host "##vso[task.setvariable variable=RunCspellUpgradeVerification]false"
48+ exit 0
49+ }
50+ $publicApiCheckExists = Test-Path 'eng/scripts/spell-check-public-api.ps1'
51+ if (!$publicApiCheckExists) {
52+ Write-Host "Public API spell check script not found. Skipping upgrade checks."
53+ }
54+ Write-Host "Changed Files:"
55+ ./eng/common/scripts/Generate-PR-Diff.ps1 `
56+ -TargetPath '.' `
57+ -ArtifactPath '$(ArtifactStagingDirectory)'
58+ $changedFiles = (Get-Content '$(ArtifactStagingDirectory)/diff.json' | ConvertFrom-Json).ChangedFiles
59+ Write-Host $changedFiles
60+
61+ if ($changedFiles -contains 'eng/common/spelling/package-lock.json') {
62+ Write-Host "Detected change to cspell package-lock.json. Setting variables to run cspell upgrade verification."
63+ New-Item -ItemType Directory -Path '${{ parameters.CspellUpgradeArtifactDirectory }}' -Force | Out-Null
64+ Write-Host "##vso[task.setvariable variable=RunCspellUpgradeVerification]true"
65+ } else {
66+ Write-Host "No changes to cspell package-lock.json detected."
67+ Write-Host "##vso[task.setvariable variable=RunCspellUpgradeVerification]false"
68+ }
69+ displayName: Determine if cspell upgrade verification is needed
70+
71+ # Using the checkout task interferes with the job's existing checkout.
72+ # sparse-checkout.yml cannot be used here because it doesn't use runtime
73+ # conditions to determine if it should run
74+ - pwsh : |
75+ git clone `
76+ --no-checkout `
77+ --filter=tree:0 `
78+ --branch $(System.PullRequest.TargetBranch) `
79+ $(Build.Repository.Uri) `
80+ $(Pipeline.Workspace)/public-api-before
81+
82+ Set-Location $(Pipeline.Workspace)/public-api-before
83+ git sparse-checkout init
84+ git sparse-checkout set --no-cone '/*' '!/*/' '/eng' '/.vscode' '${{ parameters.CspellUpgradePublicApiCheckoutExpression }}'
85+ git checkout $(System.PullRequest.TargetBranch)
86+ condition: and(succeeded(), eq(variables['RunCspellUpgradeVerification'], 'true'))
87+ displayName: Sparse checkout before state of public API surface area
88+
89+ - pwsh : |
90+ ./eng/scripts/spell-check-public-api.ps1 > '${{ parameters.CspellUpgradeArtifactDirectory }}/spelling-after.txt'
91+ Get-Content '${{ parameters.CspellUpgradeArtifactDirectory }}/spelling-after.txt'
92+ condition: and(succeeded(), eq(variables['RunCspellUpgradeVerification'], 'true'))
93+ displayName: Get public API spelling errors after cspell upgrade
94+ # It's possible that cspell found errors, don't fail the build
95+ ignoreLASTEXITCODE: true
96+
97+ - pwsh : |
98+ ./eng/scripts/spell-check-public-api.ps1 > '${{ parameters.CspellUpgradeArtifactDirectory }}/spelling-before.txt'
99+ Get-Content '${{ parameters.CspellUpgradeArtifactDirectory }}/spelling-before.txt'
100+ condition: and(succeeded(), eq(variables['RunCspellUpgradeVerification'], 'true'))
101+ displayName: Get public API spelling errors before cspell upgrade
102+ # It's possible that cspell found errors, don't fail the build
103+ ignoreLASTEXITCODE: true
104+ workingDirectory: $(Pipeline.Workspace)/public-api-before
105+
106+ # On Linux the diff command exits with a nonzero exit code if there is a
107+ # diff. This step will fail if there are differences.
108+ - pwsh : |
109+ diff --unified `
110+ ${{ parameters.CspellUpgradeArtifactDirectory }}/spelling-before.txt `
111+ ${{ parameters.CspellUpgradeArtifactDirectory }}/spelling-after.txt | Tee-Object -FilePath ${{ parameters.CspellUpgradeArtifactDirectory }}/spelling-diff.txt
112+ condition: and(succeeded(), eq(variables['RunCspellUpgradeVerification'], 'true'))
113+ displayName: Compare public API spelling errors before and after cspell upgrade
114+
115+ - template : /eng/common/pipelines/templates/steps/publish-1es-artifact.yml
116+ parameters :
117+ ArtifactName : cspell-upgrade-check
118+ ArtifactPath : ${{ parameters.CspellUpgradeArtifactDirectory }}
119+ CustomCondition : and(succeededOrFailed(), eq(variables['RunCspellUpgradeVerification'], 'true'))
0 commit comments