Skip to content

Commit

Permalink
Add support for run_if_not. (#3004)
Browse files Browse the repository at this point in the history
This is required to filter fuchsia changes in presubmit.

Bug: flutter/flutter#93261
  • Loading branch information
godofredoc authored Aug 24, 2023
1 parent acb974d commit 58676a6
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 119 deletions.
6 changes: 5 additions & 1 deletion CI_YAML.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ targets:
# presubmit: Whether to run this target on presubmit (defaults to true).
# postsubmit: Whether to run this target on postsubmit (defaults to true).
# run_if: List of path regexes that can trigger this target on presubmit.
# If none are passed, will always run in presubmit.
# If none are passed, it will evaluare run_if_not. If both are empty the target
# will always run in presubmit.
# run_if_not: List of path regexes used to filter out presubmit targets. The target will
# be run only if the files changed do not match any paths in this list. If run_if
# is provided and not empty run_if_not will be ignored.
# enabled_branches: List of strings of branches this target can run on.
# This overrides the global enabled_branches.
# properties: A map of string, string. Values are parsed to their closest data model.
Expand Down
54 changes: 43 additions & 11 deletions app_dart/lib/src/foundation/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,36 @@ FutureOr<String> getUrl(
}
}

/// Expands globs string to a regex for evaluation.
Future<RegExp> parseGlob(String glob) async {
glob = glob.replaceAll('**', '[A-Za-z0-9_/.]+');
glob = glob.replaceAll('*', '[A-Za-z0-9_.]+');
return RegExp('^$glob\$');
}

