Skip to content

Commit

Permalink
adding using statement to System.IO for build file
Browse files Browse the repository at this point in the history
  • Loading branch information
santisq committed Jun 5, 2024
1 parent 59cdf89 commit fd6cee2
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions PSCompression.build.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# I might've also stolen this from jborean93 ¯\_(ツ)_/¯
using namespace System.IO

# I might've also stolen this from jborean93 ¯\_(ツ)_/¯
[CmdletBinding()]
param(
[ValidateSet('Debug', 'Release')]
[string]
$Configuration = 'Debug'
)

$modulePath = [IO.Path]::Combine($PSScriptRoot, 'module')
$manifestItem = Get-Item ([IO.Path]::Combine($modulePath, '*.psd1'))
$modulePath = [Path]::Combine($PSScriptRoot, 'module')
$manifestItem = Get-Item ([Path]::Combine($modulePath, '*.psd1'))
$ModuleName = $manifestItem.BaseName

$testModuleManifestSplat = @{
Expand All @@ -17,13 +19,13 @@ $testModuleManifestSplat = @{
}
$Manifest = Test-ModuleManifest @testModuleManifestSplat
$Version = $Manifest.Version
$BuildPath = [IO.Path]::Combine($PSScriptRoot, 'output')
$PowerShellPath = [IO.Path]::Combine($PSScriptRoot, 'module')
$CSharpPath = [IO.Path]::Combine($PSScriptRoot, 'src', $ModuleName)
$ReleasePath = [IO.Path]::Combine($BuildPath, $ModuleName, $Version)
$BuildPath = [Path]::Combine($PSScriptRoot, 'output')
$PowerShellPath = [Path]::Combine($PSScriptRoot, 'module')
$CSharpPath = [Path]::Combine($PSScriptRoot, 'src', $ModuleName)
$ReleasePath = [Path]::Combine($BuildPath, $ModuleName, $Version)
$IsUnix = $PSEdition -eq 'Core' -and -not $IsWindows
$UseNativeArguments = $PSVersionTable.PSVersion -gt '7.0'
($csharpProjectInfo = [xml]::new()).Load((Get-Item ([IO.Path]::Combine($CSharpPath, '*.csproj'))).FullName)
($csharpProjectInfo = [xml]::new()).Load((Get-Item ([Path]::Combine($CSharpPath, '*.csproj'))).FullName)
$TargetFrameworks = @(@($csharpProjectInfo.Project.PropertyGroup)[0].
TargetFrameworks.Split(';', [StringSplitOptions]::RemoveEmptyEntries))
$PSFramework = $TargetFrameworks[0]
Expand All @@ -38,8 +40,8 @@ task Clean {

task BuildDocs {
$helpParams = @{
Path = [IO.Path]::Combine($PSScriptRoot, 'docs', 'en-US')
OutputPath = [IO.Path]::Combine($ReleasePath, 'en-US')
Path = [Path]::Combine($PSScriptRoot, 'docs', 'en-US')
OutputPath = [Path]::Combine($ReleasePath, 'en-US')
}
New-ExternalHelp @helpParams | Out-Null
}
Expand Down Expand Up @@ -71,25 +73,25 @@ task BuildManaged {

task CopyToRelease {
$copyParams = @{
Path = [IO.Path]::Combine($PowerShellPath, '*')
Path = [Path]::Combine($PowerShellPath, '*')
Destination = $ReleasePath
Recurse = $true
Force = $true
}
Copy-Item @copyParams

foreach ($framework in $TargetFrameworks) {
$buildFolder = [IO.Path]::Combine($CSharpPath, 'bin', $Configuration, $framework, 'publish')
$binFolder = [IO.Path]::Combine($ReleasePath, 'bin', $framework, $_.Name)
$buildFolder = [Path]::Combine($CSharpPath, 'bin', $Configuration, $framework, 'publish')
$binFolder = [Path]::Combine($ReleasePath, 'bin', $framework, $_.Name)
if (-not (Test-Path -LiteralPath $binFolder)) {
New-Item -Path $binFolder -ItemType Directory | Out-Null
}
Copy-Item ([IO.Path]::Combine($buildFolder, '*')) -Destination $binFolder -Recurse
Copy-Item ([Path]::Combine($buildFolder, '*')) -Destination $binFolder -Recurse
}
}

task Package {
$nupkgPath = [IO.Path]::Combine($BuildPath, "$ModuleName.$Version*.nupkg")
$nupkgPath = [Path]::Combine($BuildPath, "$ModuleName.$Version*.nupkg")
if (Test-Path $nupkgPath) {
Remove-Item $nupkgPath -Force
}
Expand All @@ -116,7 +118,7 @@ task Package {
task Analyze {
$pssaSplat = @{
Path = $ReleasePath
Settings = [IO.Path]::Combine($PSScriptRoot, 'ScriptAnalyzerSettings.psd1')
Settings = [Path]::Combine($PSScriptRoot, 'ScriptAnalyzerSettings.psd1')
Recurse = $true
ErrorAction = 'SilentlyContinue'
}
Expand All @@ -128,18 +130,18 @@ task Analyze {
}

task DoUnitTest {
$testsPath = [IO.Path]::Combine($PSScriptRoot, 'tests', 'units')
$testsPath = [Path]::Combine($PSScriptRoot, 'tests', 'units')
if (-not (Test-Path -LiteralPath $testsPath)) {
Write-Host 'No unit tests found, skipping'
return
}

$resultsPath = [IO.Path]::Combine($BuildPath, 'TestResults')
$resultsPath = [Path]::Combine($BuildPath, 'TestResults')
if (-not (Test-Path -LiteralPath $resultsPath)) {
New-Item $resultsPath -ItemType Directory -ErrorAction Stop | Out-Null
}

$tempResultsPath = [IO.Path]::Combine($resultsPath, 'TempUnit')
$tempResultsPath = [Path]::Combine($resultsPath, 'TempUnit')
if (Test-Path -LiteralPath $tempResultsPath) {
Remove-Item -LiteralPath $tempResultsPath -Force -Recurse
}
Expand Down Expand Up @@ -181,18 +183,18 @@ task DoUnitTest {
}

task DoTest {
$pesterScript = [IO.Path]::Combine($PSScriptRoot, 'tools', 'PesterTest.ps1')
$pesterScript = [Path]::Combine($PSScriptRoot, 'tools', 'PesterTest.ps1')
if (-not (Test-Path $pesterScript)) {
Write-Host 'No Pester tests found, skipping'
return
}

$resultsPath = [IO.Path]::Combine($BuildPath, 'TestResults')
$resultsPath = [Path]::Combine($BuildPath, 'TestResults')
if (-not (Test-Path $resultsPath)) {
New-Item $resultsPath -ItemType Directory -ErrorAction Stop | Out-Null
}

$resultsFile = [IO.Path]::Combine($resultsPath, 'Pester.xml')
$resultsFile = [Path]::Combine($resultsPath, 'Pester.xml')
if (Test-Path $resultsFile) {
Remove-Item $resultsFile -ErrorAction Stop -Force
}
Expand All @@ -205,27 +207,27 @@ task DoTest {
'-ExecutionPolicy', 'Bypass'
}
'-File', $pesterScript
'-TestPath', ([IO.Path]::Combine($PSScriptRoot, 'tests'))
'-TestPath', ([Path]::Combine($PSScriptRoot, 'tests'))
'-OutputFile', $resultsFile
)

if ($Configuration -eq 'Debug') {
$unitCoveragePath = [IO.Path]::Combine($resultsPath, 'UnitCoverage.json')
$unitCoveragePath = [Path]::Combine($resultsPath, 'UnitCoverage.json')
$targetArgs = '"' + ($arguments -join '" "') + '"'

if ($UseNativeArguments) {
$watchFolder = [IO.Path]::Combine($ReleasePath, 'bin', $PSFramework)
$watchFolder = [Path]::Combine($ReleasePath, 'bin', $PSFramework)
}
else {
$targetArgs = '"' + ($targetArgs -replace '"', '\"') + '"'
$watchFolder = '"{0}"' -f ([IO.Path]::Combine($ReleasePath, 'bin', $PSFramework))
$watchFolder = '"{0}"' -f ([Path]::Combine($ReleasePath, 'bin', $PSFramework))
}

$arguments = @(
$watchFolder
'--target', $pwsh
'--targetargs', $targetArgs
'--output', ([IO.Path]::Combine($resultsPath, 'Coverage.xml'))
'--output', ([Path]::Combine($resultsPath, 'Coverage.xml'))
'--format', 'cobertura'
if (Test-Path -LiteralPath $unitCoveragePath) {
'--merge-with', $unitCoveragePath
Expand Down

0 comments on commit fd6cee2

Please sign in to comment.