Skip to content

Commit 1e3d156

Browse files
πŸš€ [Feature]: Release-triggering file patterns now configurable (#19)
Repositories can now configure which file changes trigger build, test, and publish stages. Previously, only changes to `src/` and `README.md` were recognized as significant β€” this was hardcoded and could not be overridden. Repositories that ship additional important files (e.g., `examples/`, custom config) can now declare their own patterns through the settings file or the action input. - Fixes PSModule/Process-PSModule#278 ## New: Configurable important file patterns The `ImportantFilePatterns` setting accepts an array of regex patterns. When a PR changes only files that don't match any pattern, build/test/publish stages are skipped. **Via settings file** (`.github/PSModule.yml`): ```yaml ImportantFilePatterns: - '^src/' - '^README\.md$' - '^examples/' ``` **Via action input** (newline-separated): ```yaml - uses: PSModule/Get-PSModuleSettings@v1 with: ImportantFilePatterns: | ^src/ ^README\.md$ ^examples/ ``` The setting fully replaces the defaults when configured. Include the default patterns in your list if you still want them. Resolution order: settings file β†’ action input β†’ hardcoded fallback (`^src/`, `^README\.md$`). ## Changed: PR skip comment now reflects configured patterns The PR comment posted when no important files changed now dynamically lists the actual patterns in effect, rather than a hardcoded table. ## Technical Details - `action.yml`: Added `ImportantFilePatterns` input with newline-separated default and corresponding `PSMODULE_GET_SETTINGS_INPUT_ImportantFilePatterns` env var. - `Settings.schema.json`: Added top-level `ImportantFilePatterns` property as array of strings. - `main.ps1`: Added resolution logic (settings file β†’ parsed input β†’ hardcoded default). Replaced hardcoded `$importantPatterns` array with `$settings.ImportantFilePatterns`. Refactored PR comment to generate the pattern table dynamically. - `README.md`: Documented the new input and settings file property with examples. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 21c88f4 commit 1e3d156

3 files changed

Lines changed: 63 additions & 18 deletions

File tree

β€Žaction.ymlβ€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ inputs:
3131
description: The working directory where the script will run from.
3232
required: false
3333
default: ${{ github.workspace }}
34+
ImportantFilePatterns:
35+
description: |
36+
Newline-separated list of regex patterns that identify important files.
37+
Changes matching these patterns trigger build, test, and publish stages.
38+
When set, fully replaces the defaults.
39+
required: false
40+
default: |
41+
^src/
42+
^README\.md$
3443
3544
outputs:
3645
Settings:
@@ -51,6 +60,7 @@ runs:
5160
PSMODULE_GET_SETTINGS_INPUT_Version: ${{ inputs.Version }}
5261
PSMODULE_GET_SETTINGS_INPUT_Prerelease: ${{ inputs.Prerelease }}
5362
PSMODULE_GET_SETTINGS_INPUT_WorkingDirectory: ${{ inputs.WorkingDirectory }}
63+
PSMODULE_GET_SETTINGS_INPUT_ImportantFilePatterns: ${{ inputs.ImportantFilePatterns }}
5464
with:
5565
Name: Get-PSModuleSettings
5666
ShowInfo: false

β€Žsrc/Settings.schema.jsonβ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
"type": "string",
1010
"description": "The name of the module"
1111
},
12+
"ImportantFilePatterns": {
13+
"type": "array",
14+
"description": "Regex patterns that identify important files. Changes matching these patterns trigger build, test, and publish stages. Defaults to ['^src/', '^README\\.md$'] when not configured.",
15+
"items": {
16+
"type": "string",
17+
"minLength": 1
18+
}
19+
},
1220
"Test": {
1321
"type": "object",
1422
"description": "Test configuration settings",

β€Žsrc/main.ps1β€Ž

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ $verbose = $env:PSMODULE_GET_SETTINGS_INPUT_Verbose
77
$version = $env:PSMODULE_GET_SETTINGS_INPUT_Version
88
$prerelease = $env:PSMODULE_GET_SETTINGS_INPUT_Prerelease
99
$workingDirectory = $env:PSMODULE_GET_SETTINGS_INPUT_WorkingDirectory
10+
$importantFilePatternsInput = $env:PSMODULE_GET_SETTINGS_INPUT_ImportantFilePatterns
1011

1112
LogGroup 'Inputs' {
1213
[pscustomobject]@{
@@ -89,9 +90,33 @@ LogGroup 'Name' {
8990
}
9091
}
9192

93+
LogGroup 'ImportantFilePatterns' {
94+
$defaultImportantFilePatterns = @('^src/', '^README\.md$')
95+
if ($null -ne $settings.ImportantFilePatterns) {
96+
$importantFilePatterns = @($settings.ImportantFilePatterns)
97+
Write-Host "Using ImportantFilePatterns from settings file: [$($importantFilePatterns -join ', ')]"
98+
} elseif (-not [string]::IsNullOrWhiteSpace($importantFilePatternsInput)) {
99+
$importantFilePatterns = @($importantFilePatternsInput -split "`n" | ForEach-Object { $_.Trim() } | Where-Object { $_ })
100+
Write-Host "Using ImportantFilePatterns from action input: [$($importantFilePatterns -join ', ')]"
101+
} else {
102+
$importantFilePatterns = $defaultImportantFilePatterns
103+
Write-Host "Using default ImportantFilePatterns: [$($importantFilePatterns -join ', ')]"
104+
}
105+
106+
# Validate that all patterns are valid regular expressions
107+
foreach ($pattern in $importantFilePatterns) {
108+
try {
109+
[void][regex]::new($pattern)
110+
} catch {
111+
throw "Invalid regex in ImportantFilePatterns: '$pattern'. $_"
112+
}
113+
}
114+
}
115+
92116
$settings = [pscustomobject]@{
93-
Name = $name
94-
Test = [pscustomobject]@{
117+
Name = $name
118+
ImportantFilePatterns = $importantFilePatterns
119+
Test = [pscustomobject]@{
95120
Skip = $settings.Test.Skip ?? $false
96121
Linux = [pscustomobject]@{
97122
Skip = $settings.Test.Linux.Skip ?? $false
@@ -147,7 +172,7 @@ $settings = [pscustomobject]@{
147172
StepSummaryMode = $settings.Test.CodeCoverage.StepSummaryMode ?? 'Missed, Files'
148173
}
149174
}
150-
Build = [pscustomobject]@{
175+
Build = [pscustomobject]@{
151176
Skip = $settings.Build.Skip ?? $false
152177
Module = [pscustomobject]@{
153178
Skip = $settings.Build.Module.Skip ?? $false
@@ -160,7 +185,7 @@ $settings = [pscustomobject]@{
160185
Skip = $settings.Build.Site.Skip ?? $false
161186
}
162187
}
163-
Publish = [pscustomobject]@{
188+
Publish = [pscustomobject]@{
164189
Module = [pscustomobject]@{
165190
Skip = $settings.Publish.Module.Skip ?? $false
166191
AutoCleanup = $settings.Publish.Module.AutoCleanup ?? $true
@@ -178,7 +203,7 @@ $settings = [pscustomobject]@{
178203
UsePRTitleAsNotesHeading = $settings.Publish.Module.UsePRTitleAsNotesHeading ?? $true
179204
}
180205
}
181-
Linter = [pscustomobject]@{
206+
Linter = [pscustomobject]@{
182207
Skip = $settings.Linter.Skip ?? $false
183208
ShowSummaryOnSuccess = $settings.Linter.ShowSummaryOnSuccess ?? $false
184209
env = $settings.Linter.env ?? @{}
@@ -231,11 +256,7 @@ LogGroup 'Calculate Job Run Conditions:' {
231256
$isOpenOrLabeledPR = $isPR -and $pullRequestAction -in @('opened', 'reopened', 'synchronize', 'labeled')
232257

233258
# Check if important files have changed in the PR
234-
# Important files for module and docs publish:
235-
# - .github/workflows/Process-PSModule.yml
236-
# - src/**
237-
# - examples/**
238-
# - README.md
259+
# Important files are determined by the configured ImportantFilePatterns setting
239260
$hasImportantChanges = $false
240261
if ($isPR -and $pullRequest.Number) {
241262
LogGroup 'Check for Important File Changes' {
@@ -251,11 +272,8 @@ LogGroup 'Calculate Job Run Conditions:' {
251272
Write-Host "Changed files ($($changedFiles.Count)):"
252273
$changedFiles | ForEach-Object { Write-Host " - $_" }
253274

254-
# Define important file patterns
255-
$importantPatterns = @(
256-
'^src/'
257-
'^README\.md$'
258-
)
275+
# Use configured important file patterns
276+
$importantPatterns = $settings.ImportantFilePatterns
259277

260278
# Check if any changed file matches an important pattern
261279
foreach ($file in $changedFiles) {
@@ -276,15 +294,24 @@ LogGroup 'Calculate Job Run Conditions:' {
276294

277295
# Add a comment to open PRs explaining why build/test is skipped (best-effort, may fail if permissions not granted)
278296
if ($isOpenOrUpdatedPR) {
297+
$patternRows = ($importantPatterns | ForEach-Object {
298+
$escapedPattern = $_.Replace('|', '\|')
299+
$backtickMatches = [regex]::Matches($escapedPattern, '`+')
300+
$maxRun = 0
301+
foreach ($m in $backtickMatches) {
302+
if ($m.Value.Length -gt $maxRun) { $maxRun = $m.Value.Length }
303+
}
304+
$codeDelimiter = '`' * ($maxRun + 1)
305+
"| ${codeDelimiter}${escapedPattern}${codeDelimiter} | Matches files where path matches this pattern |"
306+
}) -join "`n"
279307
$commentBody = @"
280308
### No Significant Changes Detected
281309
282310
This PR does not contain changes to files that would trigger a new release:
283311
284-
| Path | Description |
312+
| Pattern | Description |
285313
| :--- | :---------- |
286-
| ``src/**`` | Module source code |
287-
| ``README.md`` | Documentation |
314+
$patternRows
288315
289316
**Build, test, and publish stages will be skipped** for this PR.
290317

0 commit comments

Comments
Β (0)