Skip to content

Commit 71d223e

Browse files
vaindclaude
andauthored
fix(updater): Pass OriginalTag to post-update script on second run (#133)
* fix: Add OriginalTag parameter for post-update script validation * fix: Clarify comment for OriginalTag parameter in update-dependency script * fix(updater): Pass OriginalTag to post-update script on second run When the updater creates a new PR and runs the update-dependency script a second time, it was not passing the OriginalTag parameter. This caused the script to fail validation since Tag requires OriginalTag to be set. Changes: - Updated action.yml to pass OriginalTag on second script execution - Added unit test for explicit Tag/OriginalTag parameters - Added validation test to ensure Tag fails without OriginalTag All 34 tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * fix(changelog): Update post-update-script entry to include related pull requests --------- Co-authored-by: Claude <[email protected]>
1 parent 0bd595f commit 71d223e

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Features
66

7-
- Updater - Add `post-update-script` input parameter to run custom scripts after dependency updates ([#130](https://github.com/getsentry/github-workflows/pull/130))
7+
- 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))
88
- Scripts receive original and new version as arguments
99
- Support both bash (`.sh`) and PowerShell (`.ps1`) scripts
1010
- Enables workflows like updating lock files, running code generators, or modifying configuration files

updater/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ runs:
288288
DEPENDENCY_PATH: ${{ inputs.path }}
289289
POST_UPDATE_SCRIPT: ${{ inputs.post-update-script }}
290290
GH_TOKEN: ${{ inputs.api-token }}
291-
run: ${{ github.action_path }}/scripts/update-dependency.ps1 -Path $env:DEPENDENCY_PATH -Tag '${{ steps.target.outputs.latestTag }}' -PostUpdateScript $env:POST_UPDATE_SCRIPT
291+
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
292292

293293
- name: Update Changelog
294294
if: ${{ inputs.changelog-entry == 'true' && ( steps.target.outputs.latestTag != steps.target.outputs.originalTag ) && ( steps.root.outputs.changed == 'false') }}

updater/scripts/update-dependency.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ param(
1616
[string] $GhTitlePattern = '',
1717
# Specific version - if passed, no discovery is performed and the version is set directly
1818
[string] $Tag = '',
19+
# Version that the dependency was on before the update - should be only passed if $Tag is set. Necessary for PostUpdateScript.
20+
[string] $OriginalTag = '',
1921
# Optional post-update script to run after successful dependency update
2022
# The script receives the original and new version as arguments
2123
[string] $PostUpdateScript = ''
@@ -134,6 +136,8 @@ if (-not $isSubmodule) {
134136
}
135137

136138
if ("$Tag" -eq '') {
139+
$OriginalTag | Should -Be ''
140+
137141
if ($isSubmodule) {
138142
git submodule update --init --no-fetch --single-branch $Path
139143
Push-Location $Path
@@ -250,11 +254,10 @@ if ("$Tag" -eq '') {
250254
}
251255

252256
$Tag = $latestTag
257+
} else {
258+
$OriginalTag | Should -Not -Be ''
253259
}
254260

255-
$originalTagForPostUpdate = if ($originalTag) { $originalTag } else { '' }
256-
$newTagForPostUpdate = $Tag
257-
258261
if ($isSubmodule) {
259262
Write-Host "Updating submodule $Path to $Tag"
260263
Push-Location $Path

updater/tests/update-dependency.Tests.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,63 @@ param([string] $originalVersion, [string] $newVersion)
515515
Remove-Item $postUpdateScript -ErrorAction SilentlyContinue
516516
}
517517

518+
It 'runs PowerShell post-update script when Tag and OriginalTag are explicitly provided' {
519+
$testFile = "$testDir/test.properties"
520+
$repo = 'https://github.com/getsentry/sentry-cli'
521+
@("repo=$repo", 'version=0.27.0') | Out-File $testFile
522+
523+
$postUpdateScript = "$testDir/post-update-explicit.ps1"
524+
$markerFile = "$testDir/post-update-marker-explicit.txt"
525+
@'
526+
param([string] $originalVersion, [string] $newVersion)
527+
"$originalVersion|$newVersion" | Out-File
528+
'@ + " '$markerFile'" | Out-File $postUpdateScript
529+
530+
# Simulate the second run where we explicitly set Tag and OriginalTag
531+
$params = @{
532+
Path = $testFile
533+
Tag = '0.28.0'
534+
OriginalTag = '0.27.0'
535+
PostUpdateScript = $postUpdateScript
536+
}
537+
$result = & "$PSScriptRoot/../scripts/update-dependency.ps1" @params
538+
if (-not $?) {
539+
throw $result
540+
}
541+
542+
# Verify post-update script was executed with correct versions
543+
Test-Path $markerFile | Should -Be $true
544+
$markerContent = Get-Content $markerFile
545+
$markerContent | Should -Match '^0\.27\.0\|0\.28\.0$'
546+
547+
# Clean up
548+
Remove-Item $markerFile -ErrorAction SilentlyContinue
549+
Remove-Item $postUpdateScript -ErrorAction SilentlyContinue
550+
}
551+
552+
It 'fails when Tag is provided without OriginalTag' {
553+
$testFile = "$testDir/test.properties"
554+
$repo = 'https://github.com/getsentry/sentry-cli'
555+
@("repo=$repo", 'version=0.27.0') | Out-File $testFile
556+
557+
$postUpdateScript = "$testDir/post-update-fail.ps1"
558+
@'
559+
param([string] $originalVersion, [string] $newVersion)
560+
"$originalVersion|$newVersion" | Out-File marker.txt
561+
'@ | Out-File $postUpdateScript
562+
563+
# This should fail because Tag requires OriginalTag
564+
$params = @{
565+
Path = $testFile
566+
Tag = '0.28.0'
567+
PostUpdateScript = $postUpdateScript
568+
}
569+
{ & "$PSScriptRoot/../scripts/update-dependency.ps1" @params } | Should -Throw '*Expected*to be different*'
570+
571+
# Clean up
572+
Remove-Item $postUpdateScript -ErrorAction SilentlyContinue
573+
}
574+
518575
It 'runs bash post-update script with version arguments' -Skip:$IsWindows {
519576
$testFile = "$testDir/test.properties"
520577
$repo = 'https://github.com/getsentry/sentry-cli'

0 commit comments

Comments
 (0)