Skip to content

Commit e211f8e

Browse files
committed
tests and other fixes
1 parent fdc292f commit e211f8e

File tree

2 files changed

+65
-51
lines changed

2 files changed

+65
-51
lines changed

updater/scripts/update-dependency.ps1

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,33 @@ if ("$Tag" -eq '')
157157

158158
Write-Host "Sorted tags: $tags"
159159
$latestTag = $tags[-1]
160+
161+
if (("$originalTag" -ne '') -and ("$latestTag" -ne '') -and ("$latestTag" -ne "$originalTag"))
162+
{
163+
do
164+
{
165+
# It's possible that the dependency was updated to a pre-release version manually in which case we don't want to
166+
# roll back, even though it's not the latest version matching the configured pattern.
167+
if ((GetComparableVersion $originalTag) -ge (GetComparableVersion $latestTag))
168+
{
169+
Write-Host "SemVer represented by the original tag '$originalTag' is newer than the latest tag '$latestTag'. Skipping update."
170+
$latestTag = $originalTag
171+
break
172+
}
173+
174+
# Verify that the latest tag actually points to a different commit. Otherwise, we don't need to update.
175+
$refs = $(git ls-remote --tags $url)
176+
$refOriginal = (($refs -match "refs/tags/$originalTag" ) -split '[ \t]') | Select-Object -First 1
177+
$refLatest = (($refs -match "refs/tags/$latestTag" ) -split '[ \t]') | Select-Object -First 1
178+
if ($refOriginal -eq $refLatest)
179+
{
180+
Write-Host "Latest tag '$latestTag' points to the same commit as the original tag '$originalTag'. Skipping update."
181+
$latestTag = $originalTag
182+
break
183+
}
184+
} while ($false)
185+
}
186+
160187
$latestTagNice = ($latestTag -match '^[0-9]') ? "v$latestTag" : $latestTag
161188

162189
SetOutput 'originalTag' $originalTag
@@ -170,27 +197,6 @@ if ("$Tag" -eq '')
170197
return
171198
}
172199

173-
if (("$originalTag" -ne '') -and ("$latestTag" -ne ''))
174-
{
175-
# It's possible that the dependency was updated to a pre-release version manually in which case we don't want to
176-
# roll back, even though it's not the latest version matching the configured pattern.
177-
if ((GetComparableVersion $originalTag) -ge (GetComparableVersion $latestTag))
178-
{
179-
Write-Host "SemVer represented by the original tag '$originalTag' is newer than the latest tag '$latestTag'. Skipping update."
180-
return
181-
}
182-
183-
# Verify that the latest tag actually points to a different commit. Otherwise, we don't need to update.
184-
$refs = $(git ls-remote --tags $url)
185-
$refOriginal = (($refs -match "refs/tags/$originalTag" ) -split '[ \t]') | Select-Object -First 1
186-
$refLatest = (($refs -match "refs/tags/$latestTag" ) -split '[ \t]') | Select-Object -First 1
187-
if ($refOriginal -eq $refLatest)
188-
{
189-
Write-Host "Latest tag '$latestTag' points to the same commit as the original tag '$originalTag'. Skipping update."
190-
return
191-
}
192-
}
193-
194200
$Tag = $latestTag
195201
}
196202

updater/tests/update-dependency.ps1

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ $repoUrl = 'https://github.com/getsentry/github-workflows'
2323
$currentVersion = (git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' $repoUrl `
2424
| Select-Object -Last 1 | Select-String -Pattern 'refs/tags/(.*)$').Matches.Groups[1].Value
2525

