Skip to content

Commit

Permalink
Merge branch 'flutter:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoamador authored Jan 25, 2024
2 parents b10b508 + a22d1ad commit 77669d7
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 9 deletions.
22 changes: 17 additions & 5 deletions app_dart/lib/src/request_handlers/file_flaky_issue_and_pr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ class FileFlakyIssueAndPR extends ApiRequestHandler<Body> {
final Map<String?, PullRequest> nameToExistingPR = await getExistingPRs(gitHub, slug);
int filedIssueAndPRCount = 0;
for (final BuilderStatistic statistic in builderStatisticList) {
// Skip if ignore_flakiness is specified.
if (getIgnoreFlakiness(statistic.name, ciYaml)) {
continue;
}
if (statistic.flakyRate < _threshold) {
if (shouldSkip(statistic, ciYaml, targets)) {
continue;
}

Expand Down Expand Up @@ -93,6 +89,22 @@ class FileFlakyIssueAndPR extends ApiRequestHandler<Body> {
});
}

bool shouldSkip(BuilderStatistic statistic, CiYaml ciYaml, List<pb.Target> targets) {
// Skips if the target has been removed from .ci.yaml.
if (!targets.map((e) => e.name).toList().contains(statistic.name)) {
return true;
}
// Skips if ignore_flakiness is specified.
if (getIgnoreFlakiness(statistic.name, ciYaml)) {
return true;
}
// Skips if the flaky percentage is below the threshold.
if (statistic.flakyRate < _threshold) {
return true;
}
return false;
}

double get _threshold => double.parse(request!.uri.queryParameters[kThresholdKey]!);

Future<bool> _fileIssueAndPR(
Expand Down
22 changes: 22 additions & 0 deletions app_dart/test/request_handlers/file_flaky_issue_and_pr_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,28 @@ void main() {

expect(result['Status'], 'success');
});

test('skips when the target doesn not exist', () {
final YamlMap? ci = loadYaml(ciYamlContent) as YamlMap?;
final pb.SchedulerConfig unCheckedSchedulerConfig = pb.SchedulerConfig()..mergeFromProto3Json(ci);
final CiYaml ciYaml = CiYaml(
slug: Config.flutterSlug,
branch: Config.defaultBranch(Config.flutterSlug),
config: unCheckedSchedulerConfig,
);
final BuilderStatistic builderStatistic = BuilderStatistic(
name: 'Mac_android test',
flakyRate: 0.5,
flakyBuilds: <String>['103', '102', '101'],
succeededBuilds: <String>['203', '202', '201'],
recentCommit: 'abc',
flakyBuildOfRecentCommit: '103',
flakyNumber: 3,
totalNumber: 6,
);
final List<pb.Target> targets = unCheckedSchedulerConfig.targets;
expect(handler.shouldSkip(builderStatistic, ciYaml, targets), true);
});
});

test('retrieveMetaTagsFromContent can work with different newlines', () async {
Expand Down
19 changes: 15 additions & 4 deletions cipd_packages/codesign/lib/src/file_codesign_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ update these file paths accordingly.
}
log.info('Child file of directory ${directory.basename} is ${entity.basename}');
}
final String directoryExtension = directory.basename.split('.').last;
if (directoryExtension == 'framework' || directoryExtension == 'xcframework') {
await codesignAtPath(binaryOrBundlePath: directory.absolute.path);
}
}

/// Unzip an [EmbeddedZip] and visit its children.
Expand Down Expand Up @@ -314,17 +318,24 @@ update these file paths accordingly.
if (dryrun) {
return;
}
await codesignAtPath(binaryOrBundlePath: binaryFile.absolute.path, entitlementCurrentPath: entitlementCurrentPath);
}

