initial migration
Some checks reported errors
continuous-integration/drone/tag Build was killed

This commit is contained in:
2022-07-13 13:59:25 +02:00
parent 97761f112c
commit 8fd180b776
80 changed files with 3997 additions and 1 deletions

View File

@ -0,0 +1,21 @@
BeforeAll {
$Repo = Get-RepoPath
Import-Module $Repo.Src.Manifest.Item.FullName -Force
}
Describe 'Merge-ModuleRoot' {
Context 'Default tests' -Tag 'Default' {
It 'Test Function' {
{ Get-Command -Name 'Merge-ModuleRoot' -Module $Repo.Artifact } | Should -Not -Throw
}
It 'Test Help' {
{ Get-Help -Name 'Merge-ModuleRoot' } | Should -Not -Throw
}
It 'Help Content' {
$foo = Get-Help -Name 'Merge-ModuleRoot'
$foo.Synopsis.Length | Should -BeGreaterThan 5
$foo.Description.Count | Should -BeGreaterOrEqual 1
$foo.Description[0].Text.Length | Should -BeGreaterThan 5
}
}
}

View File

@ -0,0 +1,42 @@
function Merge-ModuleRoot {
<#
.SYNOPSIS
Merges single ps1 files into one module script file.
.DESCRIPTION
This Cmdlet is used in build pipeline to reduce the file load and import performance to the target module.
.INPUTS
[None] No pipeline input.
.OUTPUTS
[None] No pipeline output.
.EXAMPLE
Import-Module -Name DroneHelper; Merge-ModuleRoot
#>
[CmdletBinding()]
param ()
process {
$Repo = Get-RepoPath
$srcFiles = Get-ChildItem -Path $Repo.Src.Path -Recurse -File | Where-Object {
($_.Name -notmatch '.Tests.') -and ($_.Name -match '.ps1') -and ($_.Name -notmatch '.ps1xml')
}
$Output = @()
foreach ($psFile in $srcFiles) {
$fileContent = Get-Content -Path $psFile.FullName -Raw -Encoding 'utf8'
$Output += '# srcFile: {0}' -f $psFile.FullName
$Output += $fileContent.TrimEnd()
$Output += '{0}' -f [Environment]::NewLine
}
try {
$Output | Out-File -FilePath $Repo.Bin.ScriptModuleName -Encoding 'utf8' -Force -ErrorAction Stop
}
catch {
Write-FailureStateFile -StepName 'MergeModuleRoot'
throw 'Could not write the final module root script file!'
}
}
}

View File

@ -0,0 +1,21 @@
BeforeAll {
$Repo = Get-RepoPath
Import-Module $Repo.Src.Manifest.Item.FullName -Force
}
Describe 'New-BuildPackage' {
Context 'Default tests' -Tag 'Default' {
It 'Test Function' {
{ Get-Command -Name 'New-BuildPackage' -Module $Repo.Artifact } | Should -Not -Throw
}
It 'Test Help' {
{ Get-Help -Name 'New-BuildPackage' } | Should -Not -Throw
}
It 'Help Content' {
$foo = Get-Help -Name 'New-BuildPackage'
$foo.Synopsis.Length | Should -BeGreaterThan 5
$foo.Description.Count | Should -BeGreaterOrEqual 1
$foo.Description[0].Text.Length | Should -BeGreaterThan 5
}
}
}

View File

