Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions .github/workflows/performance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Performance

on:
pull_request:

concurrency:
group: performance-${{ github.event.pull_request.number }}
cancel-in-progress: true

permissions:
contents: read
pull-requests: write

jobs:
benchmark:
name: Benchmark PowerTree
runs-on: ubuntu-latest
timeout-minutes: 20

steps:
- name: Check out PR
uses: actions/checkout@v6
with:
path: pr
persist-credentials: false

- name: Check out base commit
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base
persist-credentials: false

- name: Benchmark base
shell: pwsh
run: |
& ./pr/Tests/Measure-PowerTreePerformance.ps1 `
-ModulePath ./base/PowerTree.psd1 `
-JsonPath "$env:RUNNER_TEMP/base-performance.json"

- name: Benchmark PR and publish summary
shell: pwsh
run: |
& ./pr/Tests/Measure-PowerTreePerformance.ps1 `
-ModulePath ./pr/PowerTree.psd1 `
-JsonPath "$env:RUNNER_TEMP/pr-performance.json" `
-BaselinePath "$env:RUNNER_TEMP/base-performance.json" `
-MarkdownPath "$env:RUNNER_TEMP/performance-summary.md"
Get-Content "$env:RUNNER_TEMP/performance-summary.md" -Raw |
Add-Content -Path $env:GITHUB_STEP_SUMMARY

- name: Update PR performance comment
if: github.event.pull_request.head.repo.full_name == github.repository
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
$ErrorActionPreference = "Stop"
$marker = "<!-- powertree-performance -->"
$report = Get-Content "$env:RUNNER_TEMP/performance-summary.md" -Raw
$runUrl = "$env:GITHUB_SERVER_URL/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID"
$body = "$marker`n$report`n[View workflow run]($runUrl)"
$headers = @{
Accept = "application/vnd.github+json"
Authorization = "Bearer $env:GITHUB_TOKEN"
"X-GitHub-Api-Version" = "2022-11-28"
}
$commentsUrl = "$env:GITHUB_API_URL/repos/$env:GITHUB_REPOSITORY/issues/$env:PR_NUMBER/comments"
$existing = $null
$page = 1

do {
$comments = @(Invoke-RestMethod `
-Uri "${commentsUrl}?per_page=100&page=$page" `
-Headers $headers)
$existing = $comments |
Where-Object {
$_.user.login -eq "github-actions[bot]" -and $_.body.Contains($marker)
} |
Select-Object -First 1
$page++
} while ($null -eq $existing -and $comments.Count -eq 100)

$payload = @{ body = $body } | ConvertTo-Json
if ($null -ne $existing) {
Invoke-RestMethod `
-Method Patch `
-Uri "$env:GITHUB_API_URL/repos/$env:GITHUB_REPOSITORY/issues/comments/$($existing.id)" `
-Headers $headers `
-ContentType "application/json" `
-Body $payload | Out-Null
"Updated PR performance comment"
} else {
Invoke-RestMethod `
-Method Post `
-Uri $commentsUrl `
-Headers $headers `
-ContentType "application/json" `
-Body $payload | Out-Null
"Created PR performance comment"
}
45 changes: 45 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Tests

on:
push:
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
test:
name: PowerShell ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest

steps:
- name: Check out repository
uses: actions/checkout@v7

- name: Install Pester
shell: pwsh
run: Install-Module Pester -RequiredVersion 6.1.0 -Scope CurrentUser -Force -SkipPublisherCheck

- name: Run Pester tests
shell: pwsh
run: |
$paths = Get-ChildItem ./Tests -Filter '*.Tests.ps1' |
Where-Object Name -ne 'PowerTree.Integration.Tests.ps1' |
Select-Object -ExpandProperty FullName
$result = Invoke-Pester -Path $paths -Output Detailed -PassThru
if ($result.FailedCount -gt 0) {
throw "$($result.FailedCount) Pester test(s) failed"
}

