@@ -26,6 +26,7 @@ this_dir=${BASH_SOURCE[0]%/*}
26
26
27
27
default_suites=(
28
28
analyze test
29
+ flutter_version
29
30
build_runner l10n drift pigeon icons
30
31
android # This takes multiple minutes in CI, so do it last.
31
32
)
@@ -82,7 +83,7 @@ while (( $# )); do
82
83
--all) opt_files=all; opt_all=1; shift ;;
83
84
--fix) opt_fix=1; shift ;;
84
85
--verbose) opt_verbose=1; shift ;;
85
- analyze|test|build_runner|l10n|drift|pigeon|icons|android|shellcheck)
86
+ analyze|test|flutter_version| build_runner|l10n|drift|pigeon|icons|android|shellcheck)
86
87
opt_suites+=(" $1 " ); shift ;;
87
88
* ) usage;;
88
89
esac
@@ -218,6 +219,49 @@ run_test() {
218
219
flutter test
219
220
}
220
221
222
+ # Check the Flutter version in pubspec.yaml is commented with a commit ID,
223
+ # and the commit is from upstream main.
224
+ run_flutter_version () {
225
+ # Omitted from this files check:
226
+ # tools/check
227
+ files_check pubspec.yaml \
228
+ || return 0
229
+
230
+ local flutter_tree flutter_git
231
+ flutter_tree=$( flutter_tree)
232
+ flutter_git=( git --git-dir=" ${flutter_tree} " /.git )
233
+
234
+ # Parse our Flutter version spec with its commit-ID comment.
235
+ local flutter_commit
236
+ flutter_commit=$(
237
+ perl < pubspec.yaml -0ne '
238
+ print $1 if (/^ sdk: .*\n flutter: \S+\s*# ([0-9a-f]{40})$/m)'
239
+ ) || return
240
+ if [ -z " ${flutter_commit} " ]; then
241
+ echo >&2 " error: Flutter commit spec not found in pubspec.yaml"
242
+ return 1
243
+ fi
244
+
245
+ # Check the commit is an acceptable commit.
246
+ local commit_count
247
+ commit_count=$(
248
+ " ${flutter_git[@]} " rev-list --count origin/main.." ${flutter_commit} "
249
+ ) || return
250
+ if (( "${commit_count} " )) ; then
251
+ cat >&2 << EOF
252
+ error: Flutter commit spec in pubspec.yaml is not from upstream main.
253
+ Commit ${flutter_commit} has ${commit_count} commits not in main:
254
+ EOF
255
+ " ${flutter_git[@]} " log --oneline --reverse \
256
+ origin/main.." ${flutter_commit} "
257
+ return 1
258
+ fi
259
+
260
+ if_verbose echo " OK Flutter commit ${flutter_commit} "
261
+
262
+ return 0
263
+ }
264
+
221
265
# Whether the build_runner suite should run, given $opt_files.
222
266
should_run_build_runner () {
223
267
# First, check for changes in relevant metadata.
@@ -456,6 +500,7 @@ for suite in "${opt_suites[@]}"; do
456
500
case " $suite " in
457
501
analyze) run_analyze ;;
458
502
test) run_test ;;
503
+ flutter_version) run_flutter_version ;;
459
504
build_runner) run_build_runner ;;
460
505
l10n) run_l10n ;;
461
506
drift) run_drift ;;
0 commit comments