/// Returns a LUCI [builder] list that covers changed [files].
///
/// [builders]: enabled luci builders.
/// [files]: changed files in corresponding PRs.
///
/// [builder] is with format:
/// [builder] format with run_if:
/// {
/// "name":"yyy",
/// "repo":"flutter",
/// "taskName":"zzz",
/// "enabled":true,
/// "run_if":["a/b/", "c/d_e/**", "f", "g*h/"]
/// }
/// [builder] format with run_if_not:
/// {
/// "name":"yyy",
/// "repo":"flutter",
/// "taskName":"zzz",
/// "enabled":true,
/// "run_if_not":["a/b/", "c/d_e/**", "f", "g*h/"]
/// }
/// Note: if both [run_if] and [run_if_not] are provided and not empty only
/// [run_if] is evaluated.
///
/// [file] is based on repo root: `a/b/c.dart`.
Future<List<Target>> getTargetsToRun(Iterable<Target> targets, List<String?> files) async {
Expand All @@ -124,17 +141,32 @@ Future<List<Target>> getTargetsToRun(Iterable<Target> targets, List<String?> fil
final List<String> globs = target.value.runIf;
// Handle case where [Target] initializes empty runif
if (globs.isEmpty) {
targetsToRun.add(target);
}

for (String glob in globs) {
glob = glob.replaceAll('**', '[A-Za-z0-9_/.]+');
glob = glob.replaceAll('*', '[A-Za-z0-9_.]+');
// If a file is found within a pre-set dir, the builder needs to run. No need to check further.
final RegExp regExp = RegExp('^$glob\$');
if (glob.isEmpty || files.any((String? file) => regExp.hasMatch(file!))) {
// Evaluate run_if_not.
final List<String> negativeGlobs = target.value.runIfNot;
if (negativeGlobs.isEmpty) {
targetsToRun.add(target);
break;
continue;
}
bool shouldAdd = true;
for (String glob in negativeGlobs) {
final RegExp regExp = await parseGlob(glob);
// if the file is not in any of the paths then add the target.
if (files.any((String? file) => regExp.hasMatch(file!))) {
shouldAdd = false;
break;
}
}
if (shouldAdd) {
targetsToRun.add(target);
}
} else {
for (String glob in globs) {
// If a file is found within a pre-set dir, the builder needs to run. No need to check further.
final RegExp regExp = await parseGlob(glob);
if (glob.isEmpty || files.any((String? file) => regExp.hasMatch(file!))) {
targetsToRun.add(target);
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export 'build_status_response.pbenum.dart';
class BuildStatusResponse extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'BuildStatusResponse',
package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'cocoon'),
createEmptyInstance: create)
..e<EnumBuildStatus>(
1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'buildStatus', $pb.PbFieldType.OE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import 'package:protobuf/protobuf.dart' as $pb;

class EnumBuildStatus extends $pb.ProtobufEnum {
static const EnumBuildStatus success =
EnumBuildStatus._(1, $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'success');
EnumBuildStatus._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'success');
static const EnumBuildStatus failure =
EnumBuildStatus._(2, $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'failure');
EnumBuildStatus._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'failure');

static const $core.List<EnumBuildStatus> values = <EnumBuildStatus>[
success,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import 'dart:convert' as $convert;
import 'dart:typed_data' as $typed_data;

@$core.Deprecated('Use enumBuildStatusDescriptor instead')
const EnumBuildStatus$json = {
const EnumBuildStatus$json = const {
'1': 'EnumBuildStatus',
'2': [
{'1': 'success', '2': 1},
{'1': 'failure', '2': 2},
'2': const [
const {'1': 'success', '2': 1},
const {'1': 'failure', '2': 2},
],
};

/// Descriptor for `EnumBuildStatus`. Decode as a `google.protobuf.EnumDescriptorProto`.
final $typed_data.Uint8List enumBuildStatusDescriptor =
$convert.base64Decode('Cg9FbnVtQnVpbGRTdGF0dXMSCwoHc3VjY2VzcxABEgsKB2ZhaWx1cmUQAg==');
@$core.Deprecated('Use buildStatusResponseDescriptor instead')
const BuildStatusResponse$json = {
const BuildStatusResponse$json = const {
'1': 'BuildStatusResponse',
'2': [
{'1': 'build_status', '3': 1, '4': 1, '5': 14, '6': '.EnumBuildStatus', '10': 'buildStatus'},
{'1': 'failing_tasks', '3': 2, '4': 3, '5': 9, '10': 'failingTasks'},
'2': const [
const {'1': 'build_status', '3': 1, '4': 1, '5': 14, '6': '.cocoon.EnumBuildStatus', '10': 'buildStatus'},
const {'1': 'failing_tasks', '3': 2, '4': 3, '5': 9, '10': 'failingTasks'},
],
};

/// Descriptor for `BuildStatusResponse`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List buildStatusResponseDescriptor = $convert.base64Decode(
'ChNCdWlsZFN0YXR1c1Jlc3BvbnNlEjMKDGJ1aWxkX3N0YXR1cxgBIAEoDjIQLkVudW1CdWlsZFN0YXR1c1ILYnVpbGRTdGF0dXMSIwoNZmFpbGluZ190YXNrcxgCIAMoCVIMZmFpbGluZ1Rhc2tz');
'ChNCdWlsZFN0YXR1c1Jlc3BvbnNlEjoKDGJ1aWxkX3N0YXR1cxgBIAEoDjIXLmNvY29vbi5FbnVtQnVpbGRTdGF0dXNSC2J1aWxkU3RhdHVzEiMKDWZhaWxpbmdfdGFza3MYAiADKAlSDGZhaWxpbmdUYXNrcw==');
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:protobuf/protobuf.dart' as $pb;
class GithubWebhookMessage extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'GithubWebhookMessage',
package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'cocoon'),
createEmptyInstance: create)
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'event')
..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'payload')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import 'dart:convert' as $convert;
import 'dart:typed_data' as $typed_data;

@$core.Deprecated('Use githubWebhookMessageDescriptor instead')
const GithubWebhookMessage$json = {
const GithubWebhookMessage$json = const {
'1': 'GithubWebhookMessage',
'2': [
{'1': 'event', '3': 1, '4': 1, '5': 9, '10': 'event'},
{'1': 'payload', '3': 2, '4': 1, '5': 9, '10': 'payload'},
'2': const [
const {'1': 'event', '3': 1, '4': 1, '5': 9, '10': 'event'},
const {'1': 'payload', '3': 2, '4': 1, '5': 9, '10': 'payload'},
],
};

Expand Down
2 changes: 2 additions & 0 deletions app_dart/lib/src/model/proto/internal/key.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Key extends $pb.GeneratedMessage {
static const $core.Map<$core.int, Key_Id> _Key_IdByTag = {2: Key_Id.uid, 3: Key_Id.name, 0: Key_Id.notSet};
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'Key',
package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'cocoon'),
createEmptyInstance: create)
..oo(0, [2, 3])
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'type')
Expand Down Expand Up @@ -125,6 +126,7 @@ class Key extends $pb.GeneratedMessage {
class RootKey extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'RootKey',
package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'cocoon'),
createEmptyInstance: create)
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'namespace')
..aOM<Key>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'child', subBuilder: Key.create)
Expand Down
30 changes: 15 additions & 15 deletions app_dart/lib/src/model/proto/internal/key.pbjson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ import 'dart:convert' as $convert;
import 'dart:typed_data' as $typed_data;