26-
RunTest "properties-file" {
26+
RunTest 'properties-file' {
2727
$testFile = "$testDir/test.properties"
28-
@("repo=$repoUrl", "version = none") | Out-File $testFile
28+
@("repo=$repoUrl", 'version = none') | Out-File $testFile
2929
UpdateDependency $testFile
3030
AssertEqual @("repo=$repoUrl", "version = $currentVersion") (Get-Content $testFile)
3131
}
3232

33-
RunTest "version pattern match" {
33+
RunTest 'version pattern match' {
3434
$testFile = "$testDir/test.properties"
3535
$repo = 'https://github.com/getsentry/sentry-cli'
36-
@("repo=$repo", "version=0") | Out-File $testFile
36+
@("repo=$repo", 'version=0') | Out-File $testFile
3737
UpdateDependency $testFile '^0\.'
38-
AssertEqual @("repo=$repo", "version=0.28.0") (Get-Content $testFile)
38+
AssertEqual @("repo=$repo", 'version=0.28.0') (Get-Content $testFile)
3939
}
4040

4141
function _testOutput([string[]] $output)
@@ -48,27 +48,27 @@ function _testOutput([string[]] $output)
4848
AssertContains $output 'mainBranch=master'
4949
}
5050

51-
RunTest "writes output" {
51+
RunTest 'writes output' {
5252
$testFile = "$testDir/test.properties"
5353
$repo = 'https://github.com/getsentry/sentry-cli'
54-
@("repo=$repo", "version=0") | Out-File $testFile
54+
@("repo=$repo", 'version=0') | Out-File $testFile
5555
$stdout = UpdateDependency $testFile '^0\.'
5656
_testOutput $stdout
5757
}
5858

59-
RunTest "writes to env:GITHUB_OUTPUT" {
59+
RunTest 'writes to env:GITHUB_OUTPUT' {
6060
$testFile = "$testDir/test.properties"
6161
$repo = 'https://github.com/getsentry/sentry-cli'
62-
@("repo=$repo", "version=0") | Out-File $testFile
62+
@("repo=$repo", 'version=0') | Out-File $testFile
6363
$outFile = "$testDir/outfile"
6464
New-Item $outFile -ItemType File | Out-Null
6565
try
6666
{
6767
$env:GITHUB_OUTPUT = $outFile
6868
$stdout = UpdateDependency $testFile '^0\.'
69-
Write-Host "Testing standard output"
69+
Write-Host 'Testing standard output'
7070
_testOutput $stdout
71-
Write-Host "Testing env:GITHUB_OUTPUT"
71+
Write-Host 'Testing env:GITHUB_OUTPUT'
7272
_testOutput (Get-Content $outFile)
7373
}
7474
finally
@@ -80,15 +80,23 @@ RunTest "writes to env:GITHUB_OUTPUT" {
8080
}
8181

8282
# Note: without custom sorting, this would have yielded 'v1.7.31_gradle_plugin'
83-
RunTest "version sorting must work properly" {
83+
RunTest 'version sorting must work properly' {
8484
$testFile = "$testDir/test.properties"
8585
$repo = 'https://github.com/getsentry/sentry-java'
86-
@("repo=$repo", "version=0") | Out-File $testFile
86+
@("repo=$repo", 'version=0') | Out-File $testFile
8787
UpdateDependency $testFile '^v?[123].*$'
88-
AssertEqual @("repo=$repo", "version=3.2.1") (Get-Content $testFile)
88+
AssertEqual @("repo=$repo", 'version=3.2.1') (Get-Content $testFile)
8989
}
9090

91-
RunTest "powershell-script" {
91+
RunTest 'will not update from a later release to an earlier release' {
92+
$testFile = "$testDir/test.properties"
93+
$repo = 'https://github.com/getsentry/sentry-java'
94+
@("repo=$repo", 'version=999.0.0-beta.1') | Out-File $testFile
95+
UpdateDependency $testFile
96+
AssertEqual @("repo=$repo", 'version=999.0.0-beta.1') (Get-Content $testFile)
97+
}
98+
99+
RunTest 'powershell-script' {
92100
$testFile = "$testDir/test.version"
93101
'' | Out-File $testFile
94102
$testScript = "$testDir/test.ps1"
@@ -109,7 +117,7 @@ switch ($action)
109117
AssertEqual $currentVersion (Get-Content $testFile)
110118
}
111119

112-
RunTest "bash-script" {
120+
RunTest 'bash-script' {
113121
$testFile = "$testDir/test.version"
114122
'' | Out-File $testFile
115123
$testScript = "$testDir/test.sh"
@@ -136,29 +144,29 @@ esac
136144
'@ | Out-File $testScript
137145
UpdateDependency $testScript
138146
AssertEqual $currentVersion (Get-Content $testFile)
139-
} -skipReason ($IsWindows ? "on Windows" : '')
147+
} -skipReason ($IsWindows ? 'on Windows' : '')
140148

141-
RunTest "powershell-script fails in get-version" {
149+
RunTest 'powershell-script fails in get-version' {
142150
$testScript = "$testDir/test.ps1"
143151
@'
144152
throw "Failure"
145153
'@ | Out-File $testScript
146154

147-
AssertFailsWith "get-version | output: Failure" { UpdateDependency $testScript }
155+
AssertFailsWith 'get-version | output: Failure' { UpdateDependency $testScript }
148156
}
149157

150-
RunTest "bash-script fails in get-version" {
158+
RunTest 'bash-script fails in get-version' {
151159
$testScript = "$testDir/test.sh"
152160
@'
153161
#!/usr/bin/env bash
154162
echo "Failure"
155163
exit 1
156164
'@ | Out-File $testScript
157165

158-
AssertFailsWith "get-version | output: Failure" { UpdateDependency $testScript }
159-
} -skipReason ($IsWindows ? "on Windows" : '')
166+
AssertFailsWith 'get-version | output: Failure' { UpdateDependency $testScript }
167+
} -skipReason ($IsWindows ? 'on Windows' : '')
160168

161-
RunTest "powershell-script fails in get-repo" {
169+
RunTest 'powershell-script fails in get-repo' {
162170
$testScript = "$testDir/test.ps1"
163171
@'
164172
param([string] $action, [string] $value)
@@ -168,10 +176,10 @@ if ($action -eq "get-repo")
168176
}
169177
'@ | Out-File $testScript
170178

171-
AssertFailsWith "get-repo | output: Failure" { UpdateDependency $testScript }
179+
AssertFailsWith 'get-repo | output: Failure' { UpdateDependency $testScript }
172180
}
173181

174-
RunTest "bash-script fails in get-repo" {
182+
RunTest 'bash-script fails in get-repo' {
175183
$testScript = "$testDir/test.sh"
176184
@'
177185
#!/usr/bin/env bash
@@ -186,10 +194,10 @@ get-repo)
186194
esac
187195
'@ | Out-File $testScript
188196

189-
AssertFailsWith "get-repo | output: Failure" { UpdateDependency $testScript }
190-
} -skipReason ($IsWindows ? "on Windows" : '')
197+
AssertFailsWith 'get-repo | output: Failure' { UpdateDependency $testScript }
198+
} -skipReason ($IsWindows ? 'on Windows' : '')
191199

192-
RunTest "powershell-script fails in set-version" {
200+
RunTest 'powershell-script fails in set-version' {
193201
$testScript = "$testDir/test.ps1"
194202
@'
195203
param([string] $action, [string] $value)
@@ -206,7 +214,7 @@ switch ($action)
206214
AssertFailsWith "set-version $currentVersion | output: Failure" { UpdateDependency $testScript }
207215
}
208216

209-
RunTest "bash-script fails in set-version" {
217+
RunTest 'bash-script fails in set-version' {
210218
$testScript = "$testDir/test.sh"
211219
@'
212220
#!/usr/bin/env bash
@@ -228,4 +236,4 @@ esac
228236
'@ | Out-File $testScript
229237

230238
AssertFailsWith "set-version $currentVersion | output: Failure" { UpdateDependency $testScript }
231-
} -skipReason ($IsWindows ? "on Windows" : '')
239+
} -skipReason ($IsWindows ? 'on Windows' : '')

0 commit comments

Comments
 (0)