- name: Run integration tests
shell: pwsh
run: ./Tests/PowerTree.Integration.Tests.ps1
37 changes: 16 additions & 21 deletions PowerTree.psm1
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
# Define script-level variables
$script:ModuleRoot = $PSScriptRoot
New-Alias -Name "ptree" -Value "Show-PowerTree"
New-Alias -Name "PowerTree" -Value "Show-PowerTree"
New-Alias -Name "Start-PowerTree" -Value "Show-PowerTree"
New-Alias -Name "Edit-PtreeConfig" -Value "Edit-PowerTreeConfig"
New-Alias -Name "Edit-Ptree" -Value "Edit-PowerTreeConfig"
New-Alias -Name "Edit-PowerTree" -Value "Edit-PowerTreeConfig"
New-Alias -Name "ptreer" -Value "Show-PowerTreeRegistry"
New-Alias -Name "PowerRegistry" -Value "Show-PowerTreeRegistry"
Set-Alias -Name "ptree" -Value "Show-PowerTree"
Set-Alias -Name "PowerTree" -Value "Show-PowerTree"
Set-Alias -Name "Start-PowerTree" -Value "Show-PowerTree"
Set-Alias -Name "Edit-PtreeConfig" -Value "Edit-PowerTreeConfig"
Set-Alias -Name "Edit-Ptree" -Value "Edit-PowerTreeConfig"
Set-Alias -Name "Edit-PowerTree" -Value "Edit-PowerTreeConfig"
Set-Alias -Name "ptreer" -Value "Show-PowerTreeRegistry"
Set-Alias -Name "PowerRegistry" -Value "Show-PowerTreeRegistry"

# Import classes first to ensure they are available to all functions
$ClassFiles = @(Get-ChildItem -Path "$PSScriptRoot\Private\Shared\DataModel\Classes.ps1" -ErrorAction SilentlyContinue)
foreach ($import in $ClassFiles) {
try {
. $import.FullName
Write-Verbose "Imported class definitions from $($import.FullName)"
}
catch {
Write-Error "Failed to import class definitions from $($import.FullName): $_"
}
$classPath = Join-Path $PSScriptRoot "Private/Shared/DataModel/Classes.ps1"
try {
. $classPath
} catch {
Write-Error "Failed to import class definitions from $classPath`: $_"
}

# Import all remaining private functions (recursively)
$Private = @(Get-ChildItem -Path "$PSScriptRoot\Private\*.ps1" -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -ne "$PSScriptRoot\Private\Shared\DataModel\Classes.ps1" })
$Private = @(Get-ChildItem -Path "$PSScriptRoot/Private/*.ps1" -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -ne $classPath })
foreach ($import in $Private) {
try {
. $import.FullName
Expand All @@ -46,4 +41,4 @@ foreach ($import in $Public) {

# Export public functions
Export-ModuleMember -Function $Public.BaseName
Export-ModuleMember -Function $Public.BaseName -Alias "ptree", "PowerTree", "Start-PowerTree", "Edit-PtreeConfig", "Edit-Ptree", "Edit-PowerTree", "ptreer", "PowerRegistry"
Export-ModuleMember -Function $Public.BaseName -Alias "ptree", "PowerTree", "Start-PowerTree", "Edit-PtreeConfig", "Edit-Ptree", "Edit-PowerTree", "ptreer", "PowerRegistry"

This file was deleted.

12 changes: 6 additions & 6 deletions Private/PowerTree/Output/Build-OutputLine.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ function Build-OutputLine {
[string]$TreePrefix,

[Parameter(Mandatory=$true)]
[bool]$HumanReadableSizes
[bool]$HumanReadableSizes,

[long]$DirectorySize = 0
)

$dirSize = 0
Expand Down Expand Up @@ -63,10 +65,8 @@ function Build-OutputLine {
# Set to zero for files
$dirSize = 0
} else {
# Calculate directory size
$dirSize = (Get-ChildItem -LiteralPath $Item.FullName -Recurse -File -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum).Sum
if($HumanReadableSizes){
$dirSize = $DirectorySize
if($HumanReadableSizes){
$content = Get-HumanReadableSize -Bytes $dirSize -Format "Padded"
} else {
$content = $dirSize
Expand Down Expand Up @@ -124,4 +124,4 @@ function Build-OutputLine {
0
}
}
}
}
Loading