@$core.Deprecated('Use keyDescriptor instead')
const Key$json = {
const Key$json = const {
'1': 'Key',
'2': [
{'1': 'type', '3': 1, '4': 1, '5': 9, '10': 'type'},
{'1': 'uid', '3': 2, '4': 1, '5': 3, '9': 0, '10': 'uid'},
{'1': 'name', '3': 3, '4': 1, '5': 9, '9': 0, '10': 'name'},
{'1': 'child', '3': 4, '4': 1, '5': 11, '6': '.Key', '10': 'child'},
'2': const [
const {'1': 'type', '3': 1, '4': 1, '5': 9, '10': 'type'},
const {'1': 'uid', '3': 2, '4': 1, '5': 3, '9': 0, '10': 'uid'},
const {'1': 'name', '3': 3, '4': 1, '5': 9, '9': 0, '10': 'name'},
const {'1': 'child', '3': 4, '4': 1, '5': 11, '6': '.cocoon.Key', '10': 'child'},
],
'8': [
{'1': 'id'},
'8': const [
const {'1': 'id'},
],
};

/// Descriptor for `Key`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List keyDescriptor = $convert.base64Decode(
'CgNLZXkSEgoEdHlwZRgBIAEoCVIEdHlwZRISCgN1aWQYAiABKANIAFIDdWlkEhQKBG5hbWUYAyABKAlIAFIEbmFtZRIaCgVjaGlsZBgEIAEoCzIELktleVIFY2hpbGRCBAoCaWQ=');
'CgNLZXkSEgoEdHlwZRgBIAEoCVIEdHlwZRISCgN1aWQYAiABKANIAFIDdWlkEhQKBG5hbWUYAyABKAlIAFIEbmFtZRIhCgVjaGlsZBgEIAEoCzILLmNvY29vbi5LZXlSBWNoaWxkQgQKAmlk');
@$core.Deprecated('Use rootKeyDescriptor instead')
const RootKey$json = {
const RootKey$json = const {
'1': 'RootKey',
'2': [
{'1': 'namespace', '3': 1, '4': 1, '5': 9, '10': 'namespace'},
{'1': 'child', '3': 2, '4': 1, '5': 11, '6': '.Key', '10': 'child'},
'2': const [
const {'1': 'namespace', '3': 1, '4': 1, '5': 9, '10': 'namespace'},
const {'1': 'child', '3': 2, '4': 1, '5': 11, '6': '.cocoon.Key', '10': 'child'},
],
};

/// Descriptor for `RootKey`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List rootKeyDescriptor = $convert
.base64Decode('CgdSb290S2V5EhwKCW5hbWVzcGFjZRgBIAEoCVIJbmFtZXNwYWNlEhoKBWNoaWxkGAIgASgLMgQuS2V5UgVjaGlsZA==');
final $typed_data.Uint8List rootKeyDescriptor = $convert.base64Decode(
'CgdSb290S2V5EhwKCW5hbWVzcGFjZRgBIAEoCVIJbmFtZXNwYWNlEiEKBWNoaWxkGAIgASgLMgsuY29jb29uLktleVIFY2hpbGQ=');
17 changes: 14 additions & 3 deletions app_dart/lib/src/model/proto/internal/scheduler.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export 'scheduler.pbenum.dart';
class SchedulerConfig_PlatformProperties extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'SchedulerConfig.PlatformProperties',
package: const $pb.PackageName($core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'scheduler'),
package:
const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'scheduler'),
createEmptyInstance: create)
..m<$core.String, $core.String>(
1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'properties',
Expand Down Expand Up @@ -83,7 +84,8 @@ class SchedulerConfig_PlatformProperties extends $pb.GeneratedMessage {
class SchedulerConfig extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'SchedulerConfig',
package: const $pb.PackageName($core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'scheduler'),
package:
const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'scheduler'),
createEmptyInstance: create)
..pc<Target>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'targets', $pb.PbFieldType.PM,
subBuilder: Target.create)
Expand Down Expand Up @@ -153,7 +155,8 @@ class SchedulerConfig extends $pb.GeneratedMessage {
class Target extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'Target',
package: const $pb.PackageName($core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'scheduler'),
package:
const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'scheduler'),
createEmptyInstance: create)
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name')
..pPS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'dependencies')
Expand Down Expand Up @@ -196,6 +199,7 @@ class Target extends $pb.GeneratedMessage {
valueFieldType: $pb.PbFieldType.OS,
packageName: const $pb.PackageName('scheduler'))
..pPS(17, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'droneDimensions')
..pPS(18, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'runIfNot')
..hasRequiredFields = false;