Future<void> codesignAtPath({
required String binaryOrBundlePath,
String? entitlementCurrentPath,
}) async {
final List<String> args = <String>[
'/usr/bin/codesign',
'--keychain',
'build.keychain', // specify the keychain to look for cert
'-f', // force
'-f', // force. Needed to overwrite signature if major executable of bundle is already signed before bundle is signed.
'-s', // use the cert provided by next argument
codesignCertName,
binaryFile.absolute.path,
binaryOrBundlePath,
'--timestamp', // add a secure timestamp
'--options=runtime', // hardened runtime
if (fileWithEntitlements.contains(entitlementCurrentPath)) ...<String>[
if (entitlementCurrentPath != '' && fileWithEntitlements.contains(entitlementCurrentPath)) ...<String>[
'--entitlements',
entitlementsFile.absolute.path,
],
Expand All @@ -338,7 +349,7 @@ update these file paths accordingly.
}

throw CodesignException(
'Failed to codesign ${binaryFile.absolute.path} with args: ${args.join(' ')}\n'
'Failed to codesign binary or bundle at $binaryOrBundlePath with args: ${args.join(' ')}\n'
'stdout:\n${(result.stdout as String).trim()}'
'stderr:\n${(result.stderr as String).trim()}',
);
Expand Down
81 changes: 81 additions & 0 deletions cipd_packages/codesign/test/file_codesign_visitor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,87 @@ void main() {
);
});

test('visitDirectory codesigns framework bundle', () async {
fileSystem
..file('${rootDirectory.path}/remote_zip_6/non_bundle/file_a').createSync(recursive: true)
..file('${rootDirectory.path}/remote_zip_6/bundle.xcframework/bundle.framework/file_b')
.createSync(recursive: true);
final Directory testDirectory = fileSystem.directory('${rootDirectory.path}/remote_zip_6');
processManager.addCommands(<FakeCommand>[
FakeCommand(
command: <String>[
'file',
'--mime-type',
'-b',
'${rootDirectory.absolute.path}/remote_zip_6/non_bundle/file_a',
],
stdout: 'other_files',
),
FakeCommand(
command: <String>[
'file',
'--mime-type',
'-b',
'${rootDirectory.absolute.path}/remote_zip_6/bundle.xcframework/bundle.framework/file_b',
],
stdout: 'other_files',
),
FakeCommand(
command: <String>[
'/usr/bin/codesign',
'--keychain',
'build.keychain',
'-f',
'-s',
randomString,
'${rootDirectory.absolute.path}/remote_zip_6/bundle.xcframework/bundle.framework',
'--timestamp',
'--options=runtime',
],
exitCode: 0,
),
FakeCommand(
command: <String>[
'/usr/bin/codesign',
'--keychain',
'build.keychain',
'-f',
'-s',
randomString,
'${rootDirectory.absolute.path}/remote_zip_6/bundle.xcframework',
'--timestamp',
'--options=runtime',
],
exitCode: 0,
),
]);
await codesignVisitor.visitDirectory(
directory: testDirectory,
parentVirtualPath: '',
);
final Set<String> messages = records
.where((LogRecord record) => record.level == Level.INFO)
.map((LogRecord record) => record.message)
.toSet();
expect(messages, contains('Visiting directory ${rootDirectory.path}/remote_zip_6/non_bundle'));
expect(
messages,
contains('Visiting directory ${rootDirectory.path}/remote_zip_6/bundle.xcframework/bundle.framework'),
);
expect(
messages,
contains(
'Executing: /usr/bin/codesign --keychain build.keychain -f -s $randomString ${rootDirectory.path}/remote_zip_6/bundle.xcframework/bundle.framework --timestamp --options=runtime\n',
),
);
expect(
messages,
contains(
'Executing: /usr/bin/codesign --keychain build.keychain -f -s $randomString ${rootDirectory.path}/remote_zip_6/bundle.xcframework --timestamp --options=runtime\n',
),
);
});

test('visitBinary codesigns binary with / without entitlement', () async {
codesignVisitor = cs.FileCodesignVisitor(
codesignCertName: randomString,
Expand Down

0 comments on commit 77669d7

Please sign in to comment.