function Get-RepoPath { <# .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. .Parameter SubPath An optional string array of sub directories relative to the root. .INPUTS [None] No pipeline input. .OUTPUTS [DroneHelper.Repo.Path] Returns a folder structured like object with relevant full paths.s .EXAMPLE Import-Module -Name DroneHelper; Get-RepoPath #> [CmdletBinding()] [OutputType('DroneHelper.Repo.Path')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSUseConsistentWhitespace', '', Justification = 'Hashtable bug in ScriptAnalyzer 1.19.1' )] param ( [Parameter(Mandatory = $false)] [ValidateNotNullOrEmpty()] [String[]]$SubPath ) process { $root = Split-Path -Path (Get-GitDirectory) $BaseName = Get-Item -Path ('{0}/src/*.psd1' -f $root) | Select-Object -ExpandProperty 'BaseName' $failureLogPath = Join-Path -Path $root -ChildPath 'failure.log' # *.psd1 related $manifestPath = Join-Path -Path $root -ChildPath 'src/*.psd1' $manifest = Get-Item -Path $manifestPath # *.psm1 related $scriptModulePath = Join-Path -Path $root -ChildPath 'src/*.psm1' $scriptModule = Get-Item -Path $scriptModulePath # Subdir related $srcPath = Join-Path -Path $root -ChildPath 'src' $binPath = Join-Path -Path $root -ChildPath 'bin' $buildPath = Join-Path -Path $root -ChildPath 'build' $resourcePath = Join-Path -Path $root -ChildPath 'resources' # bin + build artifact related $mergedScriptModulePath = Join-Path -Path $binPath -ChildPath $scriptModule.Name $artifactName = '{0}.zip' -f $BaseName $artifactPath = Join-Path -Path $binPath -ChildPath $artifactName $expandPath = Join-Path -Path $binPath -ChildPath $BaseName # iteration through the optional sub paths $formatPath = Join-Path -Path $srcPath -ChildPath 'Formats/' $cachePath = Join-Path -Path $srcPath -ChildPath 'Cache/' $docsPath = Join-Path -Path $root -ChildPath 'docs' $modulePagePath = Join-Path -Path $docsPath -ChildPath 'README.md' $docsMarkdownFilter = Join-Path -Path $docsPath -ChildPath '*.md' $subDir = @{} foreach ($dir in $SubPath) { $subDir.$dir = Join-Path -Path $root -ChildPath $dir } $changelogPath = Join-Path -Path $root -ChildPath 'CHANGELOG.md' $changelogExits = Test-Path -Path $changelogPath $ps1Filter = Join-Path -Path $srcPath -ChildPath '*.ps1' $pesterLogPath = Join-Path -Path $buildPath -ChildPath 'Pester-Results.log' $scriptAnalyzerLogPath = Join-Path -Path $buildPath -ChildPath 'ScriptAnalyzer-Results.log' $fileLinterLogPath = Join-Path -Path $buildPath -ChildPath 'FileLinter-Results.log' $scriptAnalyzerSettingsPath = Join-Path -Path $resourcePath -ChildPath 'PSScriptAnalyzerSettings.psd1' # DroneHelper Module specific $droneModuleBase = $MyInvocation.MyCommand.Module.ModuleBase $PathParams = @{ Path = $droneModuleBase ChildPath = 'Rules/PSScriptAnalyzerSettings.psd1' } $droneAnalyzerDefaultPath = Join-Path @PathParams if ($changelogExits) { $changelog = Get-Item -Path $changelogPath } else { $changelog = $null } $Path = [PSCustomObject]@{ Artifact = $BaseName Root = $root Src = [PSCustomObject]@{ Path = $srcPath Manifest = [PSCustomObject] @{ Path = $manifestPath Item = $manifest } ScriptModule = [PSCustomObject]@{ Path = $scriptModulePath Item = $scriptModule } Formats = [PSCustomObject]@{ Path = $formatPath Exists = Test-Path -Path $formatPath } Cache = [PSCustomObject]@{ Path = $cachePath Exists = Test-Path -Path $cachePath } PS1Filter = $ps1Filter } Bin = [PSCustomObject]@{ Path = $binPath ScriptModuleName = $mergedScriptModulePath ArtifactName = $artifactName ArtifactPath = $artifactPath ExpandPath = $expandPath } Build = [PSCustomObject]@{ Path = $buildPath PesterLogPath = $pesterLogPath ScriptAnalyzerLogPath = $scriptAnalyzerLogPath FileLinterLogPath = $fileLinterLogPath } Changelog = [PSCustomObject]@{ Path = $changelogPath Exists = $changelogExits Item = $changelog } Docs = [PSCustomObject]@{ Path = $docsPath ModulePagePath = $modulePagePath MarkdownFilter = $docsMarkdownFilter } DroneHelper = [PSCustomObject]@{ ModuleBase = $MyInvocation.MyCommand.Module.ModuleBase ScriptAnalyzerDefaultsPath = $droneAnalyzerDefaultPath } Resources = [PSCustomObject]@{ Path = $resourcePath ScriptAnalyzerSettingsPath = $scriptAnalyzerSettingsPath ScriptAnalyzerSettingsExist = Test-Path -Path $scriptAnalyzerSettingsPath } FailureLogPath = $failureLogPath SubDir = $subDir } $Path.PSObject.TypeNames.Insert(0, 'DroneHelper.Repo.Path') Write-Output -InputObject $Path } }