PowerStig/.build/tasks/Custom.NugetPackage.Task.ps1

177 строки
5.9 KiB
PowerShell
Исходник Постоянная ссылка Обычный вид История

4.5.0 PR to Dev for Release (#733) * Migrate PowerSTIG to Azure DevOps for Build and Test (#603) * update folder structure for azure dev ops * dscresource unit test passing * updated unit tests * Unit test pathing update, all passing * updated unit test to ensure regex data files are loaded * updated .tests.header for unit\tools directory * daily commit - Integrated test updates * updated tests based on testing feedback * optimized test header based on feedback * updated build.psd1 case sensitive * update build agent to windows-2019 * update build and azure yml files * added hqrm tests to build yml and dependencies * updated azure-pipelines.yml to include hqrm test * updated HRQM display name * updated test exclusion DSCResources * intro logic to dynamically build requiredmodules * updated yml to reflect master * updated changelog.md * Update azure-pipelines.yml * rename sources to source (#605) * Migrate PowerSTIG to Azure DevOps for Build, Test and Release Deployment (#606) * updated powerstig for dynamic versioning * updated gitversion to reflect base version * updated if statement to adhere to style gls * updated code to adhere to sgl hqrmtest * updated code to adhere to sgl hqrm tests * updated code to adhere to sgl hqrm * update yml files to support CICD pipeline * updated markdown function * update change log structure * updated spacing via PR feedback * updated 2012R2 STIG after convert tests reflected a minor delta * Update PowerSTIG to parse and apply Vmware Vsphere 6.5 STIG V1R3 (#607) * initial commit for vsphere * updated based on test results * updated based on vsphere module name * updated module manifest to check build status * updated newlines in raw xccdf * updated newline * updated newlies in rules * updated tests * updated processed Stig name * updated vsphere schema * updated composites * updated spacing * updated format * Updated based on feedback * update required parameter for composite * updated service rule * Added Integration DSCresrouce Vsphere Test * reverted changes to test * updated integration tests * added unit tests * added unit tests * added unit tests * updated formatting based on feedback * updated based on feedback * updated comments * updated tests * updated changelog.md * trailing whitespace removed * updated for HQRM tests * updated based on pr feedback * updated case * update code based on PR feedback * updated code based on PR feedback. * updated tests based on PR feedback * updated test based on PR feedback Co-authored-by: Brian Wilhite <bcwilhite@live.com> * Unable to Import PowerSTIG 4.4.0 Due to cyclic dependency Error (#617) * removed vmware.vspheredsc as a dependency because all of its required dependencies are loaded * updated module load process for VMware modules * updated build.yaml * updated test * Updated tests * removed stop error action * updated formating * updated based on failing hqrm * updated module helper * moved helper module * updated location of module helper * reduced vmware.VsphereDSC version * updated build.yaml * updated data file * update module version schema * updated based on testing * Update changelog * Update based on PR feedback * Update PowerSTIG to successfully parse/apply Microsoft IIS Server/Site STIG - Ver 1, Rel10 (#623) * added IIS Server V1R10 * updated changelog and added iis site v1r10 * updated changelog * removed N-2 STIGS * Update PowerSTIG to successfully parse Microsoft SQL Server 2012 Database STIG - Ver 1, Rel 20 (#621) * updated PowerSTIG to use SQL 2012 Database V1R20 * quotes in test * updated tabs to spaces in sql raw xccdf Co-authored-by: Brian Wilhite <bcwilhite@live.com> * explicit Pester version due to 5.x (latest) test failures * Update PowerSTIG to successfully parse/apply Windows Defender Antivirus STIG - V1R8 (#626) * added new Windows Defender STIG V1R8 removed V1R6 * updated based on PR feedback: * merged origin Co-authored-by: Brian Wilhite <bcwilhite@live.com> * initial commit (#640) Co-authored-by: Brian Wilhite <bcwilhite@live.com> * Update PowerSTIG to successfully parse/apply Microsoft IIS 10 Server/Site STIG - V1R1 (#641) * added IIS 10.0 Server * updated IIS 10 site stig * updated based on tests * updated based on tests * updated log file * added esxi 6.5 v1r4 (#637) Co-authored-by: Brian Wilhite <bcwilhite@live.com> * Update PowerSTIG to successfully parse/apply Windows Server 2012 DNS STIG - Ver 1, Rel 14 (#635) * DNS Update commit * removed DNS 1.12 * explicit version for DscResource.Test * Update PowerSTIG to allow for workgroup level scans (#643) * added community requested functionality to not require domain/forest parameters * updated warning message * reverted to old module dscresource.test * Updated based on feedback * updated sql 2016 instance 1.9 (#638) * Update PowerSTIG to successfully parse/apply MS SQL Server 2012 Instance Ver. 1 Rel. 20 (#642) * updated sql 2012 Instance V1R20 * updated Get-SqlTechnologyRole * removed tabs * added a new line to the end of xccdf * update build to use dscresource.test 0.13.1 * updated code based on feedback * Initial updates for checklist improvements * updated sql script query rule and test to take multiple db's withouth conflict * updated based on testing * First working version - multi-STIGs per checklist * Backward compatibility support added for checklist * Updates to formatting * log file update for IE rule bug * updated change log * added new line to the end of the log files * Updated based on pr feedback * Updated for Pester testing. * Update PowerSTIG to successfully parse/apply Windows 10 STIG - V1R21 (#656) * Updated to support latest WIN10 STIG * update 1.19 to remove extra slash for bug * Polishing for PR * Polishing for PR * Update to CHANGELOG.md * Updated for formatting * Formatting updates for PR * Update for formatting * Updates to formatting for PR * Formatting for PR * update changelog * Updates for PR * updated manifest * Fixed Missing OrgSettings for V-88203 - Win10 Client 1.19 and 1.21 (#672) * fixed V-88203 to be org setting with Tenant Guid * updated changelog.md * fixed registry rule issue in sql 2016 (#671) * Release Process Update: Ensure the nuget package uses explicit DSC Resource Module Versions (#670) * dialy commit * updated build task to leverage nuget * added new line for Common.Data.ps1 * warning message to troubleshoot ADO pipeline * updated package tasks * updated release.module.build * updated module * updated release * updated release * updated release * hard coded nuget.exe path * fixed FilePath parameter * dynamically detect nuget.exe * nuget dynamic detection * testing alternate nuget detection * updated release to leverage get-command for nuget detection * updated code to replace only the task needed * updated build funct. conform to style guideline * updated New-NuspecFile funciton * Update PowerSTIG to successfully parse/apply Windows 2012 R2 MS Version 2, Rev 19 (#679) * added support for 2012 R2 V2R19 * added new line to xml * added Server 2019 V1R5,removed V1R2 (#684) * Update PowerSTIG to successfully parse/apply Windows 10 STIG - V1R23 (#682) * Added Windows Client V1R23, Removed Windows CLient V1R19 * Added Windows Client V1R23, Removed Windows CLient V1R19 * removed random tabs * removed tabs from converted * updated based on feedback Co-authored-by: Brian Wilhite <bcwilhite@live.com> * added support for 2016 V1R12 DC/MS (#685) * Fixed: IIS Sever 10.0 STIG hardening rule V-100163 fails with error in Windows Server 2019 while using PowerSTIG 4.4.2 (#689) * updated PowerSTIG to use AccessControlDsc 1.4.1 * updated composites with AccessControlDsc 1.4.1 * Update PowerSTIG to successfully parse/apply IIS 10.0 Site/Server V1R2 STIGs (#701) * added support for IIS 10 Site/Server V1R2 * updated IISServer 10 V1R1 org settings file * Revert "updated IISServer 10 V1R1 org settings file" This reverts commit 54d4e827de8b7cbb588b615a9aeecc48d015c34e. * added Firefox V4R29 STIG, remove V4R27 (#700) Co-authored-by: Brian Wilhite <bcwilhite@live.com> * Update PowerSTIG to successfully parse/apply SQL Server 2016 Instance V1R10 (#705) * added SQL 2016 Instance V1R10, removed V1R8 * Updated changelog.md Co-authored-by: Brian Wilhite <bcwilhite@live.com> * added dns V1R15 (#697) squash/merge * Update PowerSTIG To Use xDnsServer version 1.16.0.0 (#703) * Updated xDnsServer version * update module version * updated changelog.md * upgrade xWebadministration to 3.2.0 (#714) * added IE 11 STIG - V1R19 (#708) * Removed Windows Server 2016 DC/MS V1R9 from processed STIGs folder (#710) * removed old 2016 DC/MS processed STIGs * updated changelog.md * Update PowerSTIG to successfully parse/apply IIS Site/Server V1R11 STIGs (#706) * added support for IIS site/server V1R11 * removed old processed STIGs * updated AuditPolicyDsc to 1.4.0.0 (#716) * Allow application of applicable user rights assignments for non-domain and disconnected systems (#719) * updated based on community feedback * update based on feedback * update powerstig to use SecurityPolicyDsc 2.10.0.0 (#717) * Updates to Checklisting * updated PowerSTIG to use ComputerMgmtDsc to 8.4.0 (#721) * Minor updates for PR * Minor update for PR * Updates to parameters * Minor update for Registry rule checklist output * Update PowerSTIG to use PSDSCResources 2.12.0.0 (#726) * updated PSDSCResources to 2.12.0.0 * kick devops * updated * update revert * Parameter name swap * Updated PowerSTIG to use FileContentDsc 1.3.0.151 (#725) * Minor update to parameter * Update WindowsDefenderDSC Version to Latest (2.0.0) (#728) * initial commit * updated spacing * updated format of composite * converted server 2019 stigs * update changelog.md * updated windows defenderdsc * updated integration tests * updated integration tests * Update tests * updated based on tests * updated based on feedback Co-authored-by: Brian Wilhite <bcwilhite@live.com> * Removed ChecklistSTIGfiles.txt * Update PowerSTIG to successfully parse/apply Windows 2012 R2 DC Version 2, Rev 21 (#727) * updated DC and MS STIGS * removed tabs * added newline * updated based on testing * updated after merge * Restored code to load manual check file * Case update for PR * Updates to formatting per style guide * updated style guidelines * updated based on testing (#732) * updated to not include system drives (#736) * changelog.md and filehash.md release update Co-authored-by: Eric Jenkins <erjenkin@microsoft.com> Co-authored-by: Steve Hose <33662177+stevehose@users.noreply.github.com>
2020-09-01 20:47:19 +03:00
param(
# Base directory of all output (default to 'output')
[Parameter()]
[string]
$OutputDirectory = (property OutputDirectory (Join-Path $BuildRoot 'output')),
[Parameter()]
[string]
$ChangelogPath = (property ChangelogPath 'CHANGELOG.md'),
[Parameter()]
[string]
$ReleaseNotesPath = (property ReleaseNotesPath (Join-Path $OutputDirectory 'ReleaseNotes.md')),
[Parameter()]
[string]
$ProjectName = (property ProjectName $(
#Find the module manifest to deduce the Project Name
(
Get-ChildItem $BuildRoot\*\*.psd1 -Exclude 'build.psd1', 'analyzersettings.psd1' |
Where-Object {
($_.Directory.Name -match 'source|src' -or $_.Directory.Name -eq $_.BaseName) -and
$(
try
{
Test-ModuleManifest $_.FullName -ErrorAction Stop
}
catch
{
Write-Warning $_
$false
}
)
}
).BaseName
)
),
[Parameter()]
[string]
$ModuleVersion = (
property ModuleVersion $(
try
{
(gitversion | ConvertFrom-Json -ErrorAction Stop).NuGetVersionV2
}
catch
{
Write-Verbose "Error attempting to use GitVersion $($_)"
''
}
)
),
[Parameter()]
[string]
# retrieves from Environment variable
$GitHubToken = (property GitHubToken ''),
[Parameter()]
[string]
$GalleryApiToken = (property GalleryApiToken ''),
[Parameter()]
[string]
$NuGetPublishSource = (property NuGetPublishSource 'https://www.powershellgallery.com/'),
[Parameter()]
$PSModuleFeed = (property PSModuleFeed 'PSGallery'),
[Parameter()]
$SkipPublish = (property SkipPublish '')
)
Import-Module -Name "$PSScriptRoot/Custom.Functions.psm1"
# Synopsis: Packaging the module by Publishing to output folder (incl dependencies)
task package_module_nupkg {
# Force registering the output repository mapping to the Project's output path
$null = Unregister-PSRepository -Name output -ErrorAction SilentlyContinue
$repositoryParams = @{
Name = 'output'
SourceLocation = $OutputDirectory
PublishLocation = $OutputDirectory
ErrorAction = 'Stop'
}
$null = Register-PSRepository @repositoryParams
# Cleaning up existing packaged module
$moduleToRemove = Get-ChildItem -Path (Join-Path -Path $OutputDirectory -ChildPath "$ProjectName.*.nupkg")
if ($null -ne $moduleToRemove)
{
Write-Build DarkGray " Remove existing $ProjectName package"
Remove-Item -Path $ModuleToRemove -Force -ErrorAction Stop
}
# find Module manifest
$builtModuleManifest = (Get-ChildItem -Path (Join-Path -Path $OutputDirectory -ChildPath $ProjectName) -Depth 2 -Filter "$ProjectName.psd1").FullName |
Where-Object {
try
{
Test-ModuleManifest -Path $_ -ErrorAction Stop
}
catch
{
$false
}
}
if (-not $builtModuleManifest)
{
throw "No valid manifest found for project $ProjectName."
}
Write-Build -Color DarkGray -Text " Built module's Manifest found at $builtModuleManifest"
# load module manifest
$moduleInfo = Import-PowerShellDataFile -Path $builtModuleManifest
# Publish dependencies (from environment) so we can publish the built module
foreach ($module in $moduleInfo.RequiredModules)
{
if (
-not ([Microsoft.PowerShell.Commands.ModuleSpecification]$module |
Find-Module -Repository output -ErrorAction SilentlyContinue)
)
{
# Replace the module by first (path & version) resolved in PSModulePath
$module = Get-Module -ListAvailable -FullyQualifiedName $module | Select-Object -First 1
if ($null -ne $module.PrivateData.PSData.Prerelease)
{
$Prerelease = "-" + $module.PrivateData.PSData.Prerelease
}
$writeBuildText = " Packaging Required Module {0} v{1}{2}" -f $Module.Name, $Module.Version.ToString(), $Prerelease
Write-Build -Color Yellow -Text $writeBuildText
Publish-Module -Repository output -Path $module.ModuleBase -ErrorAction SilentlyContinue
}
}
Write-Build -Color DarkGray -Text " Creating nuspec file"
$projectPath = Join-Path -Path $OutputDirectory -ChildPath $ProjectName
$manifestFileName = '{0}.psd1' -f $ProjectName
$moduleManifestPath = Get-ChildItem -Path $projectPath -Filter $manifestFileName -Recurse
$newNuspecFileParams = @{
ModuleManifestPath = $moduleManifestPath.FullName
DestinationPath = $OutputDirectory
}
$projectNuspecFile = New-NuspecFile @newNuspecFileParams
$nugetResults = Get-Command -Name nuget.exe | Select-Object -First 1
$nugetFilePath = $nugetResults.Source
Write-Build -Color DarkGray -Text " nuget Path: $($nugetFilePath)"
if ((Test-Path -Path $nugetFilePath) -eq $false)
{
throw "nuget.exe not found, aborting task package_module_nupkg"
}
else
{
$startProcessNugetParams = @{
FilePath = $nugetFilePath
Wait = $true
ArgumentList = @(
'Pack', $projectNuspecFile
'-OutputDirectory', $OutputDirectory
)
}
Start-Process @startProcessNugetParams
Write-Build -Color Green -Text " Packaged $ProjectName NuGet package"
}
Write-Build -Color DarkGray -Text " Cleaning up"
$null = Unregister-PSRepository -Name output -ErrorAction SilentlyContinue
}