Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using $PSNativeCommandUseErrorActionPreference #57

Merged
merged 5 commits into from
Sep 29, 2024
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
1 change: 0 additions & 1 deletion .github/workflows/ci-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
matrix:
os:
- ubuntu-24.04
- macos-14
runs-on: ${{ matrix.os }}
timeout-minutes: 30
steps:
Expand Down
20 changes: 12 additions & 8 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ tasks:
- task: test
- task: lint
test:
deps:
- setup
cmds:
# pwsh exit with 0 even if ReadLine made errors, the 1+ code is special for an example as parser error
# So returns 1+ with the result by yourself in each cmd
- pwsh --File ./tools/test-all.ps1
- pwsh --Command 'Test-ModuleManifest -Path ./PSFzfHistory/*.psd1'
- pwsh -NoProfile --File ./tools/test-all.ps1
- pwsh -NoProfile --Command '$PSNativeCommandUseErrorActionPreference = $true; $ErrorActionPreference = "Stop"; Test-ModuleManifest -Path ./PSFzfHistory/*.psd1'
fmt:
deps:
- setup
cmds:
- dprint fmt
- git ls-files '*.nix' | xargs nix fmt
Expand All @@ -30,16 +32,18 @@ tasks:
- git ls-files '*.nix' | xargs nixfmt --check
repl:
cmds:
- pwsh -NoExit -File ./tools/repl.ps1
- pwsh -NoProfile -NoExit -File ./tools/repl.ps1
setup:
cmds:
- pwsh -File ./tools/setup.ps1
- pwsh -NoProfile -File ./tools/setup.ps1
bench:
deps:
- setup
cmds:
- pwsh -File ./tools/benchmark.ps1
- pwsh -NoProfile -File ./tools/benchmark.ps1
deps:
cmds:
- pwsh -File ./tools/deps.ps1
- pwsh -NoProfile -File ./tools/deps.ps1
help:
cmds:
- task --list-all
5 changes: 4 additions & 1 deletion tools/benchmark.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems() cannot be used non tty? as called in CLI
$PSNativeCommandUseErrorActionPreference = $true
$ErrorActionPreference = 'Stop'

# [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems() cannot be used non tty? as called in CLI
# $lines = [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems()
$lines = Get-Content -Path ./fixtures/random-guids.txt

Expand Down
5 changes: 4 additions & 1 deletion tools/deps.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# nix --version - Excluded for Windows, nix targets onle Unix-like OS
$PSNativeCommandUseErrorActionPreference = $true
$ErrorActionPreference = 'Stop'

# nix --version - Excluded for Windows, nix targets onle Unix-like OS
nil --version
task --version
dprint --version
Expand Down
5 changes: 4 additions & 1 deletion tools/lint-fix.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Do NOT use 'Invoke-ScriptAnalyzer -Recurse -Path .' It includes dotfiles as .direnv
$PSNativeCommandUseErrorActionPreference = $true
$ErrorActionPreference = 'Stop'

# Do NOT use 'Invoke-ScriptAnalyzer -Recurse -Path .' It includes dotfiles as .direnv
# https://github.com/PowerShell/PSScriptAnalyzer/issues/561
Get-ChildItem -Recurse -Path PSFzfHistory -Include "*.ps*1" |
ForEach-Object {
Expand Down
23 changes: 17 additions & 6 deletions tools/setup.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# https://github.com/PowerShell/PSScriptAnalyzer
Install-Module -Name PSScriptAnalyzer -Force
# https://github.com/pester/pester
Install-Module -Name Pester -Force
# https://github.com/StartAutomating/Benchpress
Install-Module Benchpress -Scope CurrentUser -Force
$PSNativeCommandUseErrorActionPreference = $true
$ErrorActionPreference = 'Stop'

if (-not (Get-InstalledModule -ErrorAction SilentlyContinue PSScriptAnalyzer )) {
# https://github.com/PowerShell/PSScriptAnalyzer
Install-Module -Name PSScriptAnalyzer -Force
}

if (-not (Get-InstalledModule -ErrorAction SilentlyContinue Pester)) {
# https://github.com/pester/pester
Install-Module -Name Pester -Force
}

if (-not (Get-InstalledModule -ErrorAction SilentlyContinue Benchpress)) {
# https://github.com/StartAutomating/Benchpress
Install-Module Benchpress -Scope CurrentUser -Force
}
4 changes: 4 additions & 0 deletions tools/test-all.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# See https://github.com/kachick/dotfiles/issues/617 for background of this option
$PSNativeCommandUseErrorActionPreference = $true
$ErrorActionPreference = 'Stop'

# https://pester.dev/docs/commands/New-PesterConfiguration
$config = New-PesterConfiguration
$config.Run.Exit = $true
Expand Down