diff --git a/engine/src/flutter/testing/skia_gold_client/lib/skia_gold_client.dart b/engine/src/flutter/testing/skia_gold_client/lib/skia_gold_client.dart index 75827a9db8..84c27c06d5 100644 --- a/engine/src/flutter/testing/skia_gold_client/lib/skia_gold_client.dart +++ b/engine/src/flutter/testing/skia_gold_client/lib/skia_gold_client.dart @@ -88,6 +88,12 @@ interface class SkiaGoldClient { path.join(_engineRoot.flutterDir.path, '.engine-release.version'), ); + if (!_isMainBranch) { + _stderr.writeln( + 'Current git branch (${_environment['GIT_BRANCH']}) is not "main" or "master", so golden files are not checked.', + ); + } + // If the file is not found or cannot be read, we are in an invalid state. try { _releaseVersion = ReleaseVersion.parse(releaseVersionFile.readAsStringSync()); @@ -113,6 +119,14 @@ interface class SkiaGoldClient { return (environment ?? io.Platform.environment).containsKey(_kLuciEnvName); } + /// Whether the client is currently running on the main branch. + bool get _isMainBranch { + return switch (_environment['GIT_BRANCH']) { + 'main' || 'master' => true, + _ => false, + }; + } + /// Whether the current environment is a presubmit job. bool get _isPresubmit { return isLuciEnv(environment: _environment) && @@ -319,6 +333,13 @@ interface class SkiaGoldClient { int pixelColorDelta = 0, required int screenshotSize, }) async { + if (!_isMainBranch) { + if (verbose) { + _stderr.writeln('Skipping $testName (not on git main branch)'); + } + return; + } + assert(_isPresubmit || _isPostsubmit); // Clean the test name to remove the file extension. diff --git a/engine/src/flutter/testing/skia_gold_client/test/skia_gold_client_test.dart b/engine/src/flutter/testing/skia_gold_client/test/skia_gold_client_test.dart index 041b8eaf8c..ebc9298bee 100644 --- a/engine/src/flutter/testing/skia_gold_client/test/skia_gold_client_test.dart +++ b/engine/src/flutter/testing/skia_gold_client/test/skia_gold_client_test.dart @@ -20,6 +20,7 @@ void main() { /// Simulating what a presubmit environment would look like. const Map presubmitEnv = { + 'GIT_BRANCH': 'master', 'GOLDCTL': 'python tools/goldctl.py', 'GOLD_TRYJOB': 'flutter/engine/1234567890', 'LOGDOG_STREAM_PREFIX': 'buildbucket/cr-buildbucket.appspot.com/1234567890/+/logdog', @@ -28,6 +29,7 @@ void main() { /// Simulating what a postsubmit environment would look like. const Map postsubmitEnv = { + 'GIT_BRANCH': 'master', 'GOLDCTL': 'python tools/goldctl.py', 'LOGDOG_STREAM_PREFIX': 'buildbucket/cr-buildbucket.appspot.com/1234567890/+/logdog', 'LUCI_CONTEXT': '{}', @@ -87,6 +89,74 @@ void main() { } }); + test('prints a warning and skips when the git branch is not master or main', () async { + final _TestFixture fixture = _TestFixture(); + try { + final SkiaGoldClient client = createClient( + fixture, + environment: {...presubmitEnv, 'GIT_BRANCH': 'merge-queue-foo'}, + onRun: (List command) { + expect(command, [ + 'python tools/goldctl.py', + 'auth', + '--work-dir', + p.join(fixture.workDirectory.path, 'temp'), + '--luci', + ]); + createAuthOptDotJson(fixture.workDirectory.path); + return io.ProcessResult(0, 0, '', ''); + }, + ); + + // In case we change our mind, auth is still expected to work. + await client.auth(); + + expect( + fixture.outputSink.toString(), + stringContainsInOrder([ + 'Current git branch', + 'merge-queue-foo', + 'is not "main" or "master"', + ]), + ); + } finally { + fixture.dispose(); + } + }); + + test('always a success when the git branch is not master or main', () async { + final _TestFixture fixture = _TestFixture(); + try { + final SkiaGoldClient client = createClient( + fixture, + environment: {...presubmitEnv, 'GIT_BRANCH': 'merge-queue-foo'}, + onRun: (List command) { + expect(command, [ + 'python tools/goldctl.py', + 'auth', + '--work-dir', + p.join(fixture.workDirectory.path, 'temp'), + '--luci', + ]); + createAuthOptDotJson(fixture.workDirectory.path); + return io.ProcessResult(0, 0, '', ''); + }, + ); + + // In case we change our mind, auth is still expected to work. + await client.auth(); + + // Always completes OK. + await client.addImg( + 'test-name.foo', + io.File(p.join(fixture.workDirectory.path, 'temp', 'golden.png')), + screenshotSize: 1000, + ); + } finally { + fixture.dispose(); + } + }); + test('auth executes successfully', () async { final _TestFixture fixture = _TestFixture(); try {