@@ -18,6 +18,7 @@ namespace Microsoft.WebAssembly.Build.Tasks;
1818
1919public class GetChromeVersions : MBU . Task
2020{
21+ private const string s_fetchReleasesUrl = "https://chromiumdash.appspot.com/fetch_releases?channel={0}&num=1" ;
2122 private const string s_allJsonUrl = "http://omahaproxy.appspot.com/all.json" ;
2223 private const string s_snapshotBaseUrl = $ "https://storage.googleapis.com/chromium-browser-snapshots";
2324 private const string s_historyUrl = $ "https://omahaproxy.appspot.com/history";
@@ -66,9 +67,10 @@ private async Task<bool> ExecuteInternalAsync()
6667
6768 try
6869 {
69- ( ChromeVersionSpec version , string baseUrl ) = await FindVersionFromHistoryAsync ( ) . ConfigureAwait ( false ) ;
70+ // (ChromeVersionSpec version, string baseUrl) = await FindVersionFromHistoryAsync().ConfigureAwait(false);
7071 // For using all.json, use this instead:
7172 // (ChromeVersionSpec version, string baseUrl) = await FindVersionFromAllJsonAsync().ConfigureAwait(false);
73+ ( ChromeVersionSpec version , string baseUrl ) = await FindVersionFromChromiumDash ( ) . ConfigureAwait ( false ) ;
7274
7375 BaseSnapshotUrl = baseUrl ;
7476 ChromeVersion = version . version ;
@@ -167,6 +169,34 @@ async IAsyncEnumerable<string> GetVersionsAsync()
167169 }
168170 }
169171
172+ private async Task < ( ChromeVersionSpec version , string baseSnapshotUrl ) > FindVersionFromChromiumDash ( )
173+ {
174+ using Stream stream = await GetDownloadFileStreamAsync ( "fetch_releases.json" , string . Format ( s_fetchReleasesUrl , Channel ) ) . ConfigureAwait ( false ) ;
175+
176+ ChromiumDashRelease [ ] ? releases = await JsonSerializer
177+ . DeserializeAsync < ChromiumDashRelease [ ] > ( stream )
178+ . ConfigureAwait ( false ) ;
179+ if ( releases is null )
180+ throw new LogAsErrorException ( $ "Failed to read chrome versions from { s_fetchReleasesUrl } ") ;
181+
182+ ChromiumDashRelease ? foundRelease = releases . Where ( rel => string . Equals ( rel . platform , OSIdentifier , StringComparison . InvariantCultureIgnoreCase ) ) . SingleOrDefault ( ) ;
183+ if ( foundRelease is null )
184+ {
185+ string availablePlatformIds = string . Join ( ", " , releases . Select ( rel => rel . platform ) . Distinct ( ) . Order ( ) ) ;
186+ throw new LogAsErrorException ( $ "Unknown Platform '{ OSIdentifier } '. Platforms found " +
187+ $ "in fetch_releases.json: { availablePlatformIds } ") ;
188+ }
189+
190+ ChromeVersionSpec versionSpec = new ( foundRelease . platform ,
191+ Channel ,
192+ foundRelease . version ,
193+ foundRelease . chromium_main_branch_position . ToString ( ) ,
194+ foundRelease . version ) ;
195+ string ? baseSnapshotUrl = await FindSnapshotUrlFromBasePositionAsync ( versionSpec , throwIfNotFound : true )
196+ . ConfigureAwait ( false ) ;
197+ return ( versionSpec , baseSnapshotUrl ! ) ;
198+ }
199+
170200 private async Task < ( ChromeVersionSpec versionSpec , string baseSnapshotUrl ) > FindVersionFromAllJsonAsync ( )
171201 {
172202 using Stream stream = await GetDownloadFileStreamAsync ( "all.json" , s_allJsonUrl ) . ConfigureAwait ( false ) ;
@@ -271,6 +301,8 @@ private async Task<Stream> GetDownloadFileStreamAsync(string filename, string ur
271301 return null ;
272302 }
273303
304+ private sealed record ChromiumDashRelease ( string channel , int chromium_main_branch_position , string milesone , string platform , string version ) ;
305+
274306 private sealed record PerOSVersions ( string os , ChromeVersionSpec [ ] versions ) ;
275307 private sealed record ChromeVersionSpec ( string os , string channel , string version , string branch_base_position , string v8_version ) ;
276308 private sealed record ChromeDepsVersionSpec ( string chromium_version , string chromium_base_position , string v8_version )
0 commit comments