From d1768536721b929b15faf5d08b3d5a5a96608a29 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 9 Nov 2021 09:23:26 -0800 Subject: [PATCH] Make static CI a matrix (#16397) * move markdown lint tests * move markdown link tests * refactor static link analysis into a matrix * cache yarn packages * fix paramater name --- .vsts-ci/misc-analysis.yml | 106 ++++++------------ .../misc-analysis/generateMarkdownMatrix.yml | 46 ++++++++ .vsts-ci/misc-analysis/markdown.yml | 63 +++++++++++ .vsts-ci/misc-analysis/mdSpell.yml | 56 +++++++++ .../markdown-link.tests.ps1 | 13 ++- .../{markdown => markdown-lint}/.gitignore | 0 .../{markdown => markdown-lint}/gulpfile.js | 0 .../markdown.tests.ps1 | 0 .../{markdown => markdown-lint}/package.json | 0 .../{markdown => markdown-lint}/yarn.lock | 0 10 files changed, 209 insertions(+), 75 deletions(-) create mode 100644 .vsts-ci/misc-analysis/generateMarkdownMatrix.yml create mode 100644 .vsts-ci/misc-analysis/markdown.yml create mode 100644 .vsts-ci/misc-analysis/mdSpell.yml rename test/common/{markdown => markdown-link}/markdown-link.tests.ps1 (92%) rename test/common/{markdown => markdown-lint}/.gitignore (100%) rename test/common/{markdown => markdown-lint}/gulpfile.js (100%) rename test/common/{markdown => markdown-lint}/markdown.tests.ps1 (100%) rename test/common/{markdown => markdown-lint}/package.json (100%) rename test/common/{markdown => markdown-lint}/yarn.lock (100%) diff --git a/.vsts-ci/misc-analysis.yml b/.vsts-ci/misc-analysis.yml index 5de5e28265..e1f2d8ebfc 100644 --- a/.vsts-ci/misc-analysis.yml +++ b/.vsts-ci/misc-analysis.yml @@ -27,83 +27,41 @@ variables: - name: repoFolder value: PowerShell -jobs: -- job: CI_Compliance - displayName: CI Compliance +stages: +- stage: Compliance + jobs: + - job: CI_Compliance + displayName: CI Compliance - pool: - vmImage: windows-latest + pool: + vmImage: windows-latest - variables: - - name: repoPath - value: $(Agent.BuildDirectory)\$(repoFolder) + variables: + - name: repoPath + value: $(Agent.BuildDirectory)\$(repoFolder) - steps: - - checkout: self - clean: true - path: $(repoFolder) + steps: + - checkout: self + clean: true + path: $(repoFolder) - - checkout: ComplianceRepo + - checkout: ComplianceRepo - - template: ci-compliance.yml@ComplianceRepo - -- job: Linux_CI - displayName: Markdown and Common Tests - - pool: - vmImage: ubuntu-20.04 - - variables: - - name: repoPath - value: $(Agent.BuildDirectory)/$(repoFolder) - - steps: - - checkout: self - clean: true - path: $(repoFolder) - - - checkout: ComplianceRepo - - - powershell: | - Get-ChildItem -Path env: - displayName: Capture Environment - condition: succeededOrFailed() - - - powershell: | - Install-module Pester -Scope CurrentUser -Force -MaximumVersion 4.99 - displayName: Install Pester - condition: succeededOrFailed() - - - bash: | - curl -o- --progress-bar -L https://yarnpkg.com/install.sh | bash - displayName: Bootstrap Yarn - condition: succeededOrFailed() - - - bash: | - sudo yarn global add markdown-spellcheck@0.11.0 - displayName: Install mdspell - condition: succeededOrFailed() - - - bash: | - mdspell '**/*.md' '!**/Pester/**/*.md' '!**/dotnet-tools/**/*.md' --ignore-numbers --ignore-acronyms --report --en-us; - displayName: Test Spelling in Markdown - condition: succeededOrFailed() - workingDirectory: '$(repoPath)' - - - ${{ if not(contains(variables['SYSTEM.COLLECTIONURI'],'mscodehub')) }}: - - pwsh: | - Import-module ./build.psm1 - $path = Join-Path -Path $pwd -ChildPath './commonTestResults.xml' - $results = invoke-pester -Script ./test/common -OutputFile $path -OutputFormat NUnitXml -PassThru - Write-Host "##vso[results.publish type=NUnit;mergeResults=true;runTitle=Common Tests;publishRunAttachments=true;resultFiles=$path;]" - if($results.TotalCount -eq 0 -or $results.FailedCount -gt 0) - { - throw "Markdown tests failed" - } - displayName: Run Common Tests - condition: succeededOrFailed() - workingDirectory: '$(repoPath)' - - - template: dailyBuildCompliance.yml@ComplianceRepo + - template: ci-compliance.yml@ComplianceRepo +- stage: markdown_spelling_lint + displayName: Markdown Spelling and Lint + dependsOn: [] + jobs: + - template: ./misc-analysis/mdSpell.yml +- stage: markdown_link + displayName: Markdown Link + dependsOn: [] + jobs: + - template: ./misc-analysis/generateMarkdownMatrix.yml parameters: - sourceScanPath: '$(repoPath)' + jobName: generateMatrix + taskName: matrixTask + - template: ./misc-analysis/markdown.yml + parameters: + matrix: $[ dependencies.generateMatrix.outputs['matrixTask.matrix'] ] + dependsOn: generateMatrix diff --git a/.vsts-ci/misc-analysis/generateMarkdownMatrix.yml b/.vsts-ci/misc-analysis/generateMarkdownMatrix.yml new file mode 100644 index 0000000000..56a43accd5 --- /dev/null +++ b/.vsts-ci/misc-analysis/generateMarkdownMatrix.yml @@ -0,0 +1,46 @@ +parameters: + - name: jobName + - name: taskName + +jobs: +- job: ${{ parameters.jobName }} + displayName: Generate Markdown Matrix + + pool: + vmImage: ubuntu-20.04 + + variables: + - name: repoPath + value: $(Agent.BuildDirectory)/$(repoFolder) + + steps: + - checkout: self + clean: true + path: $(repoFolder) + + - powershell: | + $matrix = @{} + $matrix += @{ + 'root' = @{ + markdown_folder = "$(repoPath)" + markdown_recurse = $false + } + } + Get-ChildItem -path '$(repoPath)' -Directory | Foreach-Object { + $folder = $_ + $matrix += @{ + $_.Name = @{ + markdown_folder = $_.fullName + markdown_recurse = $true + } + } + } + + $matrixJson = $matrix | ConvertTo-Json -Compress + $variableName = "matrix" + $command = "vso[task.setvariable variable=$variableName;isoutput=true]$($matrixJson)" + Write-Verbose "sending command: '$command'" + Write-Host "##$command" + displayName: Create Matrix + condition: succeededOrFailed() + name: ${{ parameters.taskName }} diff --git a/.vsts-ci/misc-analysis/markdown.yml b/.vsts-ci/misc-analysis/markdown.yml new file mode 100644 index 0000000000..5266f90cb4 --- /dev/null +++ b/.vsts-ci/misc-analysis/markdown.yml @@ -0,0 +1,63 @@ +parameters: + - name: matrix + - name: dependsOn + +jobs: +- job: markdown + strategy: + matrix: ${{ parameters.matrix }} + maxParallel: 5 + + displayName: Markdown Link Verification + + dependsOn: ${{ parameters.dependsOn }} + + pool: + vmImage: ubuntu-20.04 + + variables: + - name: repoPath + value: $(Agent.BuildDirectory)/$(repoFolder) + - name: YARN_CACHE_FOLDER + value: $(Pipeline.Workspace)/.yarn + - name: YARN_GLOBAL_CACHE_FOLDER + value: $(Pipeline.Workspace)/.yarn-global + + steps: + - checkout: self + clean: true + path: $(repoFolder) + + - checkout: ComplianceRepo + + - task: Cache@2 + inputs: + key: '"markdown-link-check" | "$(Agent.OS)" | $(repoPath)/test/common/markdown-link/markdown-link.tests.ps1' + path: $(YARN_GLOBAL_CACHE_FOLDER) + displayName: Cache Yarn packages + + - powershell: | + Install-module Pester -Scope CurrentUser -Force -MaximumVersion 4.99 + displayName: Install Pester + + - bash: | + curl -o- --progress-bar -L https://yarnpkg.com/install.sh | bash + displayName: Bootstrap Yarn + + - bash: | + yarn config set global-folder "$(YARN_GLOBAL_CACHE_FOLDER)" + displayName: Set Yarn global cache folder + + - ${{ if not(contains(variables['SYSTEM.COLLECTIONURI'],'mscodehub')) }}: + - pwsh: | + Import-module ./build.psm1 + $path = Join-Path -Path $pwd -ChildPath './commonTestResults.xml' + $results = invoke-pester -Script ./test/common/markdown-link -OutputFile $path -OutputFormat NUnitXml -PassThru + Write-Host "##vso[results.publish type=NUnit;mergeResults=true;runTitle=Markdown Link;publishRunAttachments=true;resultFiles=$path;]" + if($results.TotalCount -eq 0 -or $results.FailedCount -gt 0) + { + throw "Markdown tests failed" + } + displayName: Run Markdown Link Tests + condition: succeededOrFailed() + workingDirectory: '$(repoPath)' diff --git a/.vsts-ci/misc-analysis/mdSpell.yml b/.vsts-ci/misc-analysis/mdSpell.yml new file mode 100644 index 0000000000..e07b475696 --- /dev/null +++ b/.vsts-ci/misc-analysis/mdSpell.yml @@ -0,0 +1,56 @@ +jobs: +- job: markdown + displayName: Markdown Spelling + + pool: + vmImage: ubuntu-20.04 + + variables: + - name: repoPath + value: $(Agent.BuildDirectory)/$(repoFolder) + + steps: + - checkout: self + clean: true + path: $(repoFolder) + + - checkout: ComplianceRepo + + - powershell: | + Get-ChildItem -Path env: + displayName: Capture Environment + condition: succeededOrFailed() + + - bash: | + curl -o- --progress-bar -L https://yarnpkg.com/install.sh | bash + displayName: Bootstrap Yarn + condition: succeededOrFailed() + + - bash: | + sudo yarn global add markdown-spellcheck@0.11.0 + displayName: Install mdspell + condition: succeededOrFailed() + + - bash: | + mdspell '**/*.md' '!**/Pester/**/*.md' '!**/dotnet-tools/**/*.md' --ignore-numbers --ignore-acronyms --report --en-us; + displayName: Test Spelling in Markdown + condition: succeededOrFailed() + workingDirectory: '$(repoPath)' + + - ${{ if not(contains(variables['SYSTEM.COLLECTIONURI'],'mscodehub')) }}: + - pwsh: | + Import-module ./build.psm1 + $path = Join-Path -Path $pwd -ChildPath './commonTestResults.xml' + $results = invoke-pester -Script ./test/common/markdown-lint -OutputFile $path -OutputFormat NUnitXml -PassThru + Write-Host "##vso[results.publish type=NUnit;mergeResults=true;runTitle=Markdown Lint;publishRunAttachments=true;resultFiles=$path;]" + if($results.TotalCount -eq 0 -or $results.FailedCount -gt 0) + { + throw "Markdown tests failed" + } + displayName: Run Markdown Lint Tests + condition: succeededOrFailed() + workingDirectory: '$(repoPath)' + + - template: dailyBuildCompliance.yml@ComplianceRepo + parameters: + sourceScanPath: '$(repoPath)' diff --git a/test/common/markdown/markdown-link.tests.ps1 b/test/common/markdown-link/markdown-link.tests.ps1 similarity index 92% rename from test/common/markdown/markdown-link.tests.ps1 rename to test/common/markdown-link/markdown-link.tests.ps1 index 4339c0174a..96c101afd4 100644 --- a/test/common/markdown/markdown-link.tests.ps1 +++ b/test/common/markdown-link/markdown-link.tests.ps1 @@ -25,7 +25,18 @@ Describe "Verify Markdown Links" { Get-Job | Remove-Job -Force } - $groups = Get-ChildItem -Path "$PSScriptRoot\..\..\..\*.md" -Recurse | Where-Object {$_.DirectoryName -notlike '*node_modules*'} | Group-Object -Property directory + $gciParams = @{} + if ($env:MARKDOWN_FOLDER) { + $gciParams["Path"] = (Join-Path -Path $env:MARKDOWN_FOLDER -ChildPath '*.md') + } else { + $gciParams["Path"] = "$PSScriptRoot\..\..\..\*.md" + } + + if ($env:MARKDOWN_RECURSE -ne 'False') { + $gciParams["Recurse"] = $true + } + + $groups = Get-ChildItem @gciParams | Where-Object {$_.DirectoryName -notlike '*node_modules*'} | Group-Object -Property directory $jobs = @{} # start all link verification in parallel diff --git a/test/common/markdown/.gitignore b/test/common/markdown-lint/.gitignore similarity index 100% rename from test/common/markdown/.gitignore rename to test/common/markdown-lint/.gitignore diff --git a/test/common/markdown/gulpfile.js b/test/common/markdown-lint/gulpfile.js similarity index 100% rename from test/common/markdown/gulpfile.js rename to test/common/markdown-lint/gulpfile.js diff --git a/test/common/markdown/markdown.tests.ps1 b/test/common/markdown-lint/markdown.tests.ps1 similarity index 100% rename from test/common/markdown/markdown.tests.ps1 rename to test/common/markdown-lint/markdown.tests.ps1 diff --git a/test/common/markdown/package.json b/test/common/markdown-lint/package.json similarity index 100% rename from test/common/markdown/package.json rename to test/common/markdown-lint/package.json diff --git a/test/common/markdown/yarn.lock b/test/common/markdown-lint/yarn.lock similarity index 100% rename from test/common/markdown/yarn.lock rename to test/common/markdown-lint/yarn.lock