diff --git a/README.md b/README.md index be00b65..a422024 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ Each setting has a matching named input and an effective standard in its descrip | Name | Description | Effective default | Required | | --- | --- | --- | --- | | `AutoCleanup` | Delete prereleases after the pull request closes. | `true` | false | -| `SettingsFilePath` | Select the repository settings file before startup. | `.github\auto-release.yml` | false | +| `SettingsFilePath` | Select the repository settings file before startup. | `.github\release.settings.yml` | false | | `DefaultBump` | Select the bump when no explicit bump or skip label exists. Accepts exactly `patch`, `minor`, or `major` with case-sensitive matching. | `patch` | false | | `CreateMajorTag` | Create or update the floating major tag after a stable release. | `true` | false | | `CreateMinorTag` | Create or update the floating minor tag after a stable release. | `true` | false | @@ -111,7 +111,11 @@ Use the `release:prerelease` label to select repository prerelease behavior. The ### Settings file path -The default repository settings file path is `.github\auto-release.yml`. Use `SettingsFilePath` to select a custom file. Omit this selector to use the default path; an empty or whitespace-only path is invalid. Literal paths with spaces or brackets are supported. A directory or a non-file-system provider is not a settings file. If the selected file is absent, valid standards and nonempty named inputs remain effective. +The default repository settings file path is `.github\release.settings.yml`. Use `SettingsFilePath` to select a custom file. Omit this selector to use the default path. An empty or whitespace-only path is invalid. The action supports literal paths with spaces or brackets. A directory or a non-file-system provider is not a settings file. + +The removed `.github\auto-release.yml` path has no fallback or alias, even when you select it explicitly. The bootstrap checks that path in the initial directory, before GitHub-Script starts. If the old file exists and you select the default path, startup fails. An existing custom file remains supported. If a custom file is missing and the old file exists, startup also fails. + +If the selected file and the old default file are both absent, valid standards and nonempty named inputs remain effective. A file-defined `WorkingDirectory` does not change file selection or the location of the old-file check. File selection and execution follow this order: @@ -133,6 +137,7 @@ There is no reserved omission value. Nonempty inputs go through normal validatio The repository file must contain a mapping of supported settings. Every input in the table except `SettingsFilePath` is a valid file key. The file can contain only the settings that differ from the standards. Unknown keys, removed keys, null values, and invalid values fail before GitHub-Script starts. A valid override cannot hide an invalid lower layer. ```yaml +# .github\release.settings.yml DatePrereleaseFormat: 'yyyyMMddHHmm' DefaultBump: patch IncrementalPrerelease: false @@ -144,6 +149,13 @@ Prerelease: false WorkingDirectory: '.' ``` +For an intentional custom path: + +```yaml +with: + SettingsFilePath: .github\custom-release.settings.yml +``` + For an invocation-specific minor bump, even when the repository configures major: ```yaml diff --git a/action.yml b/action.yml index 5a04f6c..7a9b5c3 100644 --- a/action.yml +++ b/action.yml @@ -16,7 +16,7 @@ inputs: Select the repository settings file before startup. Relative paths use an explicit WorkingDirectory, otherwise github.workspace. Nonempty named inputs override file values; omitted or empty inputs retain them. required: false - default: .github\auto-release.yml + default: .github\release.settings.yml DefaultBump: description: >- The release bump without an owned bump or skip label. Accepts exactly patch, minor, or major. diff --git a/src/Initialize-ReleaseConfiguration.ps1 b/src/Initialize-ReleaseConfiguration.ps1 index 28488d9..99481f4 100644 --- a/src/Initialize-ReleaseConfiguration.ps1 +++ b/src/Initialize-ReleaseConfiguration.ps1 @@ -83,8 +83,8 @@ try { $initialDirectory = ConvertTo-ReleaseSettingValue @initialParameters } $settingsFilePath = [Environment]::GetEnvironmentVariable('PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath') + $actionDefinition = ConvertFrom-Yaml -Yaml ([IO.File]::ReadAllText($actionDefinitionPath)) if ($null -eq $settingsFilePath) { - $actionDefinition = ConvertFrom-Yaml -Yaml ([IO.File]::ReadAllText($actionDefinitionPath)) $settingsFilePath = $actionDefinition.inputs.SettingsFilePath.default } $pathParameters = @{ @@ -93,12 +93,34 @@ try { BaseDirectory = $initialDirectory } $settingsFilePath = Resolve-ReleaseFileSystemPath @pathParameters + $defaultPathParameters = @{ + Name = 'SettingsFilePath' + Path = $actionDefinition.inputs.SettingsFilePath.default + BaseDirectory = $initialDirectory + } + $defaultConfigurationPath = Resolve-ReleaseFileSystemPath @defaultPathParameters + $legacyConfigurationPath = Join-Path -Path (Split-Path -Path $defaultConfigurationPath -Parent) -ChildPath 'auto-release.yml' + $pathComparison = [StringComparison]::Ordinal + if ($IsWindows) { + $pathComparison = [StringComparison]::OrdinalIgnoreCase + } + $usesDefaultPath = [string]::Equals($settingsFilePath, $defaultConfigurationPath, $pathComparison) + $usesLegacyPath = [string]::Equals($settingsFilePath, $legacyConfigurationPath, $pathComparison) + $configurationExists = Test-Path -LiteralPath $settingsFilePath -PathType Leaf + $legacyExists = Test-Path -LiteralPath $legacyConfigurationPath -PathType Leaf + if ($usesLegacyPath -or ($legacyExists -and ($usesDefaultPath -or -not $configurationExists))) { + throw ( + "Settings path [$legacyConfigurationPath] is no longer supported. " + + "Rename or combine its policy in [$defaultConfigurationPath]. " + + 'Update SettingsFilePath with a compatible action reference, or select an existing custom settings file.' + ) + } if (Test-Path -LiteralPath $settingsFilePath -PathType Container) { throw 'SettingsFilePath must select a file, not a directory.' } $loggedPath = ConvertTo-Json -InputObject $settingsFilePath -Compress $configuration = @{} - if (Test-Path -LiteralPath $settingsFilePath -PathType Leaf) { + if ($configurationExists) { Write-Information "Reading settings file [$loggedPath]" -InformationAction Continue $configuration = ConvertFrom-Yaml -Yaml ([IO.File]::ReadAllText($settingsFilePath)) if ($null -eq $configuration) { diff --git a/tests/Release-GHRepository.Tests.ps1 b/tests/Release-GHRepository.Tests.ps1 index 0813bca..2c876db 100644 --- a/tests/Release-GHRepository.Tests.ps1 +++ b/tests/Release-GHRepository.Tests.ps1 @@ -333,6 +333,69 @@ WorkingDirectory: '.' { & $bootstrapPath } | Should -Throw '*Unsupported release setting*SettingsFilePath*' Test-Path -LiteralPath $env:GITHUB_OUTPUT | Should -BeFalse } + + It 'loads the canonical file from before execution-directory changes' -ForEach @( + @{ InitialDirectory = 'github.workspace'; ExplicitDirectory = $false } + @{ InitialDirectory = 'an explicit WorkingDirectory'; ExplicitDirectory = $true } + ) { + $initialDirectory = $workspace + if ($ExplicitDirectory) { + $initialDirectory = Join-Path -Path $workspace -ChildPath 'initial [directory]' + $null = New-Item -Path $initialDirectory -ItemType Directory + $env:PSMODULE_AUTO_RELEASE_INPUT_WorkingDirectory = 'initial [directory]' + } + $executionDirectory = Join-Path -Path $workspace -ChildPath 'execution [directory]' + $null = New-Item -Path (Join-Path -Path $initialDirectory -ChildPath '.github') -ItemType Directory + $null = New-Item -Path (Join-Path -Path $executionDirectory -ChildPath '.github') -ItemType Directory + @' +WorkingDirectory: 'execution [directory]' +Debug: true +Verbose: true +Version: '[0.43.1]' +Prerelease: true +DefaultBump: minor +'@ | Set-Content -LiteralPath (Join-Path -Path $initialDirectory -ChildPath '.github\release.settings.yml') + 'DefaultBump: invalid' | + Set-Content -LiteralPath (Join-Path -Path $executionDirectory -ChildPath '.github\release.settings.yml') + 'DefaultBump: major' | + Set-Content -LiteralPath (Join-Path -Path $executionDirectory -ChildPath '.github\auto-release.yml') + Remove-Item -LiteralPath Env:\PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath + + $settings = & $bootstrapPath + + $settings.DefaultBump | Should -BeExactly 'minor' + $settings.DefaultBumpSource | Should -BeExactly 'RepositorySetting' + $outputs = & $readBootstrapOutputs -Path $env:GITHUB_OUTPUT + $outputs.Debug | Should -BeExactly 'true' + $outputs.Verbose | Should -BeExactly 'true' + $outputs.Version | Should -BeExactly '[0.43.1]' + $outputs.Prerelease | Should -BeExactly 'true' + if ($ExplicitDirectory) { + $outputs.WorkingDirectory | Should -BeExactly $initialDirectory + } else { + $outputs.WorkingDirectory | Should -BeExactly $executionDirectory + } + } + + It 'rejects the legacy conventional file before a startup handoff when the new file is ' -ForEach @( + @{ FileState = 'absent'; NewFileExists = $false } + @{ FileState = 'present'; NewFileExists = $true } + ) { + $initialDirectory = Join-Path -Path $workspace -ChildPath 'initial [directory]' + $null = New-Item -Path (Join-Path -Path $initialDirectory -ChildPath '.github') -ItemType Directory + $env:PSMODULE_AUTO_RELEASE_INPUT_WorkingDirectory = 'initial [directory]' + Remove-Item -LiteralPath Env:\PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath + 'DefaultBump: major' | + Set-Content -LiteralPath (Join-Path -Path $initialDirectory -ChildPath '.github\auto-release.yml') + if ($NewFileExists) { + 'DefaultBump: minor' | + Set-Content -LiteralPath (Join-Path -Path $initialDirectory -ChildPath '.github\release.settings.yml') + } + + { & $bootstrapPath } | + Should -Throw '*auto-release.yml*no longer supported*release.settings.yml*SettingsFilePath*' + Test-Path -LiteralPath $env:GITHUB_OUTPUT | Should -BeFalse + } } Describe 'Release-GHRepository caller compatibility' { @@ -391,6 +454,11 @@ Describe 'Release-GHRepository caller compatibility' { } $githubEvent | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $env:GITHUB_EVENT_PATH + $callerDirectory = Join-Path -Path $TestDrive -ChildPath ([guid]::NewGuid().ToString('N')) + $null = New-Item -Path (Join-Path -Path $callerDirectory -ChildPath '.github') -ItemType Directory + $env:GITHUB_WORKSPACE = $callerDirectory + Push-Location -LiteralPath $callerDirectory + $releaseRecordsJson = '[{"tagName":"v2.0.3","isLatest":true,"isPrerelease":false}]' $simulateLabelWrites = $false Mock Install-PSResource {} @@ -411,6 +479,7 @@ Describe 'Release-GHRepository caller compatibility' { } AfterEach { + Pop-Location foreach ($name in $environmentNames) { if ($null -eq $savedEnvironment[$name]) { if (Test-Path -LiteralPath "Env:\$name") { @@ -422,6 +491,199 @@ Describe 'Release-GHRepository caller compatibility' { } } + It 'reads the declared default without an injected SettingsFilePath input' { + Remove-Item -LiteralPath Env:\PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath + @' +DefaultBump: minor +WhatIf: true +'@ | Set-Content -LiteralPath '.github\release.settings.yml' + + $output = (& $runRelease 6>&1) -join "`n" + + $output | Should -Match 'Reading settings file .*release\.settings\.yml' + $output | Should -Match 'Default bump:\s+\[minor\]' + $output | Should -Match 'Default bump source:\s+\[RepositorySetting\]' + $output | Should -Match 'gh release create v2\.1\.0 ' + Should -Invoke gh -Times 2 -Exactly + Should -Invoke git -Times 0 -Exactly + } + + It 'uses conventional-file policy when named inputs are omitted or blank' { + Remove-Item -LiteralPath Env:\PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath + $env:PSMODULE_AUTO_RELEASE_INPUT_DefaultBump = '' + $env:PSMODULE_AUTO_RELEASE_INPUT_AutoCleanup = '' + $env:PSMODULE_AUTO_RELEASE_INPUT_VersionPrefix = '' + $env:PSMODULE_AUTO_RELEASE_INPUT_DatePrereleaseFormat = '' + @' +DefaultBump: minor +AutoCleanup: false +VersionPrefix: '' +DatePrereleaseFormat: '' +WhatIf: true +'@ | Set-Content -LiteralPath '.github\release.settings.yml' + + $output = (& $runRelease 6>&1) -join "`n" + + $output | Should -Match 'Reading settings file .*release\.settings\.yml' + $output | Should -Match 'Default bump:\s+\[minor\]' + $output | Should -Match 'Auto cleanup enabled:\s+\[False\]' + $output | Should -Match 'Version prefix:\s+\[\]' + $output | Should -Match 'Date-based prerelease format:\s+\[\]' + $output | Should -Match 'gh release create 2\.1\.0 ' + Should -Invoke gh -Times 2 -Exactly + Should -Invoke git -Times 0 -Exactly + } + + It 'inherits valid defaults when the conventional settings file is intentionally absent' { + Remove-Item -LiteralPath Env:\PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath + + $output = (& $runRelease 6>&1) -join "`n" + + $output | Should -Match 'Settings file not found at .*release\.settings\.yml' + $output | Should -Match 'Default bump:\s+\[patch\]' + $output | Should -Match 'Default bump source:\s+\[SharedDefault\]' + $output | Should -Match 'gh release create v2\.0\.4 ' + Should -Invoke gh -Times 2 -Exactly + Should -Invoke git -Times 0 -Exactly + } + + It 'rejects legacy-only conventional settings instead of silently applying another policy' { + Remove-Item -LiteralPath Env:\PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath + @' +DefaultBump: major +WhatIf: false +'@ | Set-Content -LiteralPath '.github\auto-release.yml' + + { & $runRelease } | + Should -Throw '*auto-release.yml*no longer supported*release.settings.yml*SettingsFilePath*' + Test-Path -LiteralPath $env:GITHUB_OUTPUT | Should -BeFalse + Should -Invoke gh -Times 0 -Exactly + Should -Invoke git -Times 0 -Exactly + } + + It 'rejects a legacy conventional file even when the new default file also exists' { + $env:PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath = '.github\release.settings.yml' + 'DefaultBump: major' | Set-Content -LiteralPath '.github\auto-release.yml' + 'DefaultBump: minor' | Set-Content -LiteralPath '.github\release.settings.yml' + + { & $runRelease } | Should -Throw '*auto-release.yml*no longer supported*release.settings.yml*' + Test-Path -LiteralPath $env:GITHUB_OUTPUT | Should -BeFalse + Should -Invoke gh -Times 0 -Exactly + Should -Invoke git -Times 0 -Exactly + } + + It 'rejects the removed conventional path even when explicitly supplied as ' -ForEach @( + @{ PathKind = 'relative'; PathValue = '.github\auto-release.yml' } + @{ PathKind = 'normalized relative'; PathValue = '.github\..\.github\auto-release.yml' } + @{ PathKind = 'absolute'; PathValue = $null } + ) { + $env:PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath = $PathValue + if ($PathKind -eq 'absolute') { + $env:PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath = Join-Path -Path $callerDirectory -ChildPath '.github\auto-release.yml' + } + @' +DefaultBump: major +WhatIf: false +'@ | Set-Content -LiteralPath '.github\auto-release.yml' + + { & $runRelease } | Should -Throw '*auto-release.yml*no longer supported*release.settings.yml*' + Test-Path -LiteralPath $env:GITHUB_OUTPUT | Should -BeFalse + Should -Invoke gh -Times 0 -Exactly + Should -Invoke git -Times 0 -Exactly + } + + It 'preserves an intentional custom settings path without adding discovery or fallback' { + 'DefaultBump: major' | Set-Content -LiteralPath '.github\auto-release.yml' + 'DefaultBump: major' | Set-Content -LiteralPath '.github\release.settings.yml' + $env:PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath = Join-Path -Path $callerDirectory -ChildPath 'custom.settings.yml' + @' +DefaultBump: minor +WhatIf: false +'@ | Set-Content -LiteralPath $env:PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath + $env:PSMODULE_AUTO_RELEASE_INPUT_WhatIf = 'true' + + $output = (& $runRelease 6>&1) -join "`n" + + $output | Should -Match 'Reading settings file .*custom\.settings\.yml' + $output | Should -Match 'Default bump:\s+\[minor\]' + $output | Should -Match 'gh release create v2\.1\.0 ' + Should -Invoke gh -Times 2 -Exactly + Should -Invoke git -Times 0 -Exactly + } + + It 'does not ignore legacy settings when an explicitly selected custom file is missing' { + $env:PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath = 'missing.settings.yml' + 'DefaultBump: major' | Set-Content -LiteralPath '.github\auto-release.yml' + + { & $runRelease } | Should -Throw '*auto-release.yml*no longer supported*release.settings.yml*SettingsFilePath*' + Test-Path -LiteralPath $env:GITHUB_OUTPUT | Should -BeFalse + Should -Invoke gh -Times 0 -Exactly + Should -Invoke git -Times 0 -Exactly + } + + It 'applies an explicit standard-valued input before an owned bump' { + Remove-Item -LiteralPath Env:\PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath + $env:PSMODULE_AUTO_RELEASE_INPUT_DefaultBump = 'patch' + $env:PSMODULE_AUTO_RELEASE_INPUT_AutoCleanup = 'false' + @' +DefaultBump: major +AutoCleanup: true +WhatIf: true +'@ | Set-Content -LiteralPath '.github\release.settings.yml' + $githubEvent.pull_request.labels = @(@{ name = 'release:minor' }) + $githubEvent | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $env:GITHUB_EVENT_PATH + + $output = (& $runRelease 6>&1) -join "`n" + + $output | Should -Match 'Reading settings file .*release\.settings\.yml' + $output | Should -Match 'Default bump:\s+\[patch\]' + $output | Should -Match 'Default bump source:\s+\[ActionInput\]' + $output | Should -Match 'Auto cleanup enabled:\s+\[False\]' + $output | Should -Match 'Bump source:\s+\[release:minor\]' + $output | Should -Match 'gh release create v2\.1\.0 ' + Should -Invoke gh -Times 2 -Exactly + Should -Invoke git -Times 0 -Exactly + } + + It 'keeps conventional-file text settings when named inputs are blank' { + Remove-Item -LiteralPath Env:\PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath + $env:PSMODULE_AUTO_RELEASE_INPUT_VersionPrefix = '' + $env:PSMODULE_AUTO_RELEASE_INPUT_DatePrereleaseFormat = '' + @' +DefaultBump: minor +VersionPrefix: release- +DatePrereleaseFormat: yyyyMMdd +WhatIf: true +'@ | Set-Content -LiteralPath '.github\release.settings.yml' + + $output = (& $runRelease 6>&1) -join "`n" + + $output | Should -Match 'Reading settings file .*release\.settings\.yml' + $output | Should -Match 'Version prefix:\s+\[release-\]' + $output | Should -Match 'Date-based prerelease format:\s+\[yyyyMMdd\]' + $output | Should -Match 'gh release create release-2\.1\.0 ' + Should -Invoke gh -Times 2 -Exactly + Should -Invoke git -Times 0 -Exactly + } + + It 'rejects invalid data in the new default file before contacting GitHub' -ForEach @( + @{ Yaml = 'DefaultBump: date'; Message = '*Invalid DefaultBump*' } + @{ Yaml = 'DefaultBump: null'; Message = '*DefaultBump*' } + @{ Yaml = 'WhatIf: invalid'; Message = '*WhatIf*true or false*' } + @{ Yaml = 'AutoPatching: false'; Message = '*AutoPatching*removed*' } + @{ Yaml = '- patch'; Message = '*configuration must be a mapping*' } + @{ Yaml = ''; Message = '*settings file*must be a mapping*' } + ) { + Remove-Item -LiteralPath Env:\PSMODULE_AUTO_RELEASE_INPUT_SettingsFilePath + $Yaml | Set-Content -LiteralPath '.github\release.settings.yml' + $env:PSMODULE_AUTO_RELEASE_INPUT_DefaultBump = 'patch' + + { & $runRelease } | Should -Throw $Message + Test-Path -LiteralPath $env:GITHUB_OUTPUT | Should -BeFalse + Should -Invoke gh -Times 0 -Exactly + Should -Invoke git -Times 0 -Exactly + } + It 'uses action standards without repository settings or injected input defaults' { $output = (& $runRelease) -join "`n" @@ -532,7 +794,7 @@ Describe 'Release-GHRepository caller compatibility' { ExpectedVersion = 'v2.0.4' } ) { - $defaultSettingsPath = '.github\auto-release.yml' + $defaultSettingsPath = '.github\release.settings.yml' $callerDirectory = Join-Path -Path $TestDrive -ChildPath ([guid]::NewGuid().ToString('N')) $null = New-Item -Path (Join-Path -Path $callerDirectory -ChildPath '.github') -ItemType Directory if ($FilePresent) {