Skip to content

Commit 00adc0d

Browse files
authored
build(checkver): Fix output with '-Version' (#3774)
1 parent 399274e commit 00adc0d

2 files changed

Lines changed: 83 additions & 76 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
### Builds
1313

14+
- **checkver:** Fix output with '-Version' ([#3774](https://github.com/ScoopInstaller/Scoop/issues/3774))
1415
- **schema:** Add '$schema' property ([#4623](https://github.com/ScoopInstaller/Scoop/issues/4623))
1516

1617
### Styles

bin/checkver.ps1

Lines changed: 82 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
Useful for hash updates.
1616
.PARAMETER SkipUpdated
1717
Updated manifests will not be shown.
18+
.PARAMETER Version
19+
Update manifest to specific version.
1820
.EXAMPLE
1921
PS BUCKETROOT > .\bin\checkver.ps1
2022
Check all manifest inside default directory.
@@ -76,6 +78,11 @@ $Dir = Resolve-Path $Dir
7678
$Search = $App
7779
$GitHubToken = $env:SCOOP_CHECKVER_TOKEN, (get_config 'checkver-token') | Where-Object -Property Length -Value 0 -GT | Select-Object -First 1
7880

81+
# don't use $Version with $App = '*'
82+
if ($App -eq '*' -and $Version -ne '') {
83+
throw "Don't use '-Version' with '-App *'!"
84+
}
85+
7986
# get apps to check
8087
$Queue = @()
8188
$json = ''
@@ -205,95 +212,97 @@ while ($in_progress -gt 0) {
205212
$reverse = $state.reverse
206213
$replace = $state.replace
207214
$expected_ver = $json.version
208-
$ver = ''
209-
210-
$page = $ev.SourceEventArgs.Result
211-
$err = $ev.SourceEventArgs.Error
212-
if ($json.checkver.script) {
213-
$page = $json.checkver.script -join "`r`n" | Invoke-Expression
214-
}
215+
$ver = $Version
215216

216-
if ($err) {
217-
next "$($err.message)`r`nURL $url is not valid"
218-
continue
219-
}
220-
221-
if (!$regex -and $replace) {
222-
next "'replace' requires 're' or 'regex'"
223-
continue
224-
}
225-
226-
if ($jsonpath) {
227-
# Return only a single value if regex is absent
228-
$noregex = [String]::IsNullOrEmpty($regex)
229-
# If reverse is ON and regex is ON,
230-
# Then reverse would have no effect because regex handles reverse
231-
# on its own
232-
# So in this case we have to disable reverse
233-
$ver = json_path $page $jsonpath $null ($reverse -and $noregex) $noregex
234-
if (!$ver) {
235-
$ver = json_path_legacy $page $jsonpath
217+
if (!$ver) {
218+
$page = $ev.SourceEventArgs.Result
219+
$err = $ev.SourceEventArgs.Error
220+
if ($json.checkver.script) {
221+
$page = $json.checkver.script -join "`r`n" | Invoke-Expression
236222
}
237-
if (!$ver) {
238-
next "couldn't find '$jsonpath' in $url"
223+
224+
if ($err) {
225+
next "$($err.message)`r`nURL $url is not valid"
239226
continue
240227
}
241-
}
242228

243-
if ($xpath) {
244-
$xml = [xml]$page
245-
# Find all `significant namespace declarations` from the XML file
246-
$nsList = $xml.SelectNodes("//namespace::*[not(. = ../../namespace::*)]")
247-
# Then add them into the NamespaceManager
248-
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
249-
$nsList | ForEach-Object {
250-
$nsmgr.AddNamespace($_.LocalName, $_.Value)
251-
}
252-
# Getting version from XML, using XPath
253-
$ver = $xml.SelectSingleNode($xpath, $nsmgr).'#text'
254-
if (!$ver) {
255-
next "couldn't find '$xpath' in $url"
229+
if (!$regex -and $replace) {
230+
next "'replace' requires 're' or 'regex'"
256231
continue
257232
}
258-
}
259233

260-
if ($jsonpath -and $regexp) {
261-
$page = $ver
262-
$ver = ''
263-
}
234+
if ($jsonpath) {
235+
# Return only a single value if regex is absent
236+
$noregex = [String]::IsNullOrEmpty($regex)
237+
# If reverse is ON and regex is ON,
238+
# Then reverse would have no effect because regex handles reverse
239+
# on its own
240+
# So in this case we have to disable reverse
241+
$ver = json_path $page $jsonpath $null ($reverse -and $noregex) $noregex
242+
if (!$ver) {
243+
$ver = json_path_legacy $page $jsonpath
244+
}
245+
if (!$ver) {
246+
next "couldn't find '$jsonpath' in $url"
247+
continue
248+
}
249+
}
264250

265-
if ($xpath -and $regexp) {
266-
$page = $ver
267-
$ver = ''
268-
}
251+
if ($xpath) {
252+
$xml = [xml]$page
253+
# Find all `significant namespace declarations` from the XML file
254+
$nsList = $xml.SelectNodes("//namespace::*[not(. = ../../namespace::*)]")
255+
# Then add them into the NamespaceManager
256+
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
257+
$nsList | ForEach-Object {
258+
$nsmgr.AddNamespace($_.LocalName, $_.Value)
259+
}
260+
# Getting version from XML, using XPath
261+
$ver = $xml.SelectSingleNode($xpath, $nsmgr).'#text'
262+
if (!$ver) {
263+
next "couldn't find '$xpath' in $url"
264+
continue
265+
}
266+
}
269267

270-
if ($regexp) {
271-
$regex = New-Object System.Text.RegularExpressions.Regex($regexp)
272-
if ($reverse) {
273-
$match = $regex.Matches($page) | Select-Object -Last 1
274-
} else {
275-
$match = $regex.Matches($page) | Select-Object -First 1
268+
if ($jsonpath -and $regexp) {
269+
$page = $ver
270+
$ver = ''
276271
}
277272

278-
if ($match -and $match.Success) {
279-
$matchesHashtable = @{}
280-
$regex.GetGroupNames() | ForEach-Object { $matchesHashtable.Add($_, $match.Groups[$_].Value) }
281-
$ver = $matchesHashtable['1']
282-
if ($replace) {
283-
$ver = $regex.Replace($match.Value, $replace)
273+
if ($xpath -and $regexp) {
274+
$page = $ver
275+
$ver = ''
276+
}
277+
278+
if ($regexp) {
279+
$regex = New-Object System.Text.RegularExpressions.Regex($regexp)
280+
if ($reverse) {
281+
$match = $regex.Matches($page) | Select-Object -Last 1
282+
} else {
283+
$match = $regex.Matches($page) | Select-Object -First 1
284284
}
285-
if (!$ver) {
286-
$ver = $matchesHashtable['version']
285+
286+
if ($match -and $match.Success) {
287+
$matchesHashtable = @{}
288+
$regex.GetGroupNames() | ForEach-Object { $matchesHashtable.Add($_, $match.Groups[$_].Value) }
289+
$ver = $matchesHashtable['1']
290+
if ($replace) {
291+
$ver = $regex.Replace($match.Value, $replace)
292+
}
293+
if (!$ver) {
294+
$ver = $matchesHashtable['version']
295+
}
296+
} else {
297+
next "couldn't match '$regexp' in $url"
298+
continue
287299
}
288-
} else {
289-
next "couldn't match '$regexp' in $url"
290-
continue
291300
}
292-
}
293301

294-
if (!$ver) {
295-
next "couldn't find new version in $url"
296-
continue
302+
if (!$ver) {
303+
next "couldn't find new version in $url"
304+
continue
305+
}
297306
}
298307

299308
# Skip actual only if versions are same and there is no -f
@@ -325,9 +334,6 @@ while ($in_progress -gt 0) {
325334
Write-Host 'Forcing autoupdate!' -ForegroundColor DarkMagenta
326335
}
327336
try {
328-
if ($Version -ne "") {
329-
$ver = $Version
330-
}
331337
Invoke-AutoUpdate $App $Dir $json $ver $matchesHashtable
332338
} catch {
333339
error $_.Exception.Message

0 commit comments

Comments
 (0)