From a3d802699300d3503809347e2f8526dc47f8f0f2 Mon Sep 17 00:00:00 2001 From: Casey Hillers Date: Fri, 25 Mar 2022 12:28:57 -0700 Subject: [PATCH] [flutter_conductor] Add candidate branch version to releases (#100781) --- dev/conductor/core/lib/src/next.dart | 16 ++++++- dev/conductor/core/lib/src/repository.dart | 33 +++++++++++++ dev/conductor/core/test/next_test.dart | 49 ++++++++++++++++++-- dev/conductor/core/test/repository_test.dart | 17 +++++++ 4 files changed, 110 insertions(+), 5 deletions(-) diff --git a/dev/conductor/core/lib/src/next.dart b/dev/conductor/core/lib/src/next.dart index 258706c1d3..d3b0a5db93 100644 --- a/dev/conductor/core/lib/src/next.dart +++ b/dev/conductor/core/lib/src/next.dart @@ -196,9 +196,21 @@ class NextContext extends Context { upstreamRemote: upstream, previousCheckoutLocation: state.framework.checkoutPath, ); - + stdio.printStatus('Writing candidate branch...'); + bool needsCommit = await framework.updateCandidateBranchVersion(state.releaseVersion); + if (needsCommit) { + final String revision = await framework.commit( + 'Create candidate branch version ${state.engine.candidateBranch} for ${state.releaseChannel}', + addFirst: true, + ); + // append to list of cherrypicks so we know a PR is required + state.framework.cherrypicks.add(pb.Cherrypick( + appliedRevision: revision, + state: pb.CherrypickState.COMPLETED, + )); + } stdio.printStatus('Rolling new engine hash $engineRevision to framework checkout...'); - final bool needsCommit = await framework.updateEngineRevision(engineRevision); + needsCommit = await framework.updateEngineRevision(engineRevision); if (needsCommit) { final String revision = await framework.commit( 'Update Engine revision to $engineRevision for ${state.releaseChannel} release ${state.releaseVersion}', diff --git a/dev/conductor/core/lib/src/repository.dart b/dev/conductor/core/lib/src/repository.dart index f33dc472ad..7a86c528e3 100644 --- a/dev/conductor/core/lib/src/repository.dart +++ b/dev/conductor/core/lib/src/repository.dart @@ -620,6 +620,39 @@ class FrameworkRepository extends Repository { return Version.fromString(versionJson['frameworkVersion'] as String); } + /// Create a release candidate branch version file. + /// + /// This file allows for easily traversing what candidadate branch was used + /// from a release channel. + /// + /// Returns [true] if the version file was updated and a commit is needed. + Future updateCandidateBranchVersion( + String branch, { + @visibleForTesting File? versionFile, + }) async { + assert(branch.isNotEmpty); + versionFile ??= (await checkoutDirectory) + .childDirectory('bin') + .childDirectory('internal') + .childFile('release-candidate-branch.version'); + if (versionFile.existsSync()) { + final String oldCandidateBranch = versionFile.readAsStringSync(); + if (oldCandidateBranch.trim() == branch.trim()) { + stdio.printTrace( + 'Tried to update the candidate branch but version file is already up to date at: $branch', + ); + return false; + } + } + stdio.printStatus('Create ${versionFile.path} containing $branch'); + versionFile.writeAsStringSync( + // Version files have trailing newlines + '${branch.trim()}\n', + flush: true, + ); + return true; + } + /// Update this framework's engine version file. /// /// Returns [true] if the version file was updated and a commit is needed. diff --git a/dev/conductor/core/test/next_test.dart b/dev/conductor/core/test/next_test.dart index 4e93b80543..26c8eb38f4 100644 --- a/dev/conductor/core/test/next_test.dart +++ b/dev/conductor/core/test/next_test.dart @@ -25,6 +25,7 @@ void main() { const String remoteUrl = 'https://github.com/org/repo.git'; const String revision1 = 'd3af60d18e01fcb36e0c0fa06c8502e4935ed095'; const String revision2 = 'f99555c1e1392bf2a8135056b9446680c2af4ddf'; + const String revision3 = 'ffffffffffffffffffffffffffffffffffffffff'; const String revision4 = '280e23318a0d8341415c66aa32581352a421d974'; const String releaseVersion = '1.2.0-3.0.pre'; const String releaseChannel = 'beta'; @@ -495,7 +496,21 @@ void main() { ), const FakeCommand( command: ['git', 'status', '--porcelain'], - stdout: 'MM /path/to/engine.version', + stdout: 'MM bin/internal/release-candidate-branch.version', + ), + const FakeCommand(command: ['git', 'add', '--all']), + const FakeCommand(command: [ + 'git', + 'commit', + "--message='Create candidate branch version $candidateBranch for $releaseChannel'", + ]), + const FakeCommand( + command: ['git', 'rev-parse', 'HEAD'], + stdout: revision3, + ), + const FakeCommand( + command: ['git', 'status', '--porcelain'], + stdout: 'MM bin/internal/engine.version', ), const FakeCommand(command: ['git', 'add', '--all']), const FakeCommand(command: [ @@ -571,7 +586,21 @@ void main() { const FakeCommand(command: ['git', 'checkout', workingBranch]), const FakeCommand( command: ['git', 'status', '--porcelain'], - stdout: 'MM path/to/engine.version', + stdout: 'MM bin/internal/release-candidate-branch.version', + ), + const FakeCommand(command: ['git', 'add', '--all']), + const FakeCommand(command: [ + 'git', + 'commit', + "--message='Create candidate branch version $candidateBranch for $releaseChannel'", + ]), + const FakeCommand( + command: ['git', 'rev-parse', 'HEAD'], + stdout: revision3, + ), + const FakeCommand( + command: ['git', 'status', '--porcelain'], + stdout: 'MM bin/internal/engine.version', ), const FakeCommand(command: ['git', 'add', '--all']), const FakeCommand(command: [ @@ -635,7 +664,21 @@ void main() { ), const FakeCommand( command: ['git', 'status', '--porcelain'], - stdout: 'MM path/to/.ci.yaml', + stdout: 'MM bin/internal/release-candidate-branch.version', + ), + const FakeCommand(command: ['git', 'add', '--all']), + const FakeCommand(command: [ + 'git', + 'commit', + "--message='Create candidate branch version $candidateBranch for $releaseChannel'", + ]), + const FakeCommand( + command: ['git', 'rev-parse', 'HEAD'], + stdout: revision3, + ), + const FakeCommand( + command: ['git', 'status', '--porcelain'], + stdout: 'MM bin/internal/engine.version', ), const FakeCommand(command: ['git', 'add', '--all']), const FakeCommand(command: [ diff --git a/dev/conductor/core/test/repository_test.dart b/dev/conductor/core/test/repository_test.dart index bd428ebe05..c6b95a2d99 100644 --- a/dev/conductor/core/test/repository_test.dart +++ b/dev/conductor/core/test/repository_test.dart @@ -340,6 +340,23 @@ vars = { expect(processManager.hasRemainingExpectations, false); }); + test('updateCandidateBranchVersion() returns false if branch is the same as version file', () async { + const String branch = 'flutter-2.15-candidate.3'; + final File versionFile = fileSystem.file('/release-candidate-branch.version')..writeAsStringSync(branch); + + final Checkouts checkouts = Checkouts( + fileSystem: fileSystem, + parentDirectory: fileSystem.directory(rootDir), + platform: platform, + processManager: processManager, + stdio: stdio, + ); + + final FrameworkRepository repo = FrameworkRepository(checkouts); + final bool didUpdate = await repo.updateCandidateBranchVersion(branch, versionFile: versionFile); + expect(didUpdate, false); + }); + test('updateEngineRevision() returns false if newCommit is the same as version file', () async { const String commit1 = 'abc123'; const String commit2 = 'def456';