-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add multiple URL support for autoupdate #2803
Closed
rasa
wants to merge
5
commits into
ScoopInstaller:develop
from
rasa:rasa/multiple-urls-in-autoupdate
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0bb8318
Add multiple URL support for autoupdate
rasa 646ab52
Add multiple URL autoupdate support to schema
rasa 9ca051c
Fix typo
rasa ae350e0
Add autoupdateUriOrArrayOfAutoupdateUris to schema.json
rasa e856483
Enhance lets_do_autoupdates to return more info
Ash258 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,11 +250,11 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u | |
return $hash | ||
} | ||
|
||
function update_manifest_with_new_version($json, [String] $version, [String] $url, [String] $hash, $architecture = $null) { | ||
function update_manifest_with_new_version($json, [String] $version, $url, $hash, $architecture = $null) { | ||
$json.version = $version | ||
|
||
if ($null -eq $architecture) { | ||
if ($json.url -is [System.Array]) { | ||
if ($json.url -is [System.Array] -and $url -isnot [System.Array]) { | ||
$json.url[0] = $url | ||
$json.hash[0] = $hash | ||
} else { | ||
|
@@ -263,7 +263,7 @@ function update_manifest_with_new_version($json, [String] $version, [String] $ur | |
} | ||
} else { | ||
# If there are multiple urls we replace the first one | ||
if ($json.architecture.$architecture.url -is [System.Array]) { | ||
if ($json.architecture.$architecture.url -is [System.Array] -and $url -isnot [System.Array]) { | ||
$json.architecture.$architecture.url[0] = $url | ||
$json.architecture.$architecture.hash[0] = $hash | ||
} else { | ||
|
@@ -318,34 +318,81 @@ function get_version_substitutions([String] $version, [Hashtable] $customMatches | |
return $versionVariables | ||
} | ||
|
||
function autoupdate([String] $app, $dir, $json, [String] $version, [Hashtable] $matches) { | ||
Write-Host -f DarkCyan "Autoupdating $app" | ||
function lets_do_autoupdates([String] $app, $json, [String] $version, $substitutions) { | ||
$urls = @() | ||
$hashes = @() | ||
$has_changes = $false | ||
$has_errors = $false | ||
[Bool]$valid = $true | ||
$substitutions = get_version_substitutions $version $matches | ||
|
||
if ($json.url) { | ||
for ($i=0; $i -lt $json.autoupdate.url.Length; $i++) { | ||
# create new url | ||
$url = substitute $json.autoupdate.url $substitutions | ||
$valid = $true | ||
$url = substitute $json.autoupdate.url[$i] $substitutions | ||
$urls += $url | ||
|
||
if($valid) { | ||
# create hash | ||
$hash = get_hash_for_app $app $json.autoupdate.hash $version $url $substitutions | ||
if ($json.autoupdate.hash.length -gt $i) { | ||
$h = $json.autoupdate.hash[$i] | ||
} else { | ||
$h = $null | ||
} | ||
$hash = get_hash_for_app $app $h $version $url $substitutions | ||
$hashes += $hash | ||
if ($null -eq $hash) { | ||
$valid = $false | ||
Write-Host -f DarkRed "Could not find hash!" | ||
} | ||
} | ||
} | ||
|
||
# write changes to the json object | ||
if ($valid) { | ||
$has_changes = $true | ||
update_manifest_with_new_version $json $version $urls $hashes | ||
} else { | ||
$has_errors = $true | ||
throw "Could not update $app" | ||
} | ||
|
||
return $has_changes, $has_errors | ||
} | ||
|
||
|
||
function autoupdate([String] $app, $dir, $json, [String] $version, [Hashtable] $matches) { | ||
Write-Host -f DarkCyan "Autoupdating $app" | ||
$has_changes = $false | ||
$has_errors = $false | ||
[Bool]$valid = $true | ||
$substitutions = get_version_substitutions $version $matches | ||
|
||
# write changes to the json object | ||
if ($valid) { | ||
$has_changes = $true | ||
update_manifest_with_new_version $json $version $url $hash | ||
if ($json.url) { | ||
if ($json.autoupdate.url -is [System.Array]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This if...else... should be applied to |
||
$return = lets_do_autoupdates $app $json $version $substitutions | ||
rasa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$has_changes = $return[0] | ||
$has_errors = $return[1] | ||
} else { | ||
$has_errors = $true | ||
throw "Could not update $app" | ||
# create new url | ||
$url = substitute $json.autoupdate.url $substitutions | ||
$valid = $true | ||
|
||
if($valid) { | ||
# create hash | ||
$hash = get_hash_for_app $app $json.autoupdate.hash $version $url $substitutions | ||
if ($null -eq $hash) { | ||
$valid = $false | ||
Write-Host -f DarkRed "Could not find hash!" | ||
} | ||
} | ||
|
||
# write changes to the json object | ||
if ($valid) { | ||
$has_changes = $true | ||
update_manifest_with_new_version $json $version $url $hash | ||
} else { | ||
$has_errors = $true | ||
throw "Could not update $app" | ||
} | ||
} | ||
} else { | ||
$json.architecture | Get-Member -MemberType NoteProperty | ForEach-Object { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
hash
's length is less thanurl
, the lasthash
expression is reused for remainingurl
s.So we could use one
hash
expression for all theseurl
s if hash extraction url and regex are the same, e.g.,$sha256.*?$basename
, different hashes for different$basename
s.