Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f78b01f

Browse files
author
Harry Terkelsen
authored
Roll Firefox to CIPD with dev/browser_roller.dart (#37692)
1 parent dcdb96e commit f78b01f

File tree

5 files changed

+88
-5
lines changed

5 files changed

+88
-5
lines changed

lib/web_ui/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ is needed, follow these steps to roll the new version:
147147
If you have questions, contact the Flutter Web team on Flutter Discord on the
148148
\#hackers-web-🌍 channel.
149149

150+
#### Firefox
151+
152+
We test with Firefox on LUCI in the Linux Web Engine builder. The process for
153+
rolling Firefox is even easier than Chromium. Simply update `browser_lock.yaml`
154+
with the latest version of Firefox, and run `browser_roller.dart`.
155+
150156
##### **browser_roller.dart**
151157

152158
The script has the following command-line options:
@@ -164,7 +170,7 @@ The script has the following command-line options:
164170
165171
In general, the manual process goes like this:
166172
167-
1. Dowload the binaries for the new browser/driver for each operaing system
173+
1. Dowload the binaries for the new browser/driver for each operating system
168174
(macOS, linux, windows).
169175
2. Create CIPD packages for these packages (more documentation is available for
170176
Googlers at go/cipd-flutter-web)

lib/web_ui/dev/browser_lock.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ chrome:
1919
Win: 1047731
2020
version: '107.0' # CIPD tag for the above Build IDs. Normally "ChromeMajorVersion.UploadAttempt". ;)
2121

22-
## Firefox does not use CIPD. To update the version, simply update it in this
23-
## file.
2422
firefox:
2523
version: '83.0'
2624

lib/web_ui/dev/browser_roller.dart

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ class _BrowserRoller {
118118
for (final _Platform platform in _platforms) {
119119
await _rollChromium(platform);
120120
await _rollChromeDriver(platform);
121+
// For now, we only test Firefox on Linux.
122+
if (platform.os == 'linux') {
123+
await _rollFirefox(platform);
124+
}
121125
}
122126
if (dryRun) {
123127
print('\nDry Run Done!\nNon-published roll artifacts kept here: ${_rollDir.path}\n');
@@ -163,6 +167,22 @@ data:
163167
''';
164168
}
165169

170+
// Returns the contents for the CIPD config required to publish a new Firefox package.
171+
String _getCipdFirefoxConfig({
172+
required String package,
173+
required String majorVersion,
174+
required String root,
175+
}) {
176+
return '''
177+
package: $package
178+
description: Firefox $majorVersion used for testing
179+
preserve_writable: true
180+
root: $root
181+
data:
182+
- dir: .
183+
''';
184+
}
185+
166186
// Download a file from the internet, and put it in a temporary location.
167187
Future<io.File> _downloadTemporaryFile(String url) async {
168188
// Use the hash of the Url to temporarily store a file under tmp
@@ -193,6 +213,26 @@ data:
193213
await zipFile.delete();
194214
}
195215

216+
// Uncompresses a `file` into a `destination` Directory (must exist).
217+
Future<void> _uncompressAndDeleteFile(io.File tarFile, io.Directory destination) async {
218+
vprint(' Uncompressing [${tarFile.path}] into [$destination]');
219+
final io.ProcessResult unzipResult = await io.Process.run('tar', <String>[
220+
'-x',
221+
'-f',
222+
tarFile.path,
223+
'-C',
224+
destination.path,
225+
]);
226+
227+
if (unzipResult.exitCode != 0) {
228+
throw StateError(
229+
'Failed to unzip the downloaded archive ${tarFile.path}.\n'
230+
'The unzip process exited with code ${unzipResult.exitCode}.');
231+
}
232+
vprint(' Deleting [${tarFile.path}]');
233+
await tarFile.delete();
234+
}
235+
196236
// Write String `contents` to a file in `path`.
197237
//
198238
// This is used to write CIPD config files to disk.
@@ -366,4 +406,43 @@ data:
366406
// Run CIPD
367407
await _uploadToCipd(config: cipdConfigFile, version: majorVersion, buildId: chromeBuild);
368408
}
409+
410+
411+
// Downloads Firefox from the internet, packs it in the directory structure
412+
// that the LUCI script wants. The result of this will be then uploaded to CIPD.
413+
Future<void> _rollFirefox(_Platform platform) async {
414+
final String version = _lock.firefoxLock.version;
415+
final String url = platform.binding.getFirefoxDownloadUrl(version);
416+
final String cipdPackageName = 'flutter_internal/browsers/firefox/${platform.name}';
417+
final io.Directory platformDir = io.Directory(path.join(_rollDir.path, platform.name));
418+
print('\nRolling Firefox for ${platform.name} (version:$version)');
419+
// Bail out if CIPD already has version:$majorVersion for this package!
420+
if (!dryRun && await _cipdKnowsPackageVersion(package: cipdPackageName, versionTag: version)) {
421+
print(' Skipping $cipdPackageName version:$version. Already uploaded to CIPD!');
422+
vprint(' Update browser_lock.yaml and use a different version value.');
423+
return;
424+
}
425+
426+
await platformDir.create(recursive: true);
427+
vprint(' Created target directory [${platformDir.path}]');
428+
429+
final io.File firefoxDownload = await _downloadTemporaryFile(url);
430+
431+
await _uncompressAndDeleteFile(firefoxDownload, platformDir);
432+
433+
final io.Directory? actualContentRoot = await _locateContentRoot(platformDir);
434+
assert(actualContentRoot != null);
435+
final String relativePlatformDirPath = path.relative(actualContentRoot!.path, from: _rollDir.path);
436+
437+
// Create the config manifest to upload to CIPD
438+
final io.File cipdConfigFile = await _writeFile(
439+
path.join(_rollDir.path, 'cipd.firefox.${platform.name}.yaml'),
440+
_getCipdFirefoxConfig(
441+
package: cipdPackageName,
442+
majorVersion: version,
443+
root: relativePlatformDirPath,
444+
));
445+
// Run CIPD
446+
await _uploadToCipd(config: cipdConfigFile, version: version, buildId: version);
447+
}
369448
}

lib/web_ui/dev/chrome.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ChromeEnvironment implements BrowserEnvironment {
4040
final String version = browserLock.chromeLock.versionForCurrentPlatform;
4141
_installation = await getOrInstallChrome(
4242
version,
43-
infoLog: isCirrus ? stdout : DevNull(),
43+
infoLog: isCi ? stdout : DevNull(),
4444
);
4545
}
4646

lib/web_ui/dev/firefox.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FirefoxEnvironment implements BrowserEnvironment {
3232
Future<void> prepare() async {
3333
_installation = await getOrInstallFirefox(
3434
browserLock.firefoxLock.version,
35-
infoLog: isCirrus ? stdout : DevNull(),
35+
infoLog: isCi ? stdout : DevNull(),
3636
);
3737
}
3838

0 commit comments

Comments
 (0)