@@ -17,8 +17,7 @@ namespace WinGetStore.Helpers
1717 public static class UpdateHelper
1818 {
1919#if CANARY
20- private const string GITHUB_API = "https://api.github.com/repos/{0}/{1}/actions/artifacts" ;
21- private const string GITHUB_RUNS_API = "https://api.github.com/repos/{0}/{1}/actions/runs/{2}" ;
20+ private const string GITHUB_API = "https://api.github.com/repos/{0}/{1}/actions/runs" ;
2221
2322 public static ValueTask < UpdateInfo > CheckUpdateAsync ( string username , string repository )
2423 {
@@ -58,55 +57,51 @@ public static async ValueTask<UpdateInfo> CheckUpdateAsync(string username, stri
5857 _ = response . EnsureSuccessStatusCode ( ) ;
5958 if ( response . StatusCode != HttpStatusCode . OK ) { return null ; }
6059 string responseBody = await response . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
61- ArtifactsInfo result = JsonSerializer . Deserialize ( responseBody , SourceGenerationContext . Default . ArtifactsInfo ) ;
60+ WorkflowRunsInfo result = JsonSerializer . Deserialize ( responseBody , SourceGenerationContext . Default . WorkflowRunsInfo ) ;
6261
6362 if ( result != null )
6463 {
65- Artifact artifact = result . Artifacts . FirstOrDefault ( x => x . WorkflowRun . HeadBranch == "main" ) ;
66-
67- if ( artifact != null )
64+ WorkflowRun run = result . WorkflowRuns . FirstOrDefault ( x => x is { HeadBranch : "main" , Event : "push" , Conclusion : "success" } ) ;
65+ if ( run != null )
6866 {
69- UpdateInfo updateInfo = new ( )
70- {
71- CreatedAt = artifact . CreatedAt ,
72- PublishedAt = artifact . UpdatedAt ,
73- Assets =
74- [
75- new Asset
76- {
77- Url = artifact . Url ,
78- Name = artifact . Name ,
79- Size = artifact . SizeInBytes ,
80- CreatedAt = artifact . CreatedAt ,
81- UpdatedAt = artifact . UpdatedAt ,
82- ExpiresAt = artifact . ExpiresAt ,
83- DownloadUrl = artifact . ArchiveDownloadUrl
84- }
85- ]
86- } ;
87-
8867 try
8968 {
90- url = string . Format ( GITHUB_RUNS_API , username , repository , artifact . WorkflowRun . ID ) ;
91- response = await client . GetAsync ( url ) . ConfigureAwait ( false ) ;
69+ response = await client . GetAsync ( run . ArtifactsUrl ) . ConfigureAwait ( false ) ;
9270 if ( response . StatusCode == HttpStatusCode . OK )
9371 {
9472 responseBody = await response . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
95- RunInfo run = JsonSerializer . Deserialize ( responseBody , SourceGenerationContext . Default . RunInfo ) ;
96-
97- SystemVersionInfo newVersionInfo = GetAsVersionInfo ( artifact . CreatedAt , ( int ) run . RunNumber ) ;
98- updateInfo . ReleaseUrl = run . HTMLUrl ;
99- updateInfo . IsExistNewVersion = newVersionInfo > currentVersion ;
100- updateInfo . Version = newVersionInfo ;
101- updateInfo . Assets [ 0 ] . DownloadUrl = $ "https://github.com/{ username } /{ repository } /suites/{ run . CheckSuiteID } /artifacts/{ artifact . ID } ";
73+ ArtifactsInfo artifacts = JsonSerializer . Deserialize ( responseBody , SourceGenerationContext . Default . ArtifactsInfo ) ;
74+ if ( artifacts != null )
75+ {
76+ SystemVersionInfo newVersionInfo = GetAsVersionInfo ( run . CreatedAt , run . RunNumber ) ;
77+ return new UpdateInfo ( )
78+ {
79+ ReleaseUrl = run . HTMLUrl ,
80+ CreatedAt = run . CreatedAt ,
81+ PublishedAt = run . UpdatedAt ,
82+ Assets =
83+ [
84+ .. artifacts . Artifacts . Select ( artifact => new Asset
85+ {
86+ Url = artifact . Url ,
87+ Name = artifact . Name ,
88+ Size = artifact . SizeInBytes ,
89+ CreatedAt = artifact . CreatedAt ,
90+ UpdatedAt = artifact . UpdatedAt ,
91+ ExpiresAt = artifact . ExpiresAt ,
92+ DownloadUrl = $ "https://github.com/{ username } /{ repository } /suites/{ run . CheckSuiteID } /artifacts/{ artifact . ID } "
93+ } )
94+ ] ,
95+ IsExistNewVersion = newVersionInfo > currentVersion ,
96+ Version = newVersionInfo
97+ } ;
98+ }
10299 }
103100 }
104101 catch ( Exception ex )
105102 {
106103 Microsoft . Extensions . Logging . LoggerExtensions . LogWarning ( SettingsHelper . LoggerFactory . CreateLogger ( nameof ( UpdateHelper ) ) , ex , "{message} (0x{hResult:X})" , ex . Message , ex . HResult ) ;
107104 }
108-
109- return updateInfo ;
110105 }
111106 }
112107
0 commit comments