forked from firka/flutter
Experiment with a files-changed.json per PR (#161788)
This is an experiment to determine what the wall time of a (minimal) "upload a JSON file describing files changed". We are looking for this to take (low) single digit minutes, because if we use this file (and expand it to become a build plan), it will block almost _all_ other actions, and will likely get longer as we add more complex logic and checks. Here's hoping!
This commit is contained in:
1
dev/tools/bin/GITHUB_ACTIONS.md
Normal file
1
dev/tools/bin/GITHUB_ACTIONS.md
Normal file
@@ -0,0 +1 @@
|
||||
This is a stub-file that can be deleted.
|
||||
57
dev/tools/bin/get_files_changed.dart
Normal file
57
dev/tools/bin/get_files_changed.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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 'dart:convert';
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:args/args.dart';
|
||||
|
||||
final ArgParser _argParser =
|
||||
ArgParser()
|
||||
..addOption(
|
||||
'since',
|
||||
help: 'What previous SHA to compare the current git state to.',
|
||||
defaultsTo: 'HEAD^',
|
||||
)
|
||||
..addOption(
|
||||
'output',
|
||||
help: 'What format to output in.',
|
||||
defaultsTo: io.stdout.hasTerminal ? 'text' : 'json',
|
||||
allowed: <String>['text', 'json'],
|
||||
);
|
||||
|
||||
void main(List<String> args) async {
|
||||
final ArgResults argResults = _argParser.parse(args);
|
||||
|
||||
// Get a list of files changed between this commit and the base SHA.
|
||||
final List<String> filesChanged;
|
||||
{
|
||||
final List<String> args = <String>[
|
||||
'diff',
|
||||
'--name-only',
|
||||
'--full-index',
|
||||
argResults.option('since')!,
|
||||
];
|
||||
final io.ProcessResult git = await io.Process.run('git', args);
|
||||
if (git.exitCode != 0) {
|
||||
io.stderr.writeln('$args failed (exit code: ${git.exitCode}):');
|
||||
io.stderr.writeln(git.stdout);
|
||||
io.stderr.writeln(git.stderr);
|
||||
io.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
final String stdout = git.stdout as String;
|
||||
filesChanged = const LineSplitter().convert(stdout);
|
||||
}
|
||||
|
||||
// Output to stdout.
|
||||
final _Output output = _Output.values.byName(argResults.option('output')!);
|
||||
io.stdout.writeln(switch (output) {
|
||||
_Output.text => filesChanged.join('\n'),
|
||||
_Output.json => jsonEncode(filesChanged),
|
||||
});
|
||||
}
|
||||
|
||||
enum _Output { text, json }
|
||||
Reference in New Issue
Block a user