Skip to content

Commit 997c47f

Browse files
tablackburnclaude
andcommitted
fix(review): address PR #16 inline findings
- ci: hashFiles() is not allowed in jobs.<job_id>.if (actionlint and the GitHub Actions docs both flag it). Replace the job-level guard with a Detect template state step that writes is_template to $GITHUB_OUTPUT, then gate downstream steps on that output. CI.yaml guards Cache, Build/Test, and the upload steps; PublishModuleToPowerShellGallery.yaml guards Get Module Version and Check if Release Exists, with the remaining publish steps cascading via their existing dependencies on steps.check_release.outputs.exists. - tests: [bigint] is a PS 7+ accelerator only; Windows PowerShell 5.1 needs the full type. Spell it [System.Numerics.BigInteger] in Compare-SemVerPrerelease so the SemVer numeric-identifier comparison works on the 5.1 runner. - init: switch the two hardcoded forward-slash test paths to Join-Path for consistency with the rest of Initialize-Template.ps1. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 83ea2b3 commit 997c47f

4 files changed

Lines changed: 49 additions & 17 deletions

File tree

.github/workflows/CI.yaml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,34 @@ jobs:
5656
unit-tests:
5757
name: Unit Tests (${{ matrix.os }})
5858
runs-on: ${{ matrix.os }}
59-
# Skip on the un-initialized template — Build's GENERATEMARKDOWN task
60-
# can't import the manifest while {{GUID}} is still a literal placeholder.
61-
# Marker: CHANGELOG.template.md exists only pre-init; Initialize-Template.ps1
62-
# moves it onto CHANGELOG.md during init, so downstream repos run the full
63-
# job. Path has no placeholder token, so init's substitution loop leaves it
64-
# intact in this file.
65-
if: hashFiles('CHANGELOG.template.md') == ''
6659
strategy:
6760
fail-fast: false
6861
matrix:
6962
os: [ubuntu-latest, windows-latest, macOS-latest]
7063
steps:
7164
- uses: actions/checkout@v6
7265

66+
# Skip subsequent steps on the un-initialized template — Build's
67+
# GENERATEMARKDOWN task can't import the manifest while {{GUID}} is still
68+
# a literal placeholder. Marker: CHANGELOG.template.md exists only
69+
# pre-init; Initialize-Template.ps1 moves it onto CHANGELOG.md during
70+
# init, so downstream repos run the full job. The marker path contains
71+
# no placeholder token, so init's substitution loop leaves this guard
72+
# intact when the workflow is copied into a new module.
73+
# hashFiles() is not allowed in jobs.<job_id>.if, so we evaluate it in a
74+
# step and gate downstream steps on the resulting output.
75+
- name: Detect template state
76+
id: template_guard
77+
shell: bash
78+
run: |
79+
if [ -f CHANGELOG.template.md ]; then
80+
echo "is_template=true" >> "$GITHUB_OUTPUT"
81+
else
82+
echo "is_template=false" >> "$GITHUB_OUTPUT"
83+
fi
84+
7385
- name: Cache PowerShell modules
86+
if: steps.template_guard.outputs.is_template == 'false'
7487
uses: actions/cache@v5
7588
with:
7689
path: |
@@ -81,23 +94,24 @@ jobs:
8194
${{ runner.os }}-psmodules-
8295
8396
- name: Build and Test
97+
if: steps.template_guard.outputs.is_template == 'false'
8498
shell: pwsh
8599
run: |
86100
New-Item -Path out -ItemType Directory -Force | Out-Null
87101
./build.ps1 -Task Build,Test -Bootstrap
88102
89103
- name: Upload Coverage to Codecov
104+
if: success() && steps.template_guard.outputs.is_template == 'false'
90105
uses: codecov/codecov-action@v6
91-
if: success()
92106
with:
93107
token: ${{ secrets.CODECOV_TOKEN }}
94108
files: out/codeCoverage.xml
95109
flags: ${{ matrix.os }}
96110
fail_ci_if_error: false
97111

