Skip to content

Commit cc9c13e

Browse files
authored
Experiment with a files-changed.json per PR (flutter#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!
1 parent 2d3bead commit cc9c13e

File tree

4 files changed

+118
-9
lines changed

4 files changed

+118
-9
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Generate Changed Files JSON
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
9+
jobs:
10+
generate-json:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Fetch base commit and origin/master
17+
# Fetch what to compare the commit against
18+
run: |
19+
git fetch --no-tags --prune --depth=1 origin ${{ github.event.pull_request.base.sha }}
20+
git fetch --no-tags --prune --depth=1 origin master
21+
echo "FLUTTER_ENGINE_VERSION=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_ENV"
22+
23+
- name: Initialize Dart SDK
24+
# This downloads the version of the Dart SDK for the current platform.
25+
run: |
26+
./bin/dart --version
27+
cd dev/tools && ../../bin/dart pub get
28+
29+
- name: Write changed files to a JSON file
30+
run: |
31+
./bin/dart run dev/tools/bin/get_files_changed.dart --since="${{ github.event.pull_request.base.sha }}" > changed_files.json
32+
33+
- name: Upload artifact
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: changed-files
37+
path: changed_files.json

bin/internal/update_engine_version.sh

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,24 @@
1414

1515
set -e
1616

17+
# Allow overriding the intended engine version via FLUTTER_ENGINE_VERSION.
18+
#
19+
# This is for systems, such as Github Actions, where we know ahead of time the
20+
# base-ref we want to use (to download the engine binaries and avoid trying
21+
# to compute one below).
22+
#
23+
# This environment variable is EXPERIMENTAL. If you are not on the Flutter infra
24+
# team, this code path might be removed at anytime and cease functioning. Please
25+
# file an issue if you have workflow needs.
26+
if [ -n "${FLUTTER_ENGINE_VERSION}" ]; then
27+
ENGINE_VERSION="${FLUTTER_ENGINE_VERSION}"
28+
echo "[Unstable] Override: Setting engine SHA to $ENGINE_VERSION" 1>&2
29+
fi
30+
1731
FLUTTER_ROOT="$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")")"
1832

19-
# Test for fusion repository
20-
if [ -f "$FLUTTER_ROOT/DEPS" ] && [ -f "$FLUTTER_ROOT/engine/src/.gn" ]; then
33+
# Test for fusion repository and no environment variable override.
34+
if [ -z "$ENGINE_VERSION" ] && [ -f "$FLUTTER_ROOT/DEPS" ] && [ -f "$FLUTTER_ROOT/engine/src/.gn" ]; then
2135
BRANCH=$(git -C "$FLUTTER_ROOT" rev-parse --abbrev-ref HEAD)
2236
# In a fusion repository; the engine.version comes from the git hashes.
2337
if [ -z "${LUCI_CONTEXT}" ]; then
@@ -35,14 +49,14 @@ if [ -f "$FLUTTER_ROOT/DEPS" ] && [ -f "$FLUTTER_ROOT/engine/src/.gn" ]; then
3549
else
3650
ENGINE_VERSION=$(git -C "$FLUTTER_ROOT" rev-parse HEAD)
3751
fi
52+
fi
3853

39-
if [[ "$BRANCH" != "stable" && "$BRANCH" != "beta" ]]; then
40-
# Write the engine version out so downstream tools know what to look for.
41-
echo $ENGINE_VERSION > "$FLUTTER_ROOT/bin/internal/engine.version"
54+
if [[ "$BRANCH" != "stable" && "$BRANCH" != "beta" ]]; then
55+
# Write the engine version out so downstream tools know what to look for.
56+
echo $ENGINE_VERSION > "$FLUTTER_ROOT/bin/internal/engine.version"
4257

43-
# The realm on CI is passed in.
44-
if [ -n "${FLUTTER_REALM}" ]; then
45-
echo $FLUTTER_REALM > "$FLUTTER_ROOT/bin/internal/engine.realm"
46-
fi
58+
# The realm on CI is passed in.
59+
if [ -n "${FLUTTER_REALM}" ]; then
60+
echo $FLUTTER_REALM > "$FLUTTER_ROOT/bin/internal/engine.realm"
4761
fi
4862
fi

dev/tools/bin/GITHUB_ACTIONS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a stub-file that can be deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:convert';
6+
import 'dart:io' as io;
7+
8+
import 'package:args/args.dart';
9+
10+
final ArgParser _argParser =
11+
ArgParser()
12+
..addOption(
13+
'since',
14+
help: 'What previous SHA to compare the current git state to.',
15+
defaultsTo: 'HEAD^',
16+
)
17+
..addOption(
18+
'output',
19+
help: 'What format to output in.',
20+
defaultsTo: io.stdout.hasTerminal ? 'text' : 'json',
21+
allowed: <String>['text', 'json'],
22+
);
23+
24+
void main(List<String> args) async {
25+
final ArgResults argResults = _argParser.parse(args);
26+
27+
// Get a list of files changed between this commit and the base SHA.
28+
final List<String> filesChanged;
29+
{
30+
final List<String> args = <String>[
31+
'diff',
32+
'--name-only',
33+
'--full-index',
34+
argResults.option('since')!,
35+
];
36+
final io.ProcessResult git = await io.Process.run('git', args);
37+
if (git.exitCode != 0) {
38+
io.stderr.writeln('$args failed (exit code: ${git.exitCode}):');
39+
io.stderr.writeln(git.stdout);
40+
io.stderr.writeln(git.stderr);
41+
io.exitCode = 1;
42+
return;
43+
}
44+
45+
final String stdout = git.stdout as String;
46+
filesChanged = const LineSplitter().convert(stdout);
47+
}
48+
49+
// Output to stdout.
50+
final _Output output = _Output.values.byName(argResults.option('output')!);
51+
io.stdout.writeln(switch (output) {
52+
_Output.text => filesChanged.join('\n'),
53+
_Output.json => jsonEncode(filesChanged),
54+
});
55+
}
56+
57+
enum _Output { text, json }

0 commit comments

Comments
 (0)