Skip to content

Commit c1ed26b

Browse files
Add configurable ReleaseFiles parameter for release file patterns
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
1 parent 686d8c0 commit c1ed26b

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ The action can be configured using the following settings:
5050
| `MajorLabels` | A comma separated list of labels that trigger a major release. | `major, breaking` | false |
5151
| `MinorLabels` | A comma separated list of labels that trigger a minor release. | `minor, feature` | false |
5252
| `PatchLabels` | A comma separated list of labels that trigger a patch release. | `patch, fix` | false |
53+
| `ReleaseFiles` | A comma separated list of file patterns (glob) that warrant a new release when changed. If specified and a pull request does not change any matching files, the release will be skipped. | `''` | false |
5354
| `UsePRTitleAsReleaseName` | When enabled, uses the pull request title as the name for the GitHub release. | `false` | false |
5455
| `UsePRBodyAsReleaseNotes` | When enabled, uses the pull request body as the release notes for the GitHub release. | `true` | false |
5556
| `UsePRTitleAsNotesHeading` | When enabled, the release notes will begin with the pull request title as a H1 heading followed by the pull request body. The title will include a reference to the PR number. | `true` | false |
@@ -70,10 +71,11 @@ The action's configuration can be changed by altering the settings in the config
7071
```yaml
7172
DatePrereleaseFormat: 'yyyyMMddHHmm'
7273
IncrementalPrerelease: false
74+
ReleaseFiles: 'action.yml, src/**'
7375
VersionPrefix: ''
7476
```
7577
76-
This example uses the date format for the prerelease, disables the incremental prerelease and removes the version prefix.
78+
This example uses the date format for the prerelease, disables the incremental prerelease, only triggers releases for changes to `action.yml` and files under `src/`, and removes the version prefix.
7779

7880
## Example
7981

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ inputs:
5050
description: A comma separated list of labels that trigger a patch release.
5151
required: false
5252
default: patch, fix
53+
ReleaseFiles:
54+
description: A comma separated list of file patterns (glob) that warrant a new release when changed. If specified and a pull request does not change any matching files, the release will be skipped.
55+
required: false
56+
default: ''
5357
UsePRTitleAsReleaseName:
5458
description: When enabled, uses the pull request title as the name for the GitHub release.
5559
required: false
@@ -107,6 +111,7 @@ runs:
107111
PSMODULE_AUTO_RELEASE_INPUT_MajorLabels: ${{ inputs.MajorLabels }}
108112
PSMODULE_AUTO_RELEASE_INPUT_MinorLabels: ${{ inputs.MinorLabels }}
109113
PSMODULE_AUTO_RELEASE_INPUT_PatchLabels: ${{ inputs.PatchLabels }}
114+
PSMODULE_AUTO_RELEASE_INPUT_ReleaseFiles: ${{ inputs.ReleaseFiles }}
110115
PSMODULE_AUTO_RELEASE_INPUT_UsePRBodyAsReleaseNotes: ${{ inputs.UsePRBodyAsReleaseNotes }}
111116
PSMODULE_AUTO_RELEASE_INPUT_UsePRTitleAsReleaseName: ${{ inputs.UsePRTitleAsReleaseName }}
112117
PSMODULE_AUTO_RELEASE_INPUT_UsePRTitleAsNotesHeading: ${{ inputs.UsePRTitleAsNotesHeading }}

src/main.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ LogGroup 'Set configuration' {
5656
$minorLabels = (![string]::IsNullOrEmpty($configuration.MinorLabels) ? $configuration.MinorLabels : $env:PSMODULE_AUTO_RELEASE_INPUT_MinorLabels) -split ',' | ForEach-Object { $_.Trim() }
5757
$patchLabels = (![string]::IsNullOrEmpty($configuration.PatchLabels) ? $configuration.PatchLabels : $env:PSMODULE_AUTO_RELEASE_INPUT_PatchLabels) -split ',' | ForEach-Object { $_.Trim() }
5858

59+
$releaseFilesRaw = ![string]::IsNullOrEmpty($configuration.ReleaseFiles) ? $configuration.ReleaseFiles : $env:PSMODULE_AUTO_RELEASE_INPUT_ReleaseFiles
60+
$releaseFiles = @()
61+
if (![string]::IsNullOrEmpty($releaseFilesRaw)) {
62+
$releaseFiles = $releaseFilesRaw -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' }
63+
}
64+
5965
Write-Output '-------------------------------------------------'
6066
Write-Output "Auto cleanup enabled: [$autoCleanup]"
6167
Write-Output "Auto patching enabled: [$autoPatching]"
@@ -73,6 +79,7 @@ LogGroup 'Set configuration' {
7379
Write-Output "Major labels: [$($majorLabels -join ', ')]"
7480
Write-Output "Minor labels: [$($minorLabels -join ', ')]"
7581
Write-Output "Patch labels: [$($patchLabels -join ', ')]"
82+
Write-Output "Release files: [$($releaseFiles -join ', ')]"
7683
Write-Output '-------------------------------------------------'
7784
}
7885

@@ -136,6 +143,39 @@ if ($ignoreRelease) {
136143
return
137144
}
138145

146+
if ($releaseFiles.Count -gt 0) {
147+
LogGroup 'Check changed files against release file patterns' {
148+
$prNumber = $pull_request.number
149+
$changedFiles = gh pr diff $prNumber --name-only | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' }
150+
if ($LASTEXITCODE -ne 0) {
151+
Write-Error "Failed to get changed files for PR #$prNumber."
152+
exit $LASTEXITCODE
153+
}
154+
Write-Output "Changed files in PR #$($prNumber):"
155+
$changedFiles | ForEach-Object { Write-Output " - $_" }
156+
Write-Output ''
157+
Write-Output "Release file patterns:"
158+
$releaseFiles | ForEach-Object { Write-Output " - $_" }
159+
160+
$hasReleaseFileChanges = $false
161+
:fileLoop foreach ($file in $changedFiles) {
162+
foreach ($pattern in $releaseFiles) {
163+
if ($file -like $pattern) {
164+
Write-Output "Match: [$file] matches pattern [$pattern]"
165+
$hasReleaseFileChanges = $true
166+
break fileLoop
167+
}
168+
}
169+
}
170+
171+
if (-not $hasReleaseFileChanges) {
172+
Write-Output 'No changed files match the configured release file patterns. Skipping release creation.'
173+
return
174+
}
175+
Write-Output 'Changed files match release file patterns. Proceeding with release.'
176+
}
177+
}
178+
139179
$majorRelease = ($labels | Where-Object { $majorLabels -contains $_ }).Count -gt 0
140180
$minorRelease = ($labels | Where-Object { $minorLabels -contains $_ }).Count -gt 0 -and -not $majorRelease
141181
$patchRelease = (($labels | Where-Object { $patchLabels -contains $_ }).Count -gt 0 -or $autoPatching) -and -not $majorRelease -and -not $minorRelease

0 commit comments

Comments
 (0)