1
- using NuGet . Configuration ;
1
+ using DotNetConfig ;
2
+ using NuGet . Configuration ;
2
3
using NuGet . Protocol . Core . Types ;
3
4
using NuGet . Versioning ;
4
5
using Spectre . Console ;
@@ -31,7 +32,7 @@ public static async Task<int> RunWithUpdatesAsync(this ICommandApp app, string[]
31
32
/// </summary>
32
33
public static async Task ShowUpdatesAsync ( this ICommandApp app , string [ ] args )
33
34
{
34
- if ( await GetUpdatesAsync ( args ) is { Length : > 0 } messages )
35
+ if ( await GetUpdatesAsync ( args , true ) is { Length : > 0 } messages )
35
36
{
36
37
foreach ( var message in messages )
37
38
AnsiConsole . MarkupLine ( message ) ;
@@ -48,18 +49,29 @@ public static void ShowVersion(this ICommandApp app)
48
49
AnsiConsole . MarkupLine ( $ "[link]{ ThisAssembly . Git . Url } /releases/tag/{ ThisAssembly . Project . BuildRef } [/]") ;
49
50
}
50
51
51
- static async Task < string [ ] > GetUpdatesAsync ( string [ ] args )
52
+ static async Task < string [ ] > GetUpdatesAsync ( string [ ] args , bool forced = false )
52
53
{
53
54
if ( args . Contains ( "-u" ) || args . Contains ( "--unattended" ) )
54
55
return [ ] ;
55
56
57
+ var config = Config . Build ( ConfigLevel . Global ) . GetSection ( ThisAssembly . Project . ToolCommandName ) ;
58
+
59
+ // Check once a day max
60
+ if ( ! forced )
61
+ {
62
+ var lastCheck = config . GetDateTime ( "checked" ) ?? DateTime . UtcNow . AddDays ( - 2 ) ;
63
+ // if it's been > 24 hours since the last check, we'll check again
64
+ if ( lastCheck > DateTime . UtcNow . AddDays ( - 1 ) )
65
+ return [ ] ;
66
+ }
67
+
56
68
// We check from a different feed in this case.
57
69
var civersion = ThisAssembly . Project . VersionPrefix . StartsWith ( "42.42." ) ;
58
70
59
71
var providers = Repository . Provider . GetCoreV3 ( ) ;
60
72
var repository = new SourceRepository ( new PackageSource (
61
73
// use CI feed rather than production feed depending on which version we're using
62
- civersion ?
74
+ civersion && ! string . IsNullOrEmpty ( ThisAssembly . Project . SLEET_FEED_URL ) ?
63
75
ThisAssembly . Project . SLEET_FEED_URL :
64
76
"https://api.nuget.org/v3/index.json" ) , providers ) ;
65
77
var resource = await repository . GetResourceAsync < PackageMetadataResource > ( ) ;
@@ -80,6 +92,8 @@ static async Task<string[]> GetUpdatesAsync(string[] args)
80
92
. Select ( x => x . Version )
81
93
. FirstOrDefault ( ) ;
82
94
95
+ config . SetDateTime ( "checked" , DateTime . UtcNow ) ;
96
+
83
97
if ( update != null )
84
98
{
85
99
return [
0 commit comments