From 3f155c1502aecb7e1192c02a8ed3bd50be8a2579 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Mon, 24 Jul 2023 11:24:53 -0600 Subject: [PATCH 1/9] fix lint issues --- Source/Public/f7_history.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Public/f7_history.ps1 b/Source/Public/f7_history.ps1 index 31364e4..f67f357 100644 --- a/Source/Public/f7_history.ps1 +++ b/Source/Public/f7_history.ps1 @@ -28,11 +28,11 @@ function f7_history { } | ForEach-Object { $startTime = if ($_.StartTime -ne $null -and $_.StartTime -ne [datetime]::MinValue) { $_.StartTime.ToLocalTime() } else { $null } [PSCustomObject]@{ 'CommandLine' = $_.CommandLine; 'When' = $startTime } - } + } - if ($historyItems -eq $null -or $historyItems.Count -eq 0) { - Write-Host "The global (PSReadLine) history is empty." - return + if ($null -eq $historyItems -or $historyItems.Count -eq 0) { + #Write-Host "The global (PSReadLine) history is empty." + return } $selection = $history | Out-ConsoleGridView -OutputMode Single -Filter $line -Title "Command History for All Powershell Instances" @@ -42,9 +42,9 @@ function f7_history { # Local history $history = Get-History | Sort-Object -Descending -Property Id | Select-Object @{Name = 'CommandLine'; Expression = { $_.CommandLine } } -Unique - if ($history -eq $null -or $history.Count -eq 0) { - Write-Host "The PowerShell history is empty." - return + if ($null -eq $history -or $history.Count -eq 0) { + #Write-Host "The PowerShell history is empty." + return } $selection = $history | Out-ConsoleGridView -OutputMode Single -Filter $line -Title "Command History" From b9d323d4785ee19e825adc39a61734fa7ca5b009 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Mon, 24 Jul 2023 11:33:24 -0600 Subject: [PATCH 2/9] build workflow --- .github/workflows/build.yml | 113 +++++++++++++++++++++++++++++++++++ Source/Public/f7_history.ps1 | 5 -- 2 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..dc3e9bf --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,113 @@ +# We use `MainLine Development`. See https://gitversion.net/docs/reference/modes/mainline + +name: Build and Test + +on: + pull_request: + branches: + - main + paths-ignore: + - '**.md' + - '.all-contributorsrc' + +jobs: + build: + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: GitVersion + id: gitversion + uses: PoshCode/Actions/gitversion@v1 + + - name: Install-RequiredModules + uses: PoshCode/Actions/install-requiredmodules@v1 + + - name: Build Module + id: build + uses: PoshCode/actions/build-module@v1 + with: + path: ${{github.workspace}}/Source + version: ${{ steps.gitversion.outputs.LegacySemVerPadded }} + destination: ${{github.workspace}}/output + + - name: Upload Build Output + uses: actions/upload-artifact@v3 + with: + name: Modules + path: ${{github.workspace}}/output + + - name: Upload Tests + uses: actions/upload-artifact@v3 + with: + name: PesterTests + path: ${{github.workspace}}/Tests + + - name: Upload RequiredModules.psd1 + uses: actions/upload-artifact@v3 + with: + name: RequiredModules + path: ${{github.workspace}}/RequiredModules.psd1 + + - name: Upload PSScriptAnalyzerSettings.psd1 + uses: actions/upload-artifact@v3 + with: + name: ScriptAnalyzer + path: ${{github.workspace}}/PSScriptAnalyzerSettings.psd1 + + lint: + needs: build + name: Run PSScriptAnalyzer + runs-on: ubuntu-latest + steps: + - name: Download Build Output + uses: actions/download-artifact@v3 + - name: Invoke-ScriptAnalyzer + uses: devblackops/github-action-psscriptanalyzer@master + with: + rootPath: Modules/F7History + repoToken: ${{ secrets.GITHUB_TOKEN }} + + test: + needs: build + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + steps: + - name: Download Build Output + uses: actions/download-artifact@v3 + + - name: Install Required Modules + uses: PoshCode/Actions/install-requiredmodules@v1 + with: + requiredModules-path: ${{github.workspace}}/RequiredModules/RequiredModules.psd1 + + # see https://github.com/Jaykul/RequiredModules/issues/6 + - name: Manually Install Modules F7History is dependent on + shell: pwsh + run: | + Install-Module -Name Microsoft.PowerShell.ConsoleGuiTools -Force -SkipPublisherCheck -Scope CurrentUser + Install-Module -Name PSReadLine -Force -SkipPublisherCheck -Scope CurrentUser + Install-Module -Name Pester -RequiredVersion "4.10.1" -Force -SkipPublisherCheck -Scope CurrentUser + + - name: Run Pester Tests + uses: PoshCode/Actions/pester@v1 + with: + pesterVersion: "4.10.1" + codeCoveragePath: Modules/F7History + moduleUnderTest: F7History + additionalModulePaths: ${{github.workspace}}/Modules + + - name: Publish Test Results + uses: zyborg/dotnet-tests-report@v1 + with: + test_results_path: results.xml + + - name: Upload Results + uses: actions/upload-artifact@v3 + with: + name: Pester Results + path: ${{github.workspace}}/*.xml diff --git a/Source/Public/f7_history.ps1 b/Source/Public/f7_history.ps1 index f67f357..16af1dc 100644 --- a/Source/Public/f7_history.ps1 +++ b/Source/Public/f7_history.ps1 @@ -2,11 +2,6 @@ # f7_history -Global $true | $false # function f7_history { - param( - [parameter(Mandatory = $true)] - [Boolean] - $global - ) $line = $null $cursor = $null From 31a9ccdfd80805a1cc88d1675fb4398093aa612d Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Mon, 24 Jul 2023 11:38:50 -0600 Subject: [PATCH 3/9] fix build workflow --- .github/workflows/build.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dc3e9bf..d2d67a1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,10 +17,6 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: GitVersion - id: gitversion - uses: PoshCode/Actions/gitversion@v1 - - name: Install-RequiredModules uses: PoshCode/Actions/install-requiredmodules@v1 @@ -29,7 +25,6 @@ jobs: uses: PoshCode/actions/build-module@v1 with: path: ${{github.workspace}}/Source - version: ${{ steps.gitversion.outputs.LegacySemVerPadded }} destination: ${{github.workspace}}/output - name: Upload Build Output From 632f51462e5a9915f4389c09529b0209fbd59a00 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Mon, 24 Jul 2023 11:42:35 -0600 Subject: [PATCH 4/9] fix build workflow --- Source/Public/f7_history.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Public/f7_history.ps1 b/Source/Public/f7_history.ps1 index 16af1dc..2a5bcd0 100644 --- a/Source/Public/f7_history.ps1 +++ b/Source/Public/f7_history.ps1 @@ -1,4 +1,5 @@ ################################################################################ +# # f7_history -Global $true | $false # function f7_history { From 56ab15f39615fa4a27b6f8ca1d2d9a05bf08adcb Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Mon, 24 Jul 2023 11:45:33 -0600 Subject: [PATCH 5/9] more lint errors --- Source/Public/f7_history.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Public/f7_history.ps1 b/Source/Public/f7_history.ps1 index 2a5bcd0..ba3c607 100644 --- a/Source/Public/f7_history.ps1 +++ b/Source/Public/f7_history.ps1 @@ -21,8 +21,8 @@ function f7_history { return $true } return $false - } | ForEach-Object { - $startTime = if ($_.StartTime -ne $null -and $_.StartTime -ne [datetime]::MinValue) { $_.StartTime.ToLocalTime() } else { $null } + } | ForEach-Object { + $startTime = if ($null -ne $_.StartTime -and $_.StartTime -ne [datetime]::MinValue) { $_.StartTime.ToLocalTime() } else { $null } [PSCustomObject]@{ 'CommandLine' = $_.CommandLine; 'When' = $startTime } } From 8cf5cad48c75f3f68e990c21cb48b8f53aac8138 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Mon, 24 Jul 2023 11:57:51 -0600 Subject: [PATCH 6/9] fixed test error --- Source/Public/f7_history.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/Public/f7_history.ps1 b/Source/Public/f7_history.ps1 index ba3c607..bec24a6 100644 --- a/Source/Public/f7_history.ps1 +++ b/Source/Public/f7_history.ps1 @@ -3,7 +3,12 @@ # f7_history -Global $true | $false # function f7_history { - + param( + [parameter(Mandatory = $true)] + [Boolean] + $global + ) + $line = $null $cursor = $null [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor) @@ -27,7 +32,7 @@ function f7_history { } if ($null -eq $historyItems -or $historyItems.Count -eq 0) { - #Write-Host "The global (PSReadLine) history is empty." + Write-Error "The global (PSReadLine) history is empty." return } From b51a15f58b91d167470cb418fe2eb4469c75b624 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Mon, 24 Jul 2023 12:13:44 -0600 Subject: [PATCH 7/9] Progress bar --- Source/Public/f7_history.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Public/f7_history.ps1 b/Source/Public/f7_history.ps1 index bec24a6..d7178a8 100644 --- a/Source/Public/f7_history.ps1 +++ b/Source/Public/f7_history.ps1 @@ -8,13 +8,14 @@ function f7_history { [Boolean] $global ) - + $line = $null $cursor = $null [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor) if ($global) { # Global history + Write-Progress -Activity "Getting global command history" -PercentComplete 50 -CurrentOperation "Getting global command history" $historyItems = [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems() [array]::Reverse($historyItems) @@ -31,8 +32,10 @@ function f7_history { [PSCustomObject]@{ 'CommandLine' = $_.CommandLine; 'When' = $startTime } } + Write-Progress -Completed + if ($null -eq $historyItems -or $historyItems.Count -eq 0) { - Write-Error "The global (PSReadLine) history is empty." + Write-Information "The global (PSReadLine) history is empty." -InformationAction Continue return } @@ -44,7 +47,7 @@ function f7_history { $history = Get-History | Sort-Object -Descending -Property Id | Select-Object @{Name = 'CommandLine'; Expression = { $_.CommandLine } } -Unique if ($null -eq $history -or $history.Count -eq 0) { - #Write-Host "The PowerShell history is empty." + Write-Information "The PowerShell history is empty." -InformationAction Continue return } From f225fa6342fb96fd5c395e385269bd6f322f696b Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Mon, 24 Jul 2023 12:15:53 -0600 Subject: [PATCH 8/9] better text --- Source/Public/f7_history.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Public/f7_history.ps1 b/Source/Public/f7_history.ps1 index d7178a8..623af13 100644 --- a/Source/Public/f7_history.ps1 +++ b/Source/Public/f7_history.ps1 @@ -15,7 +15,7 @@ function f7_history { if ($global) { # Global history - Write-Progress -Activity "Getting global command history" -PercentComplete 50 -CurrentOperation "Getting global command history" + Write-Progress -Activity "Getting global (PSReadLine) command history" -PercentComplete 50 -CurrentOperation "Getting global command history" $historyItems = [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems() [array]::Reverse($historyItems) From 748e8dc7a3c896972cb9320dccab15e341c42836 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Mon, 24 Jul 2023 12:21:02 -0600 Subject: [PATCH 9/9] lint error --- Source/Public/f7_history.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Public/f7_history.ps1 b/Source/Public/f7_history.ps1 index 623af13..1d88260 100644 --- a/Source/Public/f7_history.ps1 +++ b/Source/Public/f7_history.ps1 @@ -15,7 +15,7 @@ function f7_history { if ($global) { # Global history - Write-Progress -Activity "Getting global (PSReadLine) command history" -PercentComplete 50 -CurrentOperation "Getting global command history" + Write-Progress -Activity "Getting global (PSReadLine) command history" -PercentComplete -1 $historyItems = [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems() [array]::Reverse($historyItems) @@ -32,7 +32,7 @@ function f7_history { [PSCustomObject]@{ 'CommandLine' = $_.CommandLine; 'When' = $startTime } } - Write-Progress -Completed + Write-Progress -Completed -Activity "Getting global (PSReadLine) command history" if ($null -eq $historyItems -or $historyItems.Count -eq 0) { Write-Information "The global (PSReadLine) history is empty." -InformationAction Continue