Skip to content

Commit 1201e38

Browse files
committed
check: Add suite flutter_version
1 parent 9618f40 commit 1201e38

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

tools/check

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ this_dir=${BASH_SOURCE[0]%/*}
2626

2727
default_suites=(
2828
analyze test
29+
flutter_version
2930
build_runner l10n drift pigeon icons
3031
android # This takes multiple minutes in CI, so do it last.
3132
)
@@ -82,7 +83,7 @@ while (( $# )); do
8283
--all) opt_files=all; opt_all=1; shift;;
8384
--fix) opt_fix=1; shift;;
8485
--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)
8687
opt_suites+=("$1"); shift;;
8788
*) usage;;
8889
esac
@@ -218,6 +219,49 @@ run_test() {
218219
flutter test
219220
}
220221

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+
221265
# Whether the build_runner suite should run, given $opt_files.
222266
should_run_build_runner() {
223267
# First, check for changes in relevant metadata.
@@ -456,6 +500,7 @@ for suite in "${opt_suites[@]}"; do
456500
case "$suite" in
457501
analyze) run_analyze ;;
458502
test) run_test ;;
503+
flutter_version) run_flutter_version ;;
459504
build_runner) run_build_runner ;;
460505
l10n) run_l10n ;;
461506
drift) run_drift ;;

0 commit comments

Comments
 (0)