|
1 | 1 | BeforeAll {
|
2 |
| - function UpdateDependency([Parameter(Mandatory = $true)][string] $path, [string] $pattern = $null, [string] $ghTitlePattern = $null) |
| 2 | + function UpdateDependency([Parameter(Mandatory = $true)][string] $path, [string] $pattern = $null, [string] $ghTitlePattern = $null, [string] $postUpdateScript = $null) |
3 | 3 | {
|
4 | 4 | $params = @{ Path = $path }
|
5 | 5 | if ($pattern) { $params.Pattern = $pattern }
|
6 | 6 | if ($ghTitlePattern) { $params.GhTitlePattern = $ghTitlePattern }
|
| 7 | + if ($postUpdateScript) { $params.PostUpdateScript = $postUpdateScript } |
7 | 8 |
|
8 | 9 | $result = & "$PSScriptRoot/../scripts/update-dependency.ps1" @params
|
9 | 10 | if (-not $?)
|
@@ -488,4 +489,123 @@ FetchContent_Declare(
|
488 | 489 | $version | Should -Match '^8\.'
|
489 | 490 | }
|
490 | 491 | }
|
| 492 | + |
| 493 | + Context 'post-update-script' { |
| 494 | + It 'runs PowerShell post-update script with version arguments' { |
| 495 | + $testFile = "$testDir/test.properties" |
| 496 | + $repo = 'https://github.com/getsentry/sentry-cli' |
| 497 | + @("repo=$repo", 'version=0') | Out-File $testFile |
| 498 | + |
| 499 | + $postUpdateScript = "$testDir/post-update-test.ps1" |
| 500 | + $markerFile = "$testDir/post-update-marker.txt" |
| 501 | + @' |
| 502 | +param([string] $originalVersion, [string] $newVersion) |
| 503 | +"$originalVersion|$newVersion" | Out-File |
| 504 | +'@ + " '$markerFile'" | Out-File $postUpdateScript |
| 505 | + |
| 506 | + UpdateDependency $testFile '^0\.' -postUpdateScript $postUpdateScript |
| 507 | + |
| 508 | + # Verify post-update script was executed |
| 509 | + Test-Path $markerFile | Should -Be $true |
| 510 | + $markerContent = Get-Content $markerFile |
| 511 | + $markerContent | Should -Match '^0\|0\.28\.0$' |
| 512 | + |
| 513 | + # Clean up |
| 514 | + Remove-Item $markerFile -ErrorAction SilentlyContinue |
| 515 | + Remove-Item $postUpdateScript -ErrorAction SilentlyContinue |
| 516 | + } |
| 517 | + |
| 518 | + It 'runs bash post-update script with version arguments' -Skip:$IsWindows { |
| 519 | + $testFile = "$testDir/test.properties" |
| 520 | + $repo = 'https://github.com/getsentry/sentry-cli' |
| 521 | + @("repo=$repo", 'version=0') | Out-File $testFile |
| 522 | + |
| 523 | + $postUpdateScript = "$testDir/post-update-test.sh" |
| 524 | + $markerFile = "$testDir/post-update-marker.txt" |
| 525 | + @" |
| 526 | +#!/usr/bin/env bash |
| 527 | +set -euo pipefail |
| 528 | +echo "`$1|`$2" > '$markerFile' |
| 529 | +"@ | Out-File $postUpdateScript |
| 530 | + |
| 531 | + UpdateDependency $testFile '^0\.' -postUpdateScript $postUpdateScript |
| 532 | + |
| 533 | + # Verify post-update script was executed |
| 534 | + Test-Path $markerFile | Should -Be $true |
| 535 | + $markerContent = Get-Content $markerFile |
| 536 | + $markerContent | Should -Match '^0\|0\.28\.0$' |
| 537 | + |
| 538 | + # Clean up |
| 539 | + Remove-Item $markerFile -ErrorAction SilentlyContinue |
| 540 | + Remove-Item $postUpdateScript -ErrorAction SilentlyContinue |
| 541 | + } |
| 542 | + |
| 543 | + It 'fails when post-update script does not exist' { |
| 544 | + $testFile = "$testDir/test.properties" |
| 545 | + $repo = 'https://github.com/getsentry/sentry-cli' |
| 546 | + @("repo=$repo", 'version=0') | Out-File $testFile |
| 547 | + |
| 548 | + $postUpdateScript = "$testDir/nonexistent-script.ps1" |
| 549 | + |
| 550 | + { UpdateDependency $testFile '^0\.' -postUpdateScript $postUpdateScript } | Should -Throw '*Post-update script not found*' |
| 551 | + } |
| 552 | + |
| 553 | + It 'fails when PowerShell post-update script exits with error' { |
| 554 | + $testFile = "$testDir/test.properties" |
| 555 | + $repo = 'https://github.com/getsentry/sentry-cli' |
| 556 | + @("repo=$repo", 'version=0') | Out-File $testFile |
| 557 | + |
| 558 | + $postUpdateScript = "$testDir/failing-post-update.ps1" |
| 559 | + @' |
| 560 | +param([string] $originalVersion, [string] $newVersion) |
| 561 | +throw "Post-update script failed intentionally" |
| 562 | +'@ | Out-File $postUpdateScript |
| 563 | + |
| 564 | + { UpdateDependency $testFile '^0\.' -postUpdateScript $postUpdateScript } | Should -Throw '*Post-update script failed*' |
| 565 | + |
| 566 | + # Clean up |
| 567 | + Remove-Item $postUpdateScript -ErrorAction SilentlyContinue |
| 568 | + } |
| 569 | + |
| 570 | + It 'fails when bash post-update script exits with error' -Skip:$IsWindows { |
| 571 | + $testFile = "$testDir/test.properties" |
| 572 | + $repo = 'https://github.com/getsentry/sentry-cli' |
| 573 | + @("repo=$repo", 'version=0') | Out-File $testFile |
| 574 | + |
| 575 | + $postUpdateScript = "$testDir/failing-post-update.sh" |
| 576 | + @' |
| 577 | +#!/usr/bin/env bash |
| 578 | +exit 1 |
| 579 | +'@ | Out-File $postUpdateScript |
| 580 | + |
| 581 | + { UpdateDependency $testFile '^0\.' -postUpdateScript $postUpdateScript } | Should -Throw '*Post-update script failed*' |
| 582 | + |
| 583 | + # Clean up |
| 584 | + Remove-Item $postUpdateScript -ErrorAction SilentlyContinue |
| 585 | + } |
| 586 | + |
| 587 | + It 'receives empty string for original version when updating from scratch' { |
| 588 | + $testFile = "$testDir/test.properties" |
| 589 | + $repo = 'https://github.com/getsentry/sentry-cli' |
| 590 | + @("repo=$repo", 'version=') | Out-File $testFile |
| 591 | + |
| 592 | + $postUpdateScript = "$testDir/post-update-empty-original.ps1" |
| 593 | + $markerFile = "$testDir/post-update-marker-empty.txt" |
| 594 | + @' |
| 595 | +param([string] $originalVersion, [string] $newVersion) |
| 596 | +"original=[$originalVersion]|new=[$newVersion]" | Out-File |
| 597 | +'@ + " '$markerFile'" | Out-File $postUpdateScript |
| 598 | + |
| 599 | + UpdateDependency $testFile '^0\.' -postUpdateScript $postUpdateScript |
| 600 | + |
| 601 | + # Verify post-update script received empty original version |
| 602 | + Test-Path $markerFile | Should -Be $true |
| 603 | + $markerContent = Get-Content $markerFile |
| 604 | + $markerContent | Should -Match 'original=\[\]\|new=\[0\.28\.0\]' |
| 605 | + |
| 606 | + # Clean up |
| 607 | + Remove-Item $markerFile -ErrorAction SilentlyContinue |
| 608 | + Remove-Item $postUpdateScript -ErrorAction SilentlyContinue |
| 609 | + } |
| 610 | + } |
491 | 611 | }
|
0 commit comments