teach dartdoc.dart about LUCI_BRANCH env var (#86592)
This commit is contained in:
parent
eb648523db
commit
2ba15a5aba
@ -7,7 +7,9 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:args/args.dart';
|
import 'package:args/args.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
import 'package:platform/platform.dart';
|
||||||
import 'package:process/process.dart';
|
import 'package:process/process.dart';
|
||||||
|
|
||||||
import 'dartdoc_checker.dart';
|
import 'dartdoc_checker.dart';
|
||||||
@ -252,8 +254,21 @@ ArgParser _createArgsParser() {
|
|||||||
|
|
||||||
final RegExp gitBranchRegexp = RegExp(r'^## (.*)');
|
final RegExp gitBranchRegexp = RegExp(r'^## (.*)');
|
||||||
|
|
||||||
String getBranchName() {
|
/// Get the name of the release branch.
|
||||||
final ProcessResult gitResult = Process.runSync('git', <String>['status', '-b', '--porcelain']);
|
///
|
||||||
|
/// On LUCI builds, the git HEAD is detached, so first check for the env
|
||||||
|
/// variable "LUCI_BRANCH"; if it is not set, fall back to calling git.
|
||||||
|
String getBranchName({
|
||||||
|
@visibleForTesting
|
||||||
|
Platform platform = const LocalPlatform(),
|
||||||
|
@visibleForTesting
|
||||||
|
ProcessManager processManager = const LocalProcessManager(),
|
||||||
|
}) {
|
||||||
|
final String? luciBranch = platform.environment['LUCI_BRANCH'];
|
||||||
|
if (luciBranch != null && luciBranch.trim().isNotEmpty) {
|
||||||
|
return luciBranch.trim();
|
||||||
|
}
|
||||||
|
final ProcessResult gitResult = processManager.runSync(<String>['git', 'status', '-b', '--porcelain']);
|
||||||
if (gitResult.exitCode != 0)
|
if (gitResult.exitCode != 0)
|
||||||
throw 'git status exit with non-zero exit code: ${gitResult.exitCode}';
|
throw 'git status exit with non-zero exit code: ${gitResult.exitCode}';
|
||||||
final RegExpMatch? gitBranchMatch = gitBranchRegexp.firstMatch(
|
final RegExpMatch? gitBranchMatch = gitBranchRegexp.firstMatch(
|
||||||
|
81
dev/tools/test/dartdoc_test.dart
Normal file
81
dev/tools/test/dartdoc_test.dart
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:platform/platform.dart';
|
||||||
|
import 'package:process/process.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
import '../../../packages/flutter_tools/test/src/fake_process_manager.dart';
|
||||||
|
import '../dartdoc.dart' show getBranchName;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
const String branchName = 'stable';
|
||||||
|
test('getBranchName does not call git if env LUCI_BRANCH provided', () {
|
||||||
|
final Platform platform = FakePlatform(
|
||||||
|
environment: <String, String>{
|
||||||
|
'LUCI_BRANCH': branchName,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
final ProcessManager processManager = FakeProcessManager.empty();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
getBranchName(
|
||||||
|
platform: platform,
|
||||||
|
processManager: processManager,
|
||||||
|
),
|
||||||
|
branchName,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getBranchName calls git if env LUCI_BRANCH not provided', () {
|
||||||
|
final Platform platform = FakePlatform(
|
||||||
|
environment: <String, String>{},
|
||||||
|
);
|
||||||
|
|
||||||
|
final ProcessManager processManager = FakeProcessManager.list(
|
||||||
|
<FakeCommand>[
|
||||||
|
const FakeCommand(
|
||||||
|
command: <String>['git', 'status', '-b', '--porcelain'],
|
||||||
|
stdout: '## $branchName',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
getBranchName(
|
||||||
|
platform: platform,
|
||||||
|
processManager: processManager,
|
||||||
|
),
|
||||||
|
branchName,
|
||||||
|
);
|
||||||
|
expect(processManager, hasNoRemainingExpectations);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getBranchName calls git if env LUCI_BRANCH is empty', () {
|
||||||
|
final Platform platform = FakePlatform(
|
||||||
|
environment: <String, String>{
|
||||||
|
'LUCI_BRANCH': '',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
final ProcessManager processManager = FakeProcessManager.list(
|
||||||
|
<FakeCommand>[
|
||||||
|
const FakeCommand(
|
||||||
|
command: <String>['git', 'status', '-b', '--porcelain'],
|
||||||
|
stdout: '## $branchName',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
getBranchName(
|
||||||
|
platform: platform,
|
||||||
|
processManager: processManager,
|
||||||
|
),
|
||||||
|
branchName,
|
||||||
|
);
|
||||||
|
expect(processManager, hasNoRemainingExpectations);
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user