# Builds the NTFSSecurity module from source, checks that the cmdlet # documentation in Docs/Cmdlets and the help file generated from it match the # cmdlets of that build, and runs the Pester tests against the build. image: Visual Studio 2022 init: - ps: git config --global core.autocrlf true install: - ps: | [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | Out-Null Install-Module -Name platyPS -RequiredVersion 0.14.2 -Force Install-Module -Name MarkdownLinkCheck -RequiredVersion 0.2.0 -Force # The image includes Pester 3.4.0, which is signed by a different publisher. Install-Module -Name Pester -RequiredVersion 5.7.1 -Force -SkipPublisherCheck before_build: - nuget restore NTFSSecurity\packages.config -PackagesDirectory packages -NonInteractive - nuget restore Security2\packages.config -PackagesDirectory packages -NonInteractive # Provides the .NET Framework 4.5.2 reference assemblies, so the build does # not depend on a targeting pack installed on the build image. - nuget install Microsoft.NETFramework.ReferenceAssemblies.net452 -Version 1.0.3 -OutputDirectory packages -NonInteractive build_script: - ps: | $referenceAssemblies = "$env:APPVEYOR_BUILD_FOLDER\packages\Microsoft.NETFramework.ReferenceAssemblies.net452.1.0.3\build" msbuild NTFSSecurity\NTFSSecurity.csproj /nologo /verbosity:minimal /p:Configuration=Release "/p:TargetFrameworkRootPath=$referenceAssemblies" "/p:FrameworkPathOverride=$referenceAssemblies\.NETFramework\v4.5.2" if ($LASTEXITCODE -ne 0) { throw "MSBuild failed with exit code $LASTEXITCODE." } test_script: - ps: | $ErrorActionPreference = 'Stop' Import-Module -Name platyPS Import-Module -Name MarkdownLinkCheck Import-Module -Name .\NTFSSecurity\bin\Release\NTFSSecurity.psd1 -Force # 01. Test that the documentation matches the cmdlets built from source Update-MarkdownHelp -Path ./Docs/Cmdlets | Out-Null $diff = git diff -- Docs/Cmdlets if ($diff) { throw "Help is not up-to-date, run Update-MarkdownHelp: $diff" } # 02. Verify hyperlinks $brokenLinks = Get-MarkdownLink -Path .\Docs\ -BrokenOnly if ($brokenLinks) { throw "Found broken hyperlinks $brokenLinks" } # 03. Test that the help file of the module matches the documentation New-ExternalHelp -Path ./Docs/Cmdlets -OutputPath ./NTFSSecurity/en-US -Force | Out-Null $helpChanges = git status --porcelain -- NTFSSecurity/en-US if ($helpChanges) { throw "The help file is not up-to-date, run New-ExternalHelp -Path .\Docs\Cmdlets -OutputPath .\NTFSSecurity\en-US -Force: $helpChanges" } # 04. Run the Pester tests against the module build Import-Module -Name Pester -RequiredVersion 5.7.1 $configuration = New-PesterConfiguration $configuration.Run.Path = '.\Tests' $configuration.Run.PassThru = $true $configuration.Output.Verbosity = 'Detailed' $result = Invoke-Pester -Configuration $configuration # Report every test once on the Tests tab. An uploaded NUnit file lists a # Pester 5 test once for each block that contains it. if ($env:APPVEYOR_API_URL -and $result.Tests) { $tests = @(foreach ($test in $result.Tests) { @{ testName = $test.ExpandedPath testFramework = 'Pester' fileName = Split-Path -Path $test.ScriptBlock.File -Leaf outcome = if ($test.Result -eq 'NotRun') { 'NotRunnable' } else { "$($test.Result)" } durationMilliseconds = [long] $test.Duration.TotalMilliseconds ErrorMessage = @($test.ErrorRecord | ForEach-Object -Process { "$_" }) -join [Environment]::NewLine } }) $body = [Text.Encoding]::UTF8.GetBytes((ConvertTo-Json -InputObject $tests -Compress)) Invoke-RestMethod -Method Post -Uri ($env:APPVEYOR_API_URL.TrimEnd('/') + '/api/tests/batch') -Body $body -ContentType 'application/json; charset=utf-8' | Out-Null } if ($result.FailedCount -gt 0) { throw "$($result.FailedCount) Pester tests failed." }