98112
- name: Upload Test Results
113+
if: always() && steps.template_guard.outputs.is_template == 'false'
99114
uses: actions/upload-artifact@v7
100-
if: always()
101115
with:
102116
name: test-results-${{ matrix.os }}
103117
path: out/

.github/workflows/PublishModuleToPowerShellGallery.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,32 @@ jobs:
1515
publish:
1616
name: Publish Module
1717
runs-on: ubuntu-latest
18-
# Never publish the un-initialized template — the .psd1 still has
19-
# {{ModuleName}} and {{GUID}} placeholders. Same marker as CI.yaml.
20-
if: hashFiles('CHANGELOG.template.md') == ''
2118
steps:
2219
- name: Checkout
2320
uses: actions/checkout@v6
2421
with:
2522
fetch-depth: 0
2623

24+
# Never publish the un-initialized template — the .psd1 still has
25+
# {{ModuleName}} and {{GUID}} placeholders. Same marker as CI.yaml:
26+
# CHANGELOG.template.md exists only pre-init. hashFiles() is not allowed
27+
# in jobs.<job_id>.if, so we evaluate it in a step and gate the
28+
# version-detection and release-check steps on the resulting output;
29+
# everything downstream cascades on those steps' outputs and skips
30+
# naturally when they don't run.
31+
- name: Detect template state
32+
id: template_guard
33+
shell: bash
34+
run: |
35+
if [ -f CHANGELOG.template.md ]; then
36+
echo "is_template=true" >> "$GITHUB_OUTPUT"
37+
else
38+
echo "is_template=false" >> "$GITHUB_OUTPUT"
39+
fi
40+
2741
- name: Get Module Version
2842
id: version
43+
if: steps.template_guard.outputs.is_template == 'false'
2944
shell: pwsh
3045
run: |
3146
$manifest = Import-PowerShellDataFile -Path ./{{ModuleName}}/{{ModuleName}}.psd1
@@ -35,6 +50,7 @@ jobs:
3550
3651
- name: Check if Release Exists
3752
id: check_release
53+
if: steps.template_guard.outputs.is_template == 'false'
3854
shell: bash
3955
env:
4056
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Initialize-Template.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,9 @@ if (Test-Path -Path $templateModuleFolder) {
242242
# Rename example function files
243243
$publicFolder = Join-Path -Path $moduleFolder -ChildPath 'Public'
244244
$privateFolder = Join-Path -Path $moduleFolder -ChildPath 'Private'
245-
$testPublicFolder = Join-Path -Path $PSScriptRoot -ChildPath 'tests/Unit/Public'
246-
$testPrivateFolder = Join-Path -Path $PSScriptRoot -ChildPath 'tests/Unit/Private'
245+
$testUnitFolder = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath 'tests') -ChildPath 'Unit'
246+
$testPublicFolder = Join-Path -Path $testUnitFolder -ChildPath 'Public'
247+
$testPrivateFolder = Join-Path -Path $testUnitFolder -ChildPath 'Private'
247248

248249
$foldersToCheck = @($publicFolder, $privateFolder, $testPublicFolder, $testPrivateFolder)
249250

tests/ManifestHelpers.psm1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ function Compare-SemVerPrerelease {
123123

124124
if ($firstIsNumeric -and $secondIsNumeric) {
125125
# SemVer 2.0.0 permits arbitrarily large numeric identifiers — use BigInteger
126-
# rather than [long] to avoid overflow.
127-
$firstNum = [bigint]$firstId
128-
$secondNum = [bigint]$secondId
126+
# rather than [long] to avoid overflow. [bigint] is a PS 7+ accelerator only,
127+
# so spell out the full type for Windows PowerShell 5.1 compatibility.
128+
$firstNum = [System.Numerics.BigInteger]$firstId
129+
$secondNum = [System.Numerics.BigInteger]$secondId
129130

130131
if ($firstNum -lt $secondNum) {
131132
return -1

0 commit comments

Comments
 (0)