Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ The action can be configured using the following settings:
| `MajorLabels` | A comma separated list of labels that trigger a major release. | `major, breaking` | false |
| `MinorLabels` | A comma separated list of labels that trigger a minor release. | `minor, feature` | false |
| `PatchLabels` | A comma separated list of labels that trigger a patch release. | `patch, fix` | false |
| `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 |
| `UsePRTitleAsReleaseName` | When enabled, uses the pull request title as the name for the GitHub release. | `false` | false |
| `UsePRBodyAsReleaseNotes` | When enabled, uses the pull request body as the release notes for the GitHub release. | `true` | false |
| `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 |
Expand All @@ -70,10 +71,11 @@ The action's configuration can be changed by altering the settings in the config
```yaml
DatePrereleaseFormat: 'yyyyMMddHHmm'
IncrementalPrerelease: false
ReleaseFiles: 'action.yml, src/**'
VersionPrefix: ''
```

This example uses the date format for the prerelease, disables the incremental prerelease and removes the version prefix.
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.

## Example

Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ inputs:
description: A comma separated list of labels that trigger a patch release.
required: false
default: patch, fix
ReleaseFiles:
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.
required: false
default: ''
UsePRTitleAsReleaseName:
description: When enabled, uses the pull request title as the name for the GitHub release.
required: false
Expand Down Expand Up @@ -107,6 +111,7 @@ runs:
PSMODULE_AUTO_RELEASE_INPUT_MajorLabels: ${{ inputs.MajorLabels }}
PSMODULE_AUTO_RELEASE_INPUT_MinorLabels: ${{ inputs.MinorLabels }}
PSMODULE_AUTO_RELEASE_INPUT_PatchLabels: ${{ inputs.PatchLabels }}
PSMODULE_AUTO_RELEASE_INPUT_ReleaseFiles: ${{ inputs.ReleaseFiles }}
PSMODULE_AUTO_RELEASE_INPUT_UsePRBodyAsReleaseNotes: ${{ inputs.UsePRBodyAsReleaseNotes }}
PSMODULE_AUTO_RELEASE_INPUT_UsePRTitleAsReleaseName: ${{ inputs.UsePRTitleAsReleaseName }}
PSMODULE_AUTO_RELEASE_INPUT_UsePRTitleAsNotesHeading: ${{ inputs.UsePRTitleAsNotesHeading }}
Expand Down
40 changes: 40 additions & 0 deletions src/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ LogGroup 'Set configuration' {
$minorLabels = (![string]::IsNullOrEmpty($configuration.MinorLabels) ? $configuration.MinorLabels : $env:PSMODULE_AUTO_RELEASE_INPUT_MinorLabels) -split ',' | ForEach-Object { $_.Trim() }
$patchLabels = (![string]::IsNullOrEmpty($configuration.PatchLabels) ? $configuration.PatchLabels : $env:PSMODULE_AUTO_RELEASE_INPUT_PatchLabels) -split ',' | ForEach-Object { $_.Trim() }

$releaseFilesRaw = ![string]::IsNullOrEmpty($configuration.ReleaseFiles) ? $configuration.ReleaseFiles : $env:PSMODULE_AUTO_RELEASE_INPUT_ReleaseFiles
$releaseFiles = @()
if (![string]::IsNullOrEmpty($releaseFilesRaw)) {
$releaseFiles = $releaseFilesRaw -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' }
}

Write-Output '-------------------------------------------------'
Write-Output "Auto cleanup enabled: [$autoCleanup]"
Write-Output "Auto patching enabled: [$autoPatching]"
Expand All @@ -73,6 +79,7 @@ LogGroup 'Set configuration' {
Write-Output "Major labels: [$($majorLabels -join ', ')]"
Write-Output "Minor labels: [$($minorLabels -join ', ')]"
Write-Output "Patch labels: [$($patchLabels -join ', ')]"
Write-Output "Release files: [$($releaseFiles -join ', ')]"
Write-Output '-------------------------------------------------'
}

Expand Down Expand Up @@ -136,6 +143,39 @@ if ($ignoreRelease) {
return
}

if ($releaseFiles.Count -gt 0) {
LogGroup 'Check changed files against release file patterns' {
$prNumber = $pull_request.number
$changedFiles = gh pr diff $prNumber --name-only | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' }
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to get changed files for PR #$prNumber."
exit $LASTEXITCODE
}
Write-Output "Changed files in PR #$($prNumber):"
$changedFiles | ForEach-Object { Write-Output " - $_" }
Write-Output ''
Write-Output "Release file patterns:"
$releaseFiles | ForEach-Object { Write-Output " - $_" }

$hasReleaseFileChanges = $false
:fileLoop foreach ($file in $changedFiles) {
foreach ($pattern in $releaseFiles) {
if ($file -like $pattern) {
Write-Output "Match: [$file] matches pattern [$pattern]"
$hasReleaseFileChanges = $true
break fileLoop
}
}
}

if (-not $hasReleaseFileChanges) {
Write-Output 'No changed files match the configured release file patterns. Skipping release creation.'
return
}
Write-Output 'Changed files match release file patterns. Proceeding with release.'
}
}

$majorRelease = ($labels | Where-Object { $majorLabels -contains $_ }).Count -gt 0
$minorRelease = ($labels | Where-Object { $minorLabels -contains $_ }).Count -gt 0 -and -not $majorRelease
$patchRelease = (($labels | Where-Object { $patchLabels -contains $_ }).Count -gt 0 -or $autoPatching) -and -not $majorRelease -and -not $minorRelease
Expand Down