@ -0,0 +1,74 @@
function New-BuildPackage {
<#
.SYNOPSIS
Creates a new module package as compressed archive.
.DESCRIPTION
This function is used in build pipeline to create an uploadable module version for the Gitea release page.
.PARAMETER AdditionalPath
You can provide additional paths to add files or folders in published module.
.INPUTS
[None] No pipeline input.
.OUTPUTS
[None] No pipeline output.
.EXAMPLE
Import-Module -Name DroneHelper; New-BuildPackage
#>
[CmdletBinding()]
[OutputType()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseConsistentWhitespace',
'',
Justification = 'Hashtable bug in ScriptAnalyzer 1.19.1'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions',
'',
Justification = 'system state does not change permanent in temp build clients.'
)]
param (
[Parameter(Mandatory = $false)]
[String[]]$AdditionalPath
)
process {
$Repo = Get-RepoPath
$res = @()
foreach ($item in $AdditionalPath) {
try {
$res += Resolve-Path -Path $item -ErrorAction Stop
}
catch {
Write-Error -Message ('The given additional path does not exist! ({0})' -f $item) -ErrorAction Stop
}
}
Merge-ModuleRoot -ErrorAction Stop
$CompressParams = @{
Path = @(
# psm1 file
$Repo.Bin.ScriptModuleName
# psd1 file
$Repo.Src.Manifest.Item.FullName
# Formats/ folder
$Repo.Src.Formats.Path
)
DestinationPath = $Repo.Bin.ArtifactPath
Force = $true
ErrorAction = 'Stop'
Verbose = $VerbosePreference
}
$CompressParams.Path += $res
try {
Compress-Archive @CompressParams
}
catch {
Write-FailureStateFile -StepName 'BuildPackage'
throw $_.Exception.Message
}
}
}

View File

@ -0,0 +1,21 @@
BeforeAll {
$Repo = Get-RepoPath
Import-Module $Repo.Src.Manifest.Item.FullName -Force
}
Describe 'Update-ModuleMeta' {
Context 'Default tests' -Tag 'Default' {
It 'Test Function' {
{ Get-Command -Name 'Update-ModuleMeta' -Module $Repo.Artifact } | Should -Not -Throw
}
It 'Test Help' {
{ Get-Help -Name 'Update-ModuleMeta' } | Should -Not -Throw
}
It 'Help Content' {
$foo = Get-Help -Name 'Update-ModuleMeta'
$foo.Synopsis.Length | Should -BeGreaterThan 5
$foo.Description.Count | Should -BeGreaterOrEqual 1
$foo.Description[0].Text.Length | Should -BeGreaterThan 5
}
}
}

View File

@ -0,0 +1,75 @@
function Update-ModuleMeta {
<#
.SYNOPSIS
Updates the module manifest file fields to prepare the new build.
.DESCRIPTION
Replaces the version fields in the manifest file. Uses Drone env vars populated by pushed tags.
.INPUTS
[None] No pipeline input.
.OUTPUTS
[None] No pipeline output.
.EXAMPLE
Import-Module -Name DroneHelper; Update-ModuleMeta
#>
[CmdletBinding()]
[OutputType()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseConsistentWhitespace',
'',
Justification = 'Hashtable bug in ScriptAnalyzer 1.19.1'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions',
'',
Justification = 'system state does not change permanent in temp build clients.'
)]
param ()
process {
if ($Env:DRONE) {
$Repo = Get-RepoPath
if ($Env:DRONE_BUILD_EVENT -eq 'tag') {
if ($null -ne $Env:DRONE_SEMVER) {
$nVersion = $Env:DRONE_SEMVER_SHORT
if ($null -ne $Env:DRONE_SEMVER_PRERELEASE) {
$nPreRelease = $Env:DRONE_SEMVER_PRERELEASE
}
$ModManifestParams = @{
Path = $Repo.Src.Manifest.Item.FullName
ModuleVersion = $nVersion
ErrorAction = 'Stop'
}
if ($nPreRelease) {
$ModManifestParams.PreRelease = $nPreRelease
}
$ManifestData = Test-ModuleManifest -Path $Repo.Src.Manifest.Item.FullName
if (
($nVersion -ne $ManifestData.Version) -or
($nVersion -ne $ManifestData.PrivateData.PSData.Prerelease)
) {
Update-ModuleManifest @ModManifestParams
}
else {
Write-Verbose -Message 'Identical version given. Skipping update.'
}
}
else {
Write-Verbose -Message 'Could not read the new Tag / Semver!'
}
}
else {
Write-Verbose -Message 'This pipeline was not triggered by a tag.'
}
}
else {
Write-Verbose -Message 'Running outside of drone.io pipeline. Skipping module update!'
}
}
}