Unverified Commit 4575a69d authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_conductor] fix initialref to explicitly include remote name (#96481)

parent 40a2689b
...@@ -101,22 +101,6 @@ class NextContext extends Context { ...@@ -101,22 +101,6 @@ class NextContext extends Context {
upstreamRemote: upstream, upstreamRemote: upstream,
previousCheckoutLocation: state.engine.checkoutPath, previousCheckoutLocation: state.engine.checkoutPath,
); );
// check if the candidate branch is enabled in .ci.yaml
final CiYaml engineCiYaml = await engine.ciYaml;
if (!engineCiYaml.enabledBranches.contains(state.engine.candidateBranch)) {
engineCiYaml.enableBranch(state.engine.candidateBranch);
// commit
final String revision = await engine.commit(
'add branch ${state.engine.candidateBranch} to enabled_branches in .ci.yaml',
addFirst: true,
);
// append to list of cherrypicks so we know a PR is required
state.engine.cherrypicks.add(pb.Cherrypick(
appliedRevision: revision,
state: pb.CherrypickState.COMPLETED,
));
}
if (!state_import.requiresEnginePR(state)) { if (!state_import.requiresEnginePR(state)) {
stdio.printStatus( stdio.printStatus(
'This release has no engine cherrypicks. No Engine PR is necessary.\n', 'This release has no engine cherrypicks. No Engine PR is necessary.\n',
...@@ -213,21 +197,6 @@ class NextContext extends Context { ...@@ -213,21 +197,6 @@ class NextContext extends Context {
previousCheckoutLocation: state.framework.checkoutPath, previousCheckoutLocation: state.framework.checkoutPath,
); );
// Check if the current candidate branch is enabled
if (!(await framework.ciYaml).enabledBranches.contains(state.framework.candidateBranch)) {
(await framework.ciYaml).enableBranch(state.framework.candidateBranch);
// commit
final String revision = await framework.commit(
'add branch ${state.framework.candidateBranch} to enabled_branches in .ci.yaml',
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...'); stdio.printStatus('Rolling new engine hash $engineRevision to framework checkout...');
final bool needsCommit = await framework.updateEngineRevision(engineRevision); final bool needsCommit = await framework.updateEngineRevision(engineRevision);
if (needsCommit) { if (needsCommit) {
......
...@@ -844,46 +844,4 @@ class CiYaml { ...@@ -844,46 +844,4 @@ class CiYaml {
/// This is not cached as the contents can be written to while the conductor /// This is not cached as the contents can be written to while the conductor
/// is running. /// is running.
YamlMap get contents => loadYaml(stringContents) as YamlMap; YamlMap get contents => loadYaml(stringContents) as YamlMap;
List<String> get enabledBranches {
final YamlList yamlList = contents['enabled_branches'] as YamlList;
return yamlList.map<String>((dynamic element) {
return element as String;
}).toList();
}
static final RegExp _enabledBranchPattern = RegExp(r'enabled_branches:');
/// Update this .ci.yaml file with the given branch name.
///
/// The underlying [File] is written to, but not committed to git. This method
/// will throw a [ConductorException] if the [branchName] is already present
/// in the file or if the file does not have an "enabled_branches:" field.
void enableBranch(String branchName) {
final List<String> newStrings = <String>[];
if (enabledBranches.contains(branchName)) {
throw ConductorException('${file.path} already contains the branch $branchName');
}
if (!_enabledBranchPattern.hasMatch(stringContents)) {
throw ConductorException(
'Did not find the expected string "enabled_branches:" in the file ${file.path}',
);
}
final List<String> lines = stringContents.split('\n');
bool insertedCurrentBranch = false;
for (final String line in lines) {
// Every existing line should be copied to the new Yaml
newStrings.add(line);
if (insertedCurrentBranch) {
continue;
}
if (_enabledBranchPattern.hasMatch(line)) {
insertedCurrentBranch = true;
// Indent two spaces
final String indent = ' ' * 2;
newStrings.add('$indent- ${branchName.trim()}');
}
}
file.writeAsStringSync(newStrings.join('\n'), flush: true);
}
} }
...@@ -235,7 +235,7 @@ class StartContext extends Context { ...@@ -235,7 +235,7 @@ class StartContext extends Context {
}) : git = Git(processManager), }) : git = Git(processManager),
engine = EngineRepository( engine = EngineRepository(
checkouts, checkouts,
initialRef: candidateBranch, initialRef: 'upstream/$candidateBranch',
upstreamRemote: Remote( upstreamRemote: Remote(
name: RemoteName.upstream, name: RemoteName.upstream,
url: engineUpstream, url: engineUpstream,
...@@ -246,7 +246,7 @@ class StartContext extends Context { ...@@ -246,7 +246,7 @@ class StartContext extends Context {
), ),
), framework = FrameworkRepository( ), framework = FrameworkRepository(
checkouts, checkouts,
initialRef: candidateBranch, initialRef: 'upstream/$candidateBranch',
upstreamRemote: Remote( upstreamRemote: Remote(
name: RemoteName.upstream, name: RemoteName.upstream,
url: frameworkUpstream, url: frameworkUpstream,
......
...@@ -25,7 +25,6 @@ void main() { ...@@ -25,7 +25,6 @@ void main() {
const String remoteUrl = 'https://github.com/org/repo.git'; const String remoteUrl = 'https://github.com/org/repo.git';
const String revision1 = 'd3af60d18e01fcb36e0c0fa06c8502e4935ed095'; const String revision1 = 'd3af60d18e01fcb36e0c0fa06c8502e4935ed095';
const String revision2 = 'f99555c1e1392bf2a8135056b9446680c2af4ddf'; const String revision2 = 'f99555c1e1392bf2a8135056b9446680c2af4ddf';
const String revision3 = '98a5ca242b9d270ce000b26309b8a3cdc9c89df5';
const String revision4 = '280e23318a0d8341415c66aa32581352a421d974'; const String revision4 = '280e23318a0d8341415c66aa32581352a421d974';
const String releaseVersion = '1.2.0-3.0.pre'; const String releaseVersion = '1.2.0-3.0.pre';
const String releaseChannel = 'beta'; const String releaseChannel = 'beta';
...@@ -82,12 +81,7 @@ void main() { ...@@ -82,12 +81,7 @@ void main() {
group('APPLY_ENGINE_CHERRYPICKS to CODESIGN_ENGINE_BINARIES', () { group('APPLY_ENGINE_CHERRYPICKS to CODESIGN_ENGINE_BINARIES', () {
test('does not prompt user and updates currentPhase if there are no engine cherrypicks', () async { test('does not prompt user and updates currentPhase if there are no engine cherrypicks', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[ final FakeProcessManager processManager = FakeProcessManager.empty();
const FakeCommand(command: <String>['git', 'fetch', 'upstream']),
const FakeCommand(
command: <String>['git', 'checkout', workingBranch],
),
]);
final FakePlatform platform = FakePlatform( final FakePlatform platform = FakePlatform(
environment: <String, String>{ environment: <String, String>{
'HOME': <String>['path', 'to', 'home'].join(localPathSeparator), 'HOME': <String>['path', 'to', 'home'].join(localPathSeparator),
...@@ -145,24 +139,7 @@ void main() { ...@@ -145,24 +139,7 @@ void main() {
final File ciYaml = fileSystem.file('$checkoutsParentDirectory/engine/.ci.yaml') final File ciYaml = fileSystem.file('$checkoutsParentDirectory/engine/.ci.yaml')
..createSync(recursive: true); ..createSync(recursive: true);
_initializeCiYamlFile(ciYaml); _initializeCiYamlFile(ciYaml);
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[ final FakeProcessManager processManager = FakeProcessManager.empty();
const FakeCommand(command: <String>['git', 'fetch', 'upstream']),
const FakeCommand(command: <String>['git', 'checkout', workingBranch]),
const FakeCommand(
command: <String>['git', 'status', '--porcelain'],
stdout: 'MM blah',
),
const FakeCommand(command: <String>['git', 'add', '--all']),
const FakeCommand(command: <String>[
'git',
'commit',
"--message='add branch $candidateBranch to enabled_branches in .ci.yaml'",
]),
const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'],
stdout: revision2,
),
]);
final FakePlatform platform = FakePlatform( final FakePlatform platform = FakePlatform(
environment: <String, String>{ environment: <String, String>{
'HOME': <String>['path', 'to', 'home'].join(localPathSeparator), 'HOME': <String>['path', 'to', 'home'].join(localPathSeparator),
...@@ -228,16 +205,6 @@ void main() { ...@@ -228,16 +205,6 @@ void main() {
_initializeCiYamlFile(file); _initializeCiYamlFile(file);
}, },
), ),
const FakeCommand(
command: <String>['git', 'status', '--porcelain'],
stdout: 'MM .ci.yaml',
),
const FakeCommand(command: <String>['git', 'add', '--all']),
const FakeCommand(command: <String>['git', 'commit', "--message='add branch $candidateBranch to enabled_branches in .ci.yaml'"]),
const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'],
stdout: revision2,
),
const FakeCommand(command: <String>['git', 'push', 'mirror', 'HEAD:refs/heads/$workingBranch']), const FakeCommand(command: <String>['git', 'push', 'mirror', 'HEAD:refs/heads/$workingBranch']),
]); ]);
final FakePlatform platform = FakePlatform( final FakePlatform platform = FakePlatform(
...@@ -355,6 +322,7 @@ void main() { ...@@ -355,6 +322,7 @@ void main() {
fileSystem.file(stateFile), fileSystem.file(stateFile),
); );
expect(processManager, hasNoRemainingExpectations);
expect(stdio.stdout, contains('Has CI passed for the engine PR and binaries been codesigned? (y/n) ')); expect(stdio.stdout, contains('Has CI passed for the engine PR and binaries been codesigned? (y/n) '));
expect(finalState.currentPhase, ReleasePhase.CODESIGN_ENGINE_BINARIES); expect(finalState.currentPhase, ReleasePhase.CODESIGN_ENGINE_BINARIES);
expect(stdio.error.contains('Aborting command.'), true); expect(stdio.error.contains('Aborting command.'), true);
...@@ -392,6 +360,7 @@ void main() { ...@@ -392,6 +360,7 @@ void main() {
fileSystem.file(stateFile), fileSystem.file(stateFile),
); );
expect(processManager, hasNoRemainingExpectations);
expect(stdio.stdout, contains('Has CI passed for the engine PR and binaries been codesigned? (y/n) ')); expect(stdio.stdout, contains('Has CI passed for the engine PR and binaries been codesigned? (y/n) '));
expect(finalState.currentPhase, ReleasePhase.APPLY_FRAMEWORK_CHERRYPICKS); expect(finalState.currentPhase, ReleasePhase.APPLY_FRAMEWORK_CHERRYPICKS);
}); });
...@@ -524,20 +493,6 @@ void main() { ...@@ -524,20 +493,6 @@ void main() {
_initializeCiYamlFile(file); _initializeCiYamlFile(file);
}, },
), ),
const FakeCommand(
command: <String>['git', 'status', '--porcelain'],
stdout: 'MM /path/to/.ci.yaml',
),
const FakeCommand(command: <String>['git', 'add', '--all']),
const FakeCommand(command: <String>[
'git',
'commit',
"--message='add branch $candidateBranch to enabled_branches in .ci.yaml'",
]),
const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'],
stdout: revision3,
),
const FakeCommand( const FakeCommand(
command: <String>['git', 'status', '--porcelain'], command: <String>['git', 'status', '--porcelain'],
stdout: 'MM /path/to/engine.version', stdout: 'MM /path/to/engine.version',
...@@ -614,20 +569,6 @@ void main() { ...@@ -614,20 +569,6 @@ void main() {
), ),
const FakeCommand(command: <String>['git', 'fetch', 'upstream']), const FakeCommand(command: <String>['git', 'fetch', 'upstream']),
const FakeCommand(command: <String>['git', 'checkout', workingBranch]), const FakeCommand(command: <String>['git', 'checkout', workingBranch]),
const FakeCommand(
command: <String>['git', 'status', '--porcelain'],
stdout: 'MM path/to/.ci.yaml',
),
const FakeCommand(command: <String>['git', 'add', '--all']),
const FakeCommand(command: <String>[
'git',
'commit',
"--message='add branch $candidateBranch to enabled_branches in .ci.yaml'",
]),
const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'],
stdout: revision3,
),
const FakeCommand( const FakeCommand(
command: <String>['git', 'status', '--porcelain'], command: <String>['git', 'status', '--porcelain'],
stdout: 'MM path/to/engine.version', stdout: 'MM path/to/engine.version',
...@@ -697,20 +638,6 @@ void main() { ...@@ -697,20 +638,6 @@ void main() {
stdout: 'MM path/to/.ci.yaml', stdout: 'MM path/to/.ci.yaml',
), ),
const FakeCommand(command: <String>['git', 'add', '--all']), const FakeCommand(command: <String>['git', 'add', '--all']),
const FakeCommand(command: <String>[
'git',
'commit',
"--message='add branch $candidateBranch to enabled_branches in .ci.yaml'",
]),
const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'],
stdout: revision3,
),
const FakeCommand(
command: <String>['git', 'status', '--porcelain'],
stdout: 'MM path/to/engine.version',
),
const FakeCommand(command: <String>['git', 'add', '--all']),
const FakeCommand(command: <String>[ const FakeCommand(command: <String>[
'git', 'git',
'commit', 'commit',
......
...@@ -384,130 +384,6 @@ vars = { ...@@ -384,130 +384,6 @@ vars = {
); );
}); });
test('ciYaml.enableBranch() will prepend the given branch to the yaml list of enabled_branches', () async {
const String commit1 = 'abc123';
final File ciYaml = fileSystem.file('/flutter_conductor_checkouts/framework/.ci.yaml');
processManager.addCommands(<FakeCommand>[
FakeCommand(
command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
FrameworkRepository.defaultUpstream,
fileSystem.path
.join(rootDir, 'flutter_conductor_checkouts', 'framework'),
],
onRun: () {
ciYaml.createSync(recursive: true);
ciYaml.writeAsStringSync('''
# Friendly note
enabled_branches:
- ${FrameworkRepository.defaultBranch}
- dev
- beta
- stable
''');
}),
const FakeCommand(command: <String>[
'git',
'checkout',
FrameworkRepository.defaultBranch,
]),
const FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: commit1),
]);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
parentDirectory: fileSystem.directory(rootDir),
platform: platform,
processManager: processManager,
stdio: stdio,
);
final FrameworkRepository framework = FrameworkRepository(checkouts);
expect(
(await framework.ciYaml).enabledBranches,
<String>[FrameworkRepository.defaultBranch, 'dev', 'beta', 'stable'],
);
(await framework.ciYaml).enableBranch('foo');
expect(
(await framework.ciYaml).enabledBranches,
<String>['foo', FrameworkRepository.defaultBranch, 'dev', 'beta', 'stable'],
);
expect(
(await framework.ciYaml).stringContents,
'''
# Friendly note
enabled_branches:
- foo
- ${FrameworkRepository.defaultBranch}
- dev
- beta
- stable
'''
);
});
test('ciYaml.enableBranch() will throw if the input branch is already present in the yaml file', () {
const String commit1 = 'abc123';
final File ciYaml = fileSystem.file('/flutter_conductor_checkouts/framework/.ci.yaml');
processManager.addCommands(<FakeCommand>[
FakeCommand(
command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
FrameworkRepository.defaultUpstream,
fileSystem.path
.join(rootDir, 'flutter_conductor_checkouts', 'framework'),
],
onRun: () {
ciYaml.createSync(recursive: true);
ciYaml.writeAsStringSync('''
enabled_branches:
- ${FrameworkRepository.defaultBranch}
- dev
- beta
- stable
''');
}),
const FakeCommand(command: <String>[
'git',
'checkout',
FrameworkRepository.defaultBranch,
]),
const FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: commit1),
]);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
parentDirectory: fileSystem.directory(rootDir),
platform: platform,
processManager: processManager,
stdio: stdio,
);
final FrameworkRepository framework = FrameworkRepository(checkouts);
expect(
() async => (await framework.ciYaml).enableBranch(FrameworkRepository.defaultBranch),
throwsExceptionWith('.ci.yaml already contains the branch ${FrameworkRepository.defaultBranch}'),
);
});
test('framework repo set as localUpstream ensures requiredLocalBranches exist locally', () async { test('framework repo set as localUpstream ensures requiredLocalBranches exist locally', () async {
const String commit = 'deadbeef'; const String commit = 'deadbeef';
const String candidateBranch = 'flutter-1.2-candidate.3'; const String candidateBranch = 'flutter-1.2-candidate.3';
......
...@@ -163,7 +163,7 @@ void main() { ...@@ -163,7 +163,7 @@ void main() {
command: <String>['git', 'fetch', 'mirror'], command: <String>['git', 'fetch', 'mirror'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'checkout', candidateBranch], command: <String>['git', 'checkout', 'upstream/$candidateBranch'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'], command: <String>['git', 'rev-parse', 'HEAD'],
...@@ -220,7 +220,7 @@ void main() { ...@@ -220,7 +220,7 @@ void main() {
command: <String>['git', 'fetch', 'mirror'], command: <String>['git', 'fetch', 'mirror'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'checkout', candidateBranch], command: <String>['git', 'checkout', 'upstream/$candidateBranch'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'], command: <String>['git', 'rev-parse', 'HEAD'],
...@@ -349,7 +349,7 @@ void main() { ...@@ -349,7 +349,7 @@ void main() {
command: <String>['git', 'fetch', 'mirror'], command: <String>['git', 'fetch', 'mirror'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'checkout', candidateBranch], command: <String>['git', 'checkout', 'upstream/$candidateBranch'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'], command: <String>['git', 'rev-parse', 'HEAD'],
...@@ -406,7 +406,7 @@ void main() { ...@@ -406,7 +406,7 @@ void main() {
command: <String>['git', 'fetch', 'mirror'], command: <String>['git', 'fetch', 'mirror'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'checkout', candidateBranch], command: <String>['git', 'checkout', 'upstream/$candidateBranch'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'], command: <String>['git', 'rev-parse', 'HEAD'],
...@@ -542,7 +542,7 @@ void main() { ...@@ -542,7 +542,7 @@ void main() {
command: <String>['git', 'fetch', 'mirror'], command: <String>['git', 'fetch', 'mirror'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'checkout', candidateBranch], command: <String>['git', 'checkout', 'upstream/$candidateBranch'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'], command: <String>['git', 'rev-parse', 'HEAD'],
...@@ -599,7 +599,7 @@ void main() { ...@@ -599,7 +599,7 @@ void main() {
command: <String>['git', 'fetch', 'mirror'], command: <String>['git', 'fetch', 'mirror'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'checkout', candidateBranch], command: <String>['git', 'checkout', 'upstream/$candidateBranch'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'], command: <String>['git', 'rev-parse', 'HEAD'],
...@@ -729,7 +729,7 @@ void main() { ...@@ -729,7 +729,7 @@ void main() {
command: <String>['git', 'fetch', 'mirror'], command: <String>['git', 'fetch', 'mirror'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'checkout', candidateBranch], command: <String>['git', 'checkout', 'upstream/$candidateBranch'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'], command: <String>['git', 'rev-parse', 'HEAD'],
...@@ -782,7 +782,7 @@ void main() { ...@@ -782,7 +782,7 @@ void main() {
command: <String>['git', 'fetch', 'mirror'], command: <String>['git', 'fetch', 'mirror'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'checkout', candidateBranch], command: <String>['git', 'checkout', 'upstream/$candidateBranch'],
), ),
const FakeCommand( const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'], command: <String>['git', 'rev-parse', 'HEAD'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment