Skip to content

Commit 65ce46a

Browse files
CopilotMarkMichaelis
authored andcommitted
Path B: modernize remaining modules, CI, README
* IntelliTect.Common 2.0.0 - Remove obsolete helpers superseded by PowerShell 7 built-ins: Get-IsWindowsPlatform, Set-IsWindowsVariable, Initialize-Array, ConvertTo-Lines. - Rewrite Highlight to emit ANSI escape sequences via Write-Output; works cross-platform on PS7 hosts that support VT. - Bump PowerShellVersion to 7.2; add CompatiblePSEditions, Tags, LicenseUri, ProjectUri, ReleaseNotes. * IntelliTect.File 2.0.0 - Rewrite Get-FileEncoding using raw FileStream so it works on PS7+ (PS7 removed Get-Content -Encoding byte). - Remove n-ary Join-Path wrapper; PS7's built-in Join-Path accepts multiple child paths natively. - Add PSEdition/Version metadata and release notes. * IntelliTect.Git 2.0.0 - Fix Push-GitBranch: detect upstream via native git invocation, throw on non-zero git push exit codes, drop Write-Host noise. - Switch New-GitIgnore source from defunct gitignore.io to toptal.com/developers/gitignore; drop hard-coded fallback list; gracefully omit ProjectType dynamic param if list cannot be fetched. - Add PSEdition/Version metadata and release notes. * IntelliTect.PSToolbox 2.0.0 (umbrella) - Shrink RequiredModules to maintained set: Common, File, Git, CredentialManager. Update description, release notes, metadata. * CI - PullRequest.yml: actions/checkout@v4, Pester 5 via PesterConfiguration, cross-platform matrix (windows-latest + ubuntu-latest), upload test results, add PSScriptAnalyzer job. - Deploy.yml: actions/checkout@v4, use PSResourceGet's Publish-PSResource instead of Publish-Module, cleaner module-discovery logic. - PSScriptAnalyzerSettings.psd1: enable default rules at Error+Warning, excluding only the genuinely-needed exceptions. * Publish.ps1: switch to Publish-PSResource, drop submodule check. * README.md: rewrite to reflect the trimmed module set, document the retired modules and their modern replacements, link to v1.0-legacy. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8d5b461 commit 65ce46a

14 files changed

Lines changed: 776 additions & 318 deletions

File tree

.github/workflows/Deploy.yml

Lines changed: 83 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,96 @@
11
name: Deploy
2+
23
on:
34
push:
45
branches: [ main ]
56
workflow_dispatch:
7+
68
defaults:
79
run:
810
shell: pwsh
11+
912
jobs:
1013
Deploy:
11-
runs-on: windows-latest
14+
runs-on: ubuntu-latest
1215
steps:
13-
- uses: actions/checkout@v2
14-
with:
15-
fetch-depth: 2
16-
- name: Discover Changes
17-
run: |
18-
$changedModules = $(git diff --name-only HEAD HEAD~)
19-
$changedModules
20-
$files = $changedModules -split ' ' | ForEach-Object{[System.IO.FileInfo] $_}
21-
$modules = @()
22-
foreach ($file in $files)
23-
{
24-
if((Test-Path $file.FullName)){
25-
$fileDirectoryParent = $file.Directory.Parent
26-
if ($fileDirectoryParent -and $fileDirectoryParent.Name -eq "Modules") {
27-
$modules += $file.Directory
28-
}
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 2
19+
20+
- name: Discover Changed Modules
21+
id: discover
22+
shell: pwsh
23+
run: |
24+
$changed = git diff --name-only HEAD~ HEAD
25+
$changed
26+
$modules = @()
27+
foreach ($file in $changed) {
28+
$parts = $file -split '/'
29+
if ($parts.Length -ge 2 -and $parts[0] -eq 'Modules') {
30+
$modules += $parts[1]
2931
}
30-
}
31-
$modules.Length
32-
if($modules.Length -eq 0){
33-
exit
34-
}
35-
$changedModulesPath = mkdir -Name "StagingChangedModules\" -Force
36-
For ($i=0; $i -lt $modules.Length; $i++)
37-
{
38-
$module = $modules[$i]
39-
Copy-Item -Path $module.FullName -Destination $changedModulesPath -Recurse -Force
40-
}
41-
- name: Update Changed Modules
42-
run: |
43-
if(!(Test-Path StagingChangedModules)) {
44-
Write-Host "No modules changed"
45-
exit
46-
}
47-
$moduleFolders = Get-ChildItem StagingChangedModules
48-
foreach ($item in $moduleFolders){
49-
$moduleName = $item.Name
50-
$manifest = Get-ChildItem $item.PSPath | Where-Object{$_.Name -like "*psd1"}
51-
if(!$manifest){
52-
Write-Error "The manifest for $moduleName was not found"
32+
}
33+
$modules = $modules | Sort-Object -Unique
34+
Write-Host "Changed modules: $($modules -join ', ')"
35+
if ($modules.Length -eq 0) {
36+
"modules=" >> $env:GITHUB_OUTPUT
37+
return
38+
}
39+
$staging = New-Item -ItemType Directory -Force -Path StagingChangedModules
40+
foreach ($m in $modules) {
41+
Copy-Item -Path "Modules/$m" -Destination $staging.FullName -Recurse -Force
42+
}
43+
"modules=$($modules -join ',')" >> $env:GITHUB_OUTPUT
44+
45+
- name: Bump Module Version
46+
if: steps.discover.outputs.modules != ''
47+
shell: pwsh
48+
run: |
49+
$moduleFolders = Get-ChildItem StagingChangedModules -Directory
50+
foreach ($item in $moduleFolders) {
51+
$manifest = Get-ChildItem $item.FullName -Filter '*.psd1' | Select-Object -First 1
52+
if (-not $manifest) {
53+
Write-Error "Manifest for $($item.Name) was not found"
54+
continue
5355
}
54-
$content = Get-Content $manifest.PSPath | ForEach-Object{
55-
$_
56-
if ($_ -match "ModuleVersion"){
57-
$version = [System.Version]($_ -split "'")[1]
58-
}
59-
}
60-
$major = 0
61-
$minor = 0
62-
$build = 0
63-
$minorRev = 1
64-
if($version.Major -gt 0){$major = $version.Major}
65-
if($version.Minor -gt 0){$minor = $version.Minor}
66-
if($version.Build -gt 0){$build = $version.Build}
67-
if($version.MinorRevision -gt 0){$minorRev = $version.MinorRevision + 1}
68-
$updatedVersion = New-Object -TypeName system.Version -ArgumentList $major, $minor, $build, $minorRev
69-
$PushPath = ".\Modules\" +($manifest.PSChildName).Substring(0, $manifest.PSChildName.length - 5 ) + "\"+ ($manifest.PSChildName)
70-
$PublishPath = ".\StagingChangedModules\" +($manifest.PSChildName).Substring(0, $manifest.PSChildName.length - 5 ) + "\"+ ($manifest.PSChildName)
71-
72-
Update-ModuleManifest -Path $PushPath -ModuleVersion $updatedVersion
73-
Update-ModuleManifest -Path $PublishPath -ModuleVersion $updatedVersion
74-
75-
Write-Host "$moduleName's version was updated from $version to $updatedVersion"
76-
}
77-
- name: Push Changes
78-
run: |
79-
if(!(Test-Path StagingChangedModules)) {
80-
Write-Host "No modules changed"
81-
exit
82-
}
83-
git config --global user.email "tylerjones321@gmail.com"
84-
git config --global user.name "worseTyler"
85-
git add Modules/\*.psd1
86-
git commit -m "[skip ci] Commit from build agent"
87-
git push
88-
- name: Publish To Gallery
89-
run: |
90-
if(!(Test-Path StagingChangedModules)) {
91-
Write-Host "No modules changed"
92-
Write-Host "Nothing to Publish"
93-
exit
94-
}
95-
$moduleFolders = Get-ChildItem StagingChangedModules
96-
foreach ($item in $moduleFolders){
97-
Publish-Module -Path $item.FullName -NuGetApiKey ${{ secrets.POWERSHELL_GALLERY_API_KEY }} -Verbose
98-
}
56+
$current = (Test-ModuleManifest -Path $manifest.FullName).Version
57+
$build = if ($current.Build -ge 0) { $current.Build } else { 0 }
58+
$revision = if ($current.Revision -ge 0) { $current.Revision + 1 } else { 1 }
59+
$updated = [Version]::new($current.Major, $current.Minor, $build, $revision)
60+
$repoManifest = Join-Path '.' 'Modules' $item.Name $manifest.Name
61+
Update-ModuleManifest -Path $repoManifest -ModuleVersion $updated
62+
Update-ModuleManifest -Path $manifest.FullName -ModuleVersion $updated
63+
Write-Host "$($item.Name): $current -> $updated"
64+
}
65+
66+
- name: Commit Version Bump
67+
if: steps.discover.outputs.modules != ''
68+
shell: bash
69+
run: |
70+
git config --global user.email "actions@github.com"
71+
git config --global user.name "github-actions[bot]"
72+
git add Modules/*/*.psd1
73+
if ! git diff --staged --quiet; then
74+
git commit -m "[skip ci] Bump module version from build agent"
75+
git push
76+
fi
77+
78+
- name: Install PSResourceGet
79+
if: steps.discover.outputs.modules != ''
80+
shell: pwsh
81+
run: |
82+
if (-not (Get-Module -ListAvailable -Name Microsoft.PowerShell.PSResourceGet)) {
83+
Install-Module -Name Microsoft.PowerShell.PSResourceGet -Force -Scope CurrentUser
84+
}
85+
86+
- name: Publish to PowerShell Gallery
87+
if: steps.discover.outputs.modules != ''
88+
shell: pwsh
89+
env:
90+
PSGALLERY_API_KEY: ${{ secrets.POWERSHELL_GALLERY_API_KEY }}
91+
run: |
92+
Import-Module Microsoft.PowerShell.PSResourceGet
93+
foreach ($item in Get-ChildItem StagingChangedModules -Directory) {
94+
Write-Host "Publishing $($item.Name) ..."
95+
Publish-PSResource -Path $item.FullName -ApiKey $env:PSGALLERY_API_KEY -Repository PSGallery -Verbose
96+
}

.github/workflows/PullRequest.yml

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,72 @@ on:
55
branches: [ main ]
66

77
workflow_dispatch:
8+
89
defaults:
910
run:
10-
shell: powershell
11+
shell: pwsh
12+
1113
jobs:
1214
PesterTest:
13-
runs-on: windows-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os: [windows-latest, ubuntu-latest]
19+
runs-on: ${{ matrix.os }}
1420
steps:
15-
- uses: actions/checkout@v2
16-
17-
- name: Pester Test
21+
- uses: actions/checkout@v4
22+
23+
- name: Install Pester 5
24+
shell: pwsh
1825
run: |
19-
$ConfirmPreference = "None"
20-
$testResults = Invoke-Pester -Script .\Modules.Tests\ -OutputFile ${{env.GITHUB_WORKSPACE}}\Test-Pester.XML -OutputFormat NUnitXML -PassThru
21-
if($testResults.FailedCount -ne 0) {
22-
Write-Error "$($testResults.FailedCount) test failed."
23-
exit $LASTEXITCODE
26+
$ConfirmPreference = 'None'
27+
if (-not (Get-Module -ListAvailable -Name Pester | Where-Object { $_.Version -ge [version]'5.5.0' })) {
28+
Install-Module -Name Pester -MinimumVersion 5.5.0 -Force -SkipPublisherCheck -Scope CurrentUser
2429
}
25-
DotNetBuild:
26-
runs-on: windows-latest
30+
31+
- name: Run Pester Tests
32+
shell: pwsh
33+
run: |
34+
$ConfirmPreference = 'None'
35+
Import-Module Pester -MinimumVersion 5.5.0
36+
$config = New-PesterConfiguration
37+
$config.Run.Path = './Modules.Tests'
38+
$config.Run.Exit = $true
39+
$config.TestResult.Enabled = $true
40+
$config.TestResult.OutputFormat = 'NUnitXml'
41+
$config.TestResult.OutputPath = "${{ github.workspace }}/Test-Pester.xml"
42+
$config.Output.Verbosity = 'Detailed'
43+
Invoke-Pester -Configuration $config
44+
45+
- name: Upload test results
46+
if: always()
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: pester-results-${{ matrix.os }}
50+
path: Test-Pester.xml
51+
52+
ScriptAnalyzer:
53+
runs-on: ubuntu-latest
2754
steps:
28-
- uses: actions/checkout@v2
29-
- name: DotNet Build
55+
- uses: actions/checkout@v4
56+
57+
- name: Install PSScriptAnalyzer
58+
shell: pwsh
3059
run: |
31-
$items = Get-ChildItem -Include *.sln -Recurse
32-
foreach ($item in $items){
33-
dotnet build $item
60+
if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
61+
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
3462
}
35-
- name: DotNet Test
63+
64+
- name: Run PSScriptAnalyzer
65+
shell: pwsh
3666
run: |
37-
$items = Get-ChildItem -Include *.sln -Recurse
38-
foreach ($item in $items){
39-
dotnet test $item
40-
}
67+
Import-Module PSScriptAnalyzer
68+
$results = Invoke-ScriptAnalyzer -Path ./Modules -Recurse -Settings ./PSScriptAnalyzerSettings.psd1
69+
if ($results) {
70+
$results | Format-Table -AutoSize | Out-String | Write-Host
71+
$errors = @($results | Where-Object Severity -eq 'Error')
72+
if ($errors.Count -gt 0) {
73+
Write-Error "PSScriptAnalyzer found $($errors.Count) error(s)."
74+
exit 1
75+
}
76+
}

Modules.Tests/Common.Tests.ps1

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,6 @@ Describe "Test-Property" {
258258
}
259259
}
260260

261-
Describe "Get-IsWindowsPlatform" {
262-
It "Get-IsWindowsPlatform verifiction using existence of env:SystemRoot" {
263-
Get-IsWindowsPlatform | Should -Be $(Get-Variable IsWindows).Value
264-
}
265-
}
266-
267261
Describe 'Wait-ForCondition' {
268262
It 'Simplest Wait' {
269263
$script:falseCount=0

Modules/IntelliTect.Common/IntelliTect.Common.psd1

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
RootModule = './IntelliTect.Common.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.2.0.7'
15+
ModuleVersion = '2.0.0'
1616

1717
# Supported PSEditions
18-
# CompatiblePSEditions = @()
18+
CompatiblePSEditions = @('Core')
1919

2020
# ID used to uniquely identify this module
2121
GUID = '1f6d62b3-f07a-4c78-b205-229f01929acf'
@@ -33,7 +33,7 @@ Copyright = '(c) 2017 IntelliTect. All rights reserved.'
3333
Description = 'Provides functionality for common functions in PowerShell'
3434

3535
# Minimum version of the PowerShell engine required by this module
36-
# PowerShellVersion = ''
36+
PowerShellVersion = '7.2'
3737

3838
# Name of the PowerShell host required by this module
3939
# PowerShellHostName = ''
@@ -69,12 +69,21 @@ Description = 'Provides functionality for common functions in PowerShell'
6969
# NestedModules = @()
7070

7171
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
72-
FunctionsToExport = 'Add-PathToEnvironmentVariable', 'Invoke-ShouldProcess',
73-
'ConvertFrom-Hashtable', 'Highlight', 'Initialize-Array',
74-
'Add-DisposeScript', 'Register-AutoDispose', 'Get-TempDirectory',
75-
'Get-TempFile', 'Get-FileSystemTempItemPath', 'ConvertTo-Lines',
76-
'Test-Command', 'Test-Property', 'Test-VariableExists',
77-
'Get-IsWindowsPlatform', 'Set-IsWindowsVariable', 'Wait-ForCondition'
72+
FunctionsToExport = @(
73+
'Add-PathToEnvironmentVariable',
74+
'Invoke-ShouldProcess',
75+
'ConvertFrom-Hashtable',
76+
'Highlight',
77+
'Add-DisposeScript',
78+
'Register-AutoDispose',
79+
'Get-TempDirectory',
80+
'Get-TempFile',
81+
'Get-FileSystemTempItemPath',
82+
'Test-Command',
83+
'Test-Property',
84+
'Test-VariableExists',
85+
'Wait-ForCondition'
86+
)
7887

7988
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
8089
CmdletsToExport = '*'
@@ -112,7 +121,24 @@ PrivateData = @{
112121
# IconUri = ''
113122

114123
# ReleaseNotes of this module
115-
# ReleaseNotes = ''
124+
ReleaseNotes = @'
125+
2.0.0
126+
- Removed obsolete helpers superseded by built-in PowerShell 7 features:
127+
Get-IsWindowsPlatform, Set-IsWindowsVariable (use $IsWindows automatic variable),
128+
Initialize-Array (use @(...) array subexpression), ConvertTo-Lines (use -split).
129+
- Highlight rewritten to emit ANSI escape sequences via Write-Output
130+
instead of Write-Host with -ForegroundColor. Works cross-platform.
131+
- Minimum PowerShell version raised to 7.2.
132+
'@
133+
134+
# Tags applied to this module.
135+
Tags = @('IntelliTect', 'Common', 'Utility')
136+
137+
# A URL to the license for this module.
138+
LicenseUri = 'https://github.com/IntelliTect/PSToolbox/blob/main/LICENSE.txt'
139+
140+
# A URL to the main website for this project.
141+
ProjectUri = 'https://github.com/IntelliTect/PSToolbox'
116142

117143
# Prerelease string of this module
118144
# Prerelease = ''

0 commit comments

Comments
 (0)