Skip to content

Commit 3d3bb2d

Browse files
pynapponiheaven
authored andcommitted
feat(config): Allow scoop to check and update 'nightly' apps (ScoopInstaller#5166)
Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>
1 parent ebda3d9 commit 3d3bb2d

7 files changed

Lines changed: 37 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## [Unreleased](https://github.com/ScoopInstaller/Scoop/compare/master...develop)
22

3+
### Features
4+
5+
- **config:** Allow Scoop to check if apps versioned as 'nightly' are outdated ([#5166](https://github.com/ScoopInstaller/Scoop/issues/5166))
6+
37
### Bug Fixes
48

59
- **decompress:** Use PS's default 'Expand-Archive()' ([#5185](https://github.com/ScoopInstaller/Scoop/issues/5185))

lib/install.ps1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
function nightly_version($date, $quiet = $false) {
2-
$date_str = $date.tostring("yyyyMMdd")
1+
function nightly_version($quiet = $false) {
32
if (!$quiet) {
43
warn "This is a nightly version. Downloaded files won't be verified."
54
}
6-
"nightly-$date_str"
5+
return "nightly-$(Get-Date -Format 'yyyyMMdd')"
76
}
87

98
function install_app($app, $architecture, $global, $suggested, $use_cache = $true, $check_hash = $true) {
@@ -21,7 +20,7 @@ function install_app($app, $architecture, $global, $suggested, $use_cache = $tru
2120

2221
$is_nightly = $version -eq 'nightly'
2322
if ($is_nightly) {
24-
$version = nightly_version $(get-date)
23+
$version = nightly_version
2524
$check_hash = $false
2625
}
2726

lib/versions.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,20 @@ function Compare-Version {
147147
$splitReferenceVersion = @(SplitVersion -Version $ReferenceVersion -Delimiter $Delimiter)
148148
$splitDifferenceVersion = @(SplitVersion -Version $DifferenceVersion -Delimiter $Delimiter)
149149

150-
# Nightly versions are always equal
150+
# Nightly versions are always equal unless UPDATE_NIGHTLY is $true
151151
if ($splitReferenceVersion[0] -eq 'nightly' -and $splitDifferenceVersion[0] -eq 'nightly') {
152-
return 0
152+
if (get_config UPDATE_NIGHTLY) {
153+
# nightly versions will be compared by date if UPDATE_NIGHTLY is $true
154+
if ($null -eq $splitReferenceVersion[1]) {
155+
$splitReferenceVersion += Get-Date -Format 'yyyyMMdd'
156+
}
157+
if ($null -eq $splitDifferenceVersion[1]) {
158+
$splitDifferenceVersion += Get-Date -Format 'yyyyMMdd'
159+
}
160+
return [Math]::Sign($splitDifferenceVersion[1] - $splitReferenceVersion[1])
161+
} else {
162+
return 0
163+
}
153164
}
154165

155166
for ($i = 0; $i -lt [Math]::Max($splitReferenceVersion.Length, $splitDifferenceVersion.Length); $i++) {

libexec/scoop-config.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
# Should be in the format 'YYYY-MM-DD', 'YYYY/MM/DD' or any other forms that accepted by '[System.DateTime]::Parse()'.
112112
# Ref: https://docs.microsoft.com/dotnet/api/system.datetime.parse?view=netframework-4.5#StringToParse
113113
#
114+
# update_nightly: $true|$false
115+
# Nightly version is formatted as 'nightly-yyyyMMdd' and will be updated after one day if this is set to $true.
116+
# Otherwise, nightly version will not be updated unless `--force` is used.
117+
#
114118
# ARIA2 configuration
115119
# -------------------
116120
#

libexec/scoop-download.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ foreach ($curr_app in $apps) {
8585

8686
$curr_check_hash = $check_hash
8787
if ($version -eq 'nightly') {
88-
$version = nightly_version $(get-date)
88+
$version = nightly_version
8989
$curr_check_hash = $false
9090
}
9191

libexec/scoop-update.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function update($app, $global, $quiet = $false, $independent, $suggested, $use_c
202202
$version = $manifest.version
203203
$is_nightly = $version -eq 'nightly'
204204
if ($is_nightly) {
205-
$version = nightly_version $(get-date) $quiet
205+
$version = nightly_version $quiet
206206
$check_hash = $false
207207
}
208208

test/Scoop-Versions.Tests.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,21 @@ Describe 'versions comparison' -Tag 'Scoop' {
9090
}
9191

9292
It 'handles equal versions' {
93+
function get_config { $null }
9394
Compare-Version '12.0' '12.0' | Should -Be 0
9495
Compare-Version '7.0.4-9' '7.0.4-9' | Should -Be 0
9596
Compare-Version 'nightly-20190801' 'nightly' | Should -Be 0
9697
Compare-Version 'nightly-20190801' 'nightly-20200801' | Should -Be 0
9798
}
99+
100+
It 'handles nightly versions with `update_nightly`' {
101+
function get_config { $true }
102+
Mock Get-Date { '20200801' }
103+
Compare-Version 'nightly-20200801' 'nightly' | Should -Be 0
104+
Compare-Version 'nightly-20200730' 'nightly' | Should -Be 1
105+
Compare-Version 'nightly-20200730' 'nightly-20200801' | Should -Be 1
106+
Compare-Version 'nightly-20200802' 'nightly' | Should -Be -1
107+
Compare-Version 'nightly-20200802' 'nightly-20200801' | Should -Be -1
108+
}
98109
}
99110
}

0 commit comments

Comments
 (0)