diff --git a/CHANGELOG.md b/CHANGELOG.md index 136d5fa..76b13a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Features -- Updater - Add `post-update-script` input parameter to run custom scripts after dependency updates ([#130](https://github.com/getsentry/github-workflows/pull/130)) +- Updater - Add `post-update-script` input parameter to run custom scripts after dependency updates ([#130](https://github.com/getsentry/github-workflows/pull/130), [#133](https://github.com/getsentry/github-workflows/pull/133)) - Scripts receive original and new version as arguments - Support both bash (`.sh`) and PowerShell (`.ps1`) scripts - Enables workflows like updating lock files, running code generators, or modifying configuration files diff --git a/updater/action.yml b/updater/action.yml index 5349ec9..f153507 100644 --- a/updater/action.yml +++ b/updater/action.yml @@ -288,7 +288,7 @@ runs: DEPENDENCY_PATH: ${{ inputs.path }} POST_UPDATE_SCRIPT: ${{ inputs.post-update-script }} GH_TOKEN: ${{ inputs.api-token }} - run: ${{ github.action_path }}/scripts/update-dependency.ps1 -Path $env:DEPENDENCY_PATH -Tag '${{ steps.target.outputs.latestTag }}' -PostUpdateScript $env:POST_UPDATE_SCRIPT + run: ${{ github.action_path }}/scripts/update-dependency.ps1 -Path $env:DEPENDENCY_PATH -Tag '${{ steps.target.outputs.latestTag }}' -OriginalTag '${{ steps.target.outputs.originalTag }}' -PostUpdateScript $env:POST_UPDATE_SCRIPT - name: Update Changelog if: ${{ inputs.changelog-entry == 'true' && ( steps.target.outputs.latestTag != steps.target.outputs.originalTag ) && ( steps.root.outputs.changed == 'false') }} diff --git a/updater/scripts/update-dependency.ps1 b/updater/scripts/update-dependency.ps1 index 648a3a8..dec0b20 100644 --- a/updater/scripts/update-dependency.ps1 +++ b/updater/scripts/update-dependency.ps1 @@ -16,6 +16,8 @@ param( [string] $GhTitlePattern = '', # Specific version - if passed, no discovery is performed and the version is set directly [string] $Tag = '', + # Version that the dependency was on before the update - should be only passed if $Tag is set. Necessary for PostUpdateScript. + [string] $OriginalTag = '', # Optional post-update script to run after successful dependency update # The script receives the original and new version as arguments [string] $PostUpdateScript = '' @@ -134,6 +136,8 @@ if (-not $isSubmodule) { } if ("$Tag" -eq '') { + $OriginalTag | Should -Be '' + if ($isSubmodule) { git submodule update --init --no-fetch --single-branch $Path Push-Location $Path @@ -250,11 +254,10 @@ if ("$Tag" -eq '') { } $Tag = $latestTag +} else { + $OriginalTag | Should -Not -Be '' } -$originalTagForPostUpdate = if ($originalTag) { $originalTag } else { '' } -$newTagForPostUpdate = $Tag - if ($isSubmodule) { Write-Host "Updating submodule $Path to $Tag" Push-Location $Path diff --git a/updater/tests/update-dependency.Tests.ps1 b/updater/tests/update-dependency.Tests.ps1 index 0d92a02..25bfbed 100644 --- a/updater/tests/update-dependency.Tests.ps1 +++ b/updater/tests/update-dependency.Tests.ps1 @@ -515,6 +515,63 @@ param([string] $originalVersion, [string] $newVersion) Remove-Item $postUpdateScript -ErrorAction SilentlyContinue } + It 'runs PowerShell post-update script when Tag and OriginalTag are explicitly provided' { + $testFile = "$testDir/test.properties" + $repo = 'https://github.com/getsentry/sentry-cli' + @("repo=$repo", 'version=0.27.0') | Out-File $testFile + + $postUpdateScript = "$testDir/post-update-explicit.ps1" + $markerFile = "$testDir/post-update-marker-explicit.txt" + @' +param([string] $originalVersion, [string] $newVersion) +"$originalVersion|$newVersion" | Out-File +'@ + " '$markerFile'" | Out-File $postUpdateScript + + # Simulate the second run where we explicitly set Tag and OriginalTag + $params = @{ + Path = $testFile + Tag = '0.28.0' + OriginalTag = '0.27.0' + PostUpdateScript = $postUpdateScript + } + $result = & "$PSScriptRoot/../scripts/update-dependency.ps1" @params + if (-not $?) { + throw $result + } + + # Verify post-update script was executed with correct versions + Test-Path $markerFile | Should -Be $true + $markerContent = Get-Content $markerFile + $markerContent | Should -Match '^0\.27\.0\|0\.28\.0$' + + # Clean up + Remove-Item $markerFile -ErrorAction SilentlyContinue + Remove-Item $postUpdateScript -ErrorAction SilentlyContinue + } + + It 'fails when Tag is provided without OriginalTag' { + $testFile = "$testDir/test.properties" + $repo = 'https://github.com/getsentry/sentry-cli' + @("repo=$repo", 'version=0.27.0') | Out-File $testFile + + $postUpdateScript = "$testDir/post-update-fail.ps1" + @' +param([string] $originalVersion, [string] $newVersion) +"$originalVersion|$newVersion" | Out-File marker.txt +'@ | Out-File $postUpdateScript + + # This should fail because Tag requires OriginalTag + $params = @{ + Path = $testFile + Tag = '0.28.0' + PostUpdateScript = $postUpdateScript + } + { & "$PSScriptRoot/../scripts/update-dependency.ps1" @params } | Should -Throw '*Expected*to be different*' + + # Clean up + Remove-Item $postUpdateScript -ErrorAction SilentlyContinue + } + It 'runs bash post-update script with version arguments' -Skip:$IsWindows { $testFile = "$testDir/test.properties" $repo = 'https://github.com/getsentry/sentry-cli'