Skip to content

Commit fdc292f

Browse files
committed
more fixes
1 parent 9b56391 commit fdc292f

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

updater/scripts/common.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
function GetComparableVersion([Parameter(Mandatory = $true)][string] $value)
2+
function GetComparableVersion([string] $value)
33
{
44
$value = $value -replace '^v', ''
55
try {

updater/scripts/update-dependency.ps1

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ if (-not $isSubmodule)
4646
if (Get-Command 'chmod' -ErrorAction SilentlyContinue)
4747
{
4848
chmod +x $Path
49-
if ($LastExitCode -ne 0) {
50-
throw "chmod failed";
49+
if ($LastExitCode -ne 0)
50+
{
51+
throw 'chmod failed';
5152
}
5253
}
5354
try
@@ -70,18 +71,18 @@ if (-not $isSubmodule)
7071
{
7172
switch ($action)
7273
{
73-
"get-version"
74+
'get-version'
7475
{
7576
return (Get-Content $Path -Raw | ConvertFrom-StringData).version
7677
}
77-
"get-repo"
78+
'get-repo'
7879
{
7980
return (Get-Content $Path -Raw | ConvertFrom-StringData).repo
8081
}
81-
"set-version"
82+
'set-version'
8283
{
8384
$content = Get-Content $Path
84-
$content = $content -replace "^(?<prop>version *= *).*$", "`${prop}$value"
85+
$content = $content -replace '^(?<prop>version *= *).*$', "`${prop}$value"
8586
$content | Out-File $Path
8687

8788
$readVersion = (Get-Content $Path -Raw | ConvertFrom-StringData).version
@@ -100,7 +101,7 @@ if (-not $isSubmodule)
100101
}
101102
}
102103

103-
if ("$Tag" -eq "")
104+
if ("$Tag" -eq '')
104105
{
105106
if ($isSubmodule)
106107
{
@@ -112,7 +113,7 @@ if ("$Tag" -eq "")
112113
git fetch --tags
113114
[string[]]$tags = $(git tag --list)
114115
$url = $(git remote get-url origin)
115-
$mainBranch = $(git remote show origin | Select-String "HEAD branch: (.*)").Matches[0].Groups[1].Value
116+
$mainBranch = $(git remote show origin | Select-String 'HEAD branch: (.*)').Matches[0].Groups[1].Value
116117
}
117118
finally
118119
{
@@ -126,9 +127,9 @@ if ("$Tag" -eq "")
126127

127128
# Get tags for a repo without cloning.
128129
[string[]]$tags = $(git ls-remote --refs --tags $url)
129-
$tags = $tags | ForEach-Object { ($_ -split "\s+")[1] -replace '^refs/tags/', '' }
130+
$tags = $tags | ForEach-Object { ($_ -split '\s+')[1] -replace '^refs/tags/', '' }
130131

131-
$headRef = ($(git ls-remote $url HEAD) -split "\s+")[0]
132+
$headRef = ($(git ls-remote $url HEAD) -split '\s+')[0]
132133
if ("$headRef" -eq '')
133134
{
134135
throw "Couldn't determine repository head (no ref returned by ls-remote HEAD"
@@ -156,35 +157,38 @@ if ("$Tag" -eq "")
156157

157158
Write-Host "Sorted tags: $tags"
158159
$latestTag = $tags[-1]
159-
$latestTagNice = ($latestTag -match "^[0-9]") ? "v$latestTag" : $latestTag
160+
$latestTagNice = ($latestTag -match '^[0-9]') ? "v$latestTag" : $latestTag
160161

161-
SetOutput "originalTag" $originalTag
162-
SetOutput "latestTag" $latestTag
163-
SetOutput "latestTagNice" $latestTagNice
164-
SetOutput "url" $url
165-
SetOutput "mainBranch" $mainBranch
162+
SetOutput 'originalTag' $originalTag
163+
SetOutput 'latestTag' $latestTag
164+
SetOutput 'latestTagNice' $latestTagNice
165+
SetOutput 'url' $url
166+
SetOutput 'mainBranch' $mainBranch
166167

167168
if ("$originalTag" -eq "$latestTag")
168169
{
169170
return
170171
}
171172

172-
# It's possible that the dependency was updated to a pre-release version manually in which case we don't want to
173-
# roll back, even though it's not the latest version matching the configured pattern.
174-
if ((GetComparableVersion $originalTag) -ge (GetComparableVersion $latestTag))
173+
if (("$originalTag" -ne '') -and ("$latestTag" -ne ''))
175174
{
176-
Write-Host "SemVer represented by the original tag '$originalTag' is newer than the latest tag '$latestTag'. Skipping update."
177-
return
178-
}
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+
}
179182

180-
# Verify that the latest tag actually points to a different commit. Otherwise, we don't need to update.
181-
$refs = $(git ls-remote --tags $url)
182-
$refOriginal = (($refs -match "refs/tags/$originalTag" ) -split "[ \t]") | Select-Object -First 1
183-
$refLatest = (($refs -match "refs/tags/$latestTag" ) -split "[ \t]") | Select-Object -First 1
184-
if ($refOriginal -eq $refLatest)
185-
{
186-
Write-Host "Latest tag '$latestTag' points to the same commit as the original tag '$originalTag'. Skipping update."
187-
return
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+
}
188192
}
189193

190194
$Tag = $latestTag

0 commit comments

Comments
 (0)