Target._() : super();
Expand All @@ -216,6 +220,7 @@ class Target extends $pb.GeneratedMessage {
$core.Map<$core.String, $core.String>? postsubmitProperties,
$core.Map<$core.String, $core.String>? dimensions,
$core.Iterable<$core.String>? droneDimensions,
$core.Iterable<$core.String>? runIfNot,
}) {
final _result = create();
if (name != null) {
Expand Down Expand Up @@ -267,6 +272,9 @@ class Target extends $pb.GeneratedMessage {
if (droneDimensions != null) {
_result.droneDimensions.addAll(droneDimensions);
}
if (runIfNot != null) {
_result.runIfNot.addAll(runIfNot);
}
return _result;
}
factory Target.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
Expand Down Expand Up @@ -423,4 +431,7 @@ class Target extends $pb.GeneratedMessage {

@$pb.TagNumber(17)
$core.List<$core.String> get droneDimensions => $_getList(15);

@$pb.TagNumber(18)
$core.List<$core.String> get runIfNot => $_getList(16);
}
8 changes: 4 additions & 4 deletions app_dart/lib/src/model/proto/internal/scheduler.pbenum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import 'package:protobuf/protobuf.dart' as $pb;

class SchedulerSystem extends $pb.ProtobufEnum {
static const SchedulerSystem cocoon =
SchedulerSystem._(1, $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'cocoon');
SchedulerSystem._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'cocoon');
static const SchedulerSystem luci =
SchedulerSystem._(2, $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'luci');
SchedulerSystem._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'luci');
static const SchedulerSystem google_internal =
SchedulerSystem._(3, $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'google_internal');
SchedulerSystem._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'google_internal');
static const SchedulerSystem release =
SchedulerSystem._(4, $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'release');
SchedulerSystem._(4, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'release');

static const $core.List<SchedulerSystem> values = <SchedulerSystem>[
cocoon,
Expand Down
Loading

0 comments on commit 58676a6

Please sign in to comment.