Skip to content

Commit 85c68b7

Browse files
committed
๐Ÿ› ๏ธ [fix] Improves ColorScriptCache build process
Improves the robustness and reliability of the `Build-ColorScriptCache` function. - ๐Ÿ› ๏ธ Handles cases where `$records` is null or empty to prevent errors during cache building. ๐Ÿ” Addresses a potential issue where the script would throw an error if no records were found. - โž• Adds a conditional check for `$records` before accessing its `Count` property. - โž• Adds a conditional check for `$totalCount` before displaying the summary. - ๐Ÿ‘ท Adds workflow run triggers to publish and changelog workflows. - ๐Ÿš€ Automates updates to changelogs after a publish workflow is completed and triggers publish workflows after tests are completed. - ๐Ÿงช Improves test robustness. - ๐Ÿ”‡ Suppresses output in tests to prevent errors. Signed-off-by: Nick2bad4u <20943337+Nick2bad4u@users.noreply.github.com>
1 parent e5eac8b commit 85c68b7

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

โ€Ž.github/workflows/publish.ymlโ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ on:
2525
required: false
2626
PACKAGES_TOKEN:
2727
required: false
28+
workflow_run:
29+
workflows: ["Test"]
30+
types:
31+
- completed
2832

2933
permissions:
3034
contents: read

โ€Ž.github/workflows/updateChangeLogs.ymlโ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: Update ChangeLogs
22

33
on:
44
workflow_dispatch:
5+
workflow_run:
6+
workflows: ["Publish"]
7+
types:
8+
- completed
59

610
concurrency:
711
group: update-changelogs-${{ github.ref }}

โ€ŽColorScripts-Enhanced/ColorScripts-Enhanced.psm1โ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ function Build-ColorScriptCache {
13231323
}
13241324

13251325
$results = @()
1326-
$totalCount = $records.Count
1326+
$totalCount = if ($records) { $records.Count } else { 0 }
13271327
$progressActivity = 'Building ColorScripts cache'
13281328

13291329
for ($index = 0; $index -lt $totalCount; $index++) {
@@ -1402,7 +1402,7 @@ function Build-ColorScriptCache {
14021402
Write-Progress -Id 1 -Activity $progressActivity -Completed
14031403

14041404
# Display summary unless PassThru is specified
1405-
if (-not $PassThru) {
1405+
if (-not $PassThru -and $totalCount -gt 0) {
14061406
$summary = $results | Group-Object -Property Status | ForEach-Object {
14071407
[pscustomobject]@{
14081408
Status = $_.Name

โ€ŽTests/ColorScripts-Enhanced.Tests.ps1โ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,11 @@ Describe "ColorScripts-Enhanced Module" {
415415
}
416416

417417
It "Should support -Name parameter" {
418-
{ Build-ColorScriptCache -Name "bars" -ErrorAction Stop } | Should -Not -Throw
418+
{ Build-ColorScriptCache -Name "bars" -ErrorAction Stop | Out-Null } | Should -Not -Throw
419419
}
420420

421421
It "Should support -Force parameter" {
422-
{ Build-ColorScriptCache -Name "bars" -Force -ErrorAction Stop } | Should -Not -Throw
422+
{ Build-ColorScriptCache -Name "bars" -Force -ErrorAction Stop | Out-Null } | Should -Not -Throw
423423
}
424424

425425
It "Should accept pipeline input" {

0 commit comments

Comments
ย (0)