Skip to content

Commit

Permalink
Merge pull request #12 from santisq/11-group-trees-by-input
Browse files Browse the repository at this point in the history
11 group trees by input
  • Loading branch information
santisq committed Jul 4, 2023
2 parents 2260806 + 17cd174 commit 496cbcc
Show file tree
Hide file tree
Showing 27 changed files with 1,256 additions and 623 deletions.
87 changes: 81 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ jobs:
- name: Check out repository
uses: actions/checkout@v3

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x

- name: Build module - Debug
shell: pwsh
run: ./build.ps1 -Configuration $env:BUILD_CONFIGURATION -Task Build
Expand All @@ -48,11 +43,91 @@ jobs:
name: PSModule
path: output/*.nupkg

test:
name: test
needs:
- build
runs-on: ${{ matrix.info.os }}
strategy:
fail-fast: false
matrix:
info:
- name: PS_5.1
psversion: '5.1'
os: windows-latest
- name: PS_7_Windows
psversion: '7'
os: windows-latest
- name: PS_7_Linux
psversion: '7'
os: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Restore Built PowerShell Module
uses: actions/download-artifact@v3
with:
name: PSModule
path: output

- name: Install Built PowerShell Module
shell: pwsh
run: |
$manifestItem = Get-Item ([IO.Path]::Combine('module', '*.psd1'))
$moduleName = $manifestItem.BaseName
$manifest = Test-ModuleManifest -Path $manifestItem.FullName -ErrorAction SilentlyContinue -WarningAction Ignore
$destPath = [IO.Path]::Combine('output', $moduleName, $manifest.Version)
if (-not (Test-Path -LiteralPath $destPath)) {
New-Item -Path $destPath -ItemType Directory | Out-Null
}
Get-ChildItem output/*.nupkg | Rename-Item -NewName { $_.Name -replace '.nupkg', '.zip' }
Expand-Archive -Path output/*.zip -DestinationPath $destPath -Force -ErrorAction Stop
- name: Run Tests - Windows PowerShell
if: ${{ matrix.info.psversion == '5.1' }}
shell: pwsh
run: |
powershell.exe -NoProfile -File ./build.ps1 -Configuration $env:BUILD_CONFIGURATION -Task Test
exit $LASTEXITCODE
- name: Run Tests - PowerShell
if: ${{ matrix.info.psversion != '5.1' }}
shell: pwsh
run: |
pwsh -NoProfile -File ./build.ps1 -Configuration $env:BUILD_CONFIGURATION -Task Test
exit $LASTEXITCODE
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v3
with:
name: Unit Test Results (${{ matrix.info.name }})
path: ./output/TestResults/Pester.xml

- name: Upload Coverage Results
if: always() && !startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v3
with:
name: Coverage Results (${{ matrix.info.name }})
path: ./output/TestResults/Coverage.xml

- name: Upload Coverage to codecov
if: always() && !startsWith(github.ref, 'refs/tags/v')
uses: codecov/codecov-action@v3
with:
files: ./output/TestResults/Coverage.xml
flags: ${{ matrix.info.name }}

publish:
name: publish
if: startsWith(github.ref, 'refs/tags/v')
needs:
- build
- test
runs-on: windows-latest
steps:
- name: Restore Built PowerShell Module
Expand All @@ -70,4 +145,4 @@ jobs:
--source 'https://www.powershellgallery.com/api/v2/package'
--no-symbols
env:
PSGALLERY_TOKEN: ${{ secrets.PSGALLERY_TOKEN }}
PSGALLERY_TOKEN: ${{ secrets.PSGALLERY_TOKEN }}
7 changes: 7 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"default": true,
"no-hard-tabs": true,
"no-duplicate-heading": false,
"line-length": false,
"no-inline-html": false
}
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"program": "pwsh",
"args": [
"-NoExit",
// "-NoProfile",
"-NoProfile",
"-Command",
"Import-Module ./output/PSTree"
],
Expand Down
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
# CHANGELOG

- __07/03/2023__
- Added `-Path` parameter, now both `-Path` and `-LiteralPath` parameters take `string[]` as input and support pipeline input.
- Added Pester tests, Code Coverage and coverage upload to [codecov.io](https://app.codecov.io/gh/santisq/PSTree).
- Removed `.Size` Property from `PSTreeFile` and `PSTreeDirectory` instances. The `Size` column has been renamed to `Length` and moved to the left-hand side of the `Hierarchy` column (I know it looks much better on the right-hand side :expressionless: but having it in the left allows for fixed width in the first 2 columns, which in turn brings less formatting issues :man_shrugging:...).

The default display for this column is available through `[PSTree.Internal._Format]::GetFormattedLength(...)`, for example:

```powershell
Get-PSTree | Select-Object Hierarchy, @{ N='Size'; E={ [PSTree.Internal._Format]::GetFormattedLength($_.Length) }}
```

- Added `GroupBy` tag to the default view, now trees are grouped by the source Path omg! Little example:

```powershell
PS ..\PSTree> Get-PSTree .\src\, .\module\ -Exclude *\obj,*\bin
Source: C:\path\to\PSTree\src
Mode Length Hierarchy
---- ------ ---------
d---- 0.00 B src
d---- 10.30 KB └── PSTree
-a--- 931.00 B ├── ExceptionHelpers.cs
-a--- 439.00 B ├── PSTree.csproj
-a--- 1.06 KB ├── PSTreeDirectory.cs
-a--- 4.01 KB ├── PSTreeExtensions.cs
-a--- 517.00 B ├── PSTreeFile.cs
-a--- 399.00 B ├── PSTreeFileSystemInfo.cs
-a--- 1.51 KB ├── PSTreeFileSystemInfo_T.cs
-a--- 897.00 B ├── PSTreeHelper.cs
-a--- 619.00 B ├── PSTreeIndexer.cs
d---- 1.13 KB ├── Internal
-a--- 1.13 KB │ └── _Format.cs
d---- 5.68 KB └── Commands
-a--- 5.68 KB └── GetPSTreeCommand.cs
Source: C:\path\to\PSTree
Mode Length Hierarchy
---- ------ ---------
d---- 6.22 KB module
-a--- 1.54 KB ├── PSTree.Format.ps1xml
-a--- 4.67 KB └── PSTree.psd1
```

- __03/22/2023__
- `Get-PSTree` is now a binary cmdlet. Functionality remains the same. Big thanks to [SeeminglyScience](https://github.com/SeeminglyScience/) and [jborean93](https://github.com/jborean93/) for all their help!
- Added `-Exclude` parameter to the cmdlet. The parameter accepts wildcards and patterns are matched with the object's `.FullName` property. For more details checkout [cmdlet docs](/docs/en-US/Get-PSTree.md).
Expand Down
65 changes: 34 additions & 31 deletions PSTree.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ param(

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

$ModuleName = $manifestItem.BaseName
$Manifest = Test-ModuleManifest -Path $manifestItem.FullName -ErrorAction Ignore -WarningAction Ignore

$testModuleManifestSplat = @{
Path = $manifestItem.FullName
ErrorAction = 'Ignore'
WarningAction = 'Ignore'
}
$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)
$IsUnix = $PSEdition -eq 'Core' -and -not $IsWindows
$UseNativeArguments =
$PSVersionTable.PSVersion.Major -gt 7 -or
($PSVersionTable.PSVersion.Major -eq 7 -and $PSVersionTable.PSVersion.Minor -gt 2)
$UseNativeArguments = $PSVersionTable.PSVersion -gt '7.0'
($csharpProjectInfo = [xml]::new()).Load((Get-Item ([IO.Path]::Combine($CSharpPath, '*.csproj'))).FullName)
$TargetFrameworks = @(@($csharpProjectInfo.Project.PropertyGroup)[0].
TargetFrameworks.Split(';', [StringSplitOptions]::RemoveEmptyEntries))

$PSFramework = $TargetFrameworks[0]

[xml] $csharpProjectInfo = Get-Content ([IO.Path]::Combine($CSharpPath, '*.csproj'))
$TargetFrameworks = @(@($csharpProjectInfo.Project.PropertyGroup)[0].TargetFrameworks.Split(
Expand All @@ -36,7 +44,7 @@ task Clean {

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

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

Expand All @@ -82,7 +90,7 @@ task CopyToRelease {
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 ([IO.Path]::Combine($buildFolder, '*')) -Destination $binFolder -Recurse
}
}

Expand All @@ -93,9 +101,9 @@ task Package {
}

$repoParams = @{
Name = 'LocalRepo'
SourceLocation = $BuildPath
PublishLocation = $BuildPath
Name = 'LocalRepo'
SourceLocation = $BuildPath
PublishLocation = $BuildPath
InstallationPolicy = 'Trusted'
}
if (Get-PSRepository -Name $repoParams.Name -ErrorAction SilentlyContinue) {
Expand All @@ -113,22 +121,22 @@ task Package {

task Analyze {
$pssaSplat = @{
Path = $ReleasePath
Settings = [IO.Path]::Combine($PSScriptRoot, 'ScriptAnalyzerSettings.psd1')
Recurse = $true
Path = $ReleasePath
Settings = [IO.Path]::Combine($PSScriptRoot, 'ScriptAnalyzerSettings.psd1')
Recurse = $true
ErrorAction = 'SilentlyContinue'
}
$results = Invoke-ScriptAnalyzer @pssaSplat
if ($null -ne $results) {
$results | Out-String
throw "Failed PsScriptAnalyzer tests, build failed"
throw 'Failed PsScriptAnalyzer tests, build failed'
}
}

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

Expand All @@ -137,9 +145,7 @@ task DoUnitTest {
New-Item $resultsPath -ItemType Directory -ErrorAction Stop | Out-Null
}

# dotnet test places the results in a subfolder of the results-directory. This subfolder is based on a random guid
# so a temp folder is used to ensure we only get the current runs results
$tempResultsPath = [IO.Path]::Combine($resultsPath, "TempUnit")
$tempResultsPath = [IO.Path]::Combine($resultsPath, 'TempUnit')
if (Test-Path -LiteralPath $tempResultsPath) {
Remove-Item -LiteralPath $tempResultsPath -Force -Recurse
}
Expand All @@ -164,11 +170,11 @@ task DoUnitTest {
}
)

Write-Host "Running unit tests"
Write-Host 'Running unit tests'
dotnet @arguments

if ($LASTEXITCODE) {
throw "Unit tests failed"
throw 'Unit tests failed'
}

if ($Configuration -eq 'Debug') {
Expand All @@ -182,8 +188,8 @@ task DoUnitTest {

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

Expand All @@ -210,7 +216,6 @@ task DoTest {
)

if ($Configuration -eq 'Debug') {
# We use coverlet to collect code coverage of our binary
$unitCoveragePath = [IO.Path]::Combine($resultsPath, 'UnitCoverage.json')
$targetArgs = '"' + ($arguments -join '" "') + '"'

Expand All @@ -236,14 +241,12 @@ task DoTest {
}

& $pwsh $arguments

if ($LASTEXITCODE) {
throw "Pester failed tests"
throw 'Pester failed tests'
}
}

task Build -Jobs Clean, BuildManaged, CopyToRelease, BuildDocs, Package

# FIXME: Work out why we need the obj and bin folder for coverage to work
task Test -Jobs BuildManaged, Analyze, DoUnitTest, DoTest

task . Build
task . Build

0 comments on commit 496cbcc

Please sign in to comment.