You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.8 KiB

<#
Tests the module manifest of the module built in NTFSSecurity\bin\Release: it passes Test-ModuleManifest,
ci: publish releases from CI on a version tag, starting with 5.0.0-rc1 Pushing a tag such as 5.0.0 or 5.0.0-rc1 on master now publishes the package that the build job built and tested to the PowerShell Gallery and creates the GitHub release with NTFSSecurity.zip. - New-ModulePackage.ps1 copies only the FileList files of the Release build, so no debug symbols, XML documentation, or copy of System.Management.Automation.dll ship. It builds the nupkg with Compress-PSResource and adds the command tags (PSIncludes_Cmdlet, PSCmdlet_*, PSCommand_*) that PSResourceGet leaves out and that the Gallery uses to list cmdlets and that Find-Command searches. Every CI run builds and uploads the packages. - Get-ReleaseInfo.ps1 returns the version and release notes: a dated CHANGELOG section for a release, the [Unreleased] section for a prerelease. - The release job checks that the tag matches the manifest version and points to a commit on master, reads the API key from the environment powershell-gallery, and skips steps already done, so a rerun is safe. - The manifest gets the prerelease label rc1 and a release notes link; the 5.0.0 changelog entries move back to [Unreleased] until the final release. - Tests/Release.Tests.ps1 covers both scripts and the packages; the changelog check moves there from Manifest.Tests.ps1. - Docs/Contributing/05-Releasing.md describes the one-time setup and the release steps; Docs/README.md explains -AllowPrerelease. Co-authored-by: Copilot &lt;223556219+Copilot@users.noreply.github.com&gt; Co-authored-by: AI Assistant &lt;ai@example.com&gt;
4 weeks ago
exports exactly the cmdlets of the module, and carries the same version as the assemblies. Release.Tests.ps1
checks that CHANGELOG.md describes that version.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Pester shares variables between blocks.'
)]
param ()
BeforeDiscovery {
# The first-party assemblies of the module carry the module version; ProcessPrivileges is a vendored library.
$versionedAssemblies = 'NTFSSecurity', 'Security2', 'PrivilegeControl'
}
Describe 'Module manifest of NTFSSecurity' {
BeforeAll {
$manifestPath = Join-Path -Path $PSScriptRoot -ChildPath '..\NTFSSecurity\bin\Release\NTFSSecurity.psd1'
$manifest = Import-PowerShellDataFile -Path $manifestPath
$module = Import-Module -Name $manifestPath -Force -PassThru -ErrorAction Stop |
Where-Object -Property Name -EQ -Value 'NTFSSecurity'
}
AfterAll {
Remove-Module -Name NTFSSecurity -Force -ErrorAction SilentlyContinue
}
It 'Should pass Test-ModuleManifest without errors or warnings' {
$testParameters = @{
Path = $manifestPath
ErrorVariable = 'manifestErrors'
WarningVariable = 'manifestWarnings'
ErrorAction = 'SilentlyContinue'
WarningAction = 'SilentlyContinue'
}
$null = Test-ModuleManifest @testParameters
@($manifestErrors) + @($manifestWarnings) | ForEach-Object -Process { "$_" } | Should -BeNullOrEmpty
}
It 'Should list each cmdlet only once in CmdletsToExport' {
$duplicates = $manifest.CmdletsToExport | Group-Object | Where-Object -Property Count -GT -Value 1
$duplicates.Name | Should -BeNullOrEmpty
}
It 'Should list only cmdlets of the module in CmdletsToExport' {
$manifest.CmdletsToExport | Where-Object -FilterScript { -not $module.ExportedCmdlets.ContainsKey($_) } |
Should -BeNullOrEmpty
}
It 'Should export exactly 36 cmdlets' {
@($manifest.CmdletsToExport) | Should -HaveCount 36
$module.ExportedCmdlets.Keys | Should -HaveCount 36
}
Context 'Version' {
It 'Should give <_>.dll the module version' -ForEach $versionedAssemblies {
$assemblyPath = Join-Path -Path $module.ModuleBase -ChildPath "$_.dll"
$assemblyVersion = [Reflection.AssemblyName]::GetAssemblyName($assemblyPath).Version
$fileVersion = [version] (Get-Item -LiteralPath $assemblyPath).VersionInfo.FileVersion
$assemblyVersion.ToString(3) | Should -BeExactly $manifest.ModuleVersion
$fileVersion.ToString(3) | Should -BeExactly $manifest.ModuleVersion
}
}
}