From 356fc9ec5261a2fa1ffe62e5ffdca33cdbcccbdc Mon Sep 17 00:00:00 2001 From: Rajesh Malviya Date: Mon, 15 Dec 2025 21:02:26 +0530 Subject: [PATCH 1/3] ci: Fetch all branches during the checkout step See: https://github.com/actions/checkout/blob/8e8c483db/action.yml#L74-L76 Without this change, the main branch is not fetched when the current branch is non-main. We need this because soon we will run the `flutter_version` suite in CI only when there are changes in `pubspec.yaml` or `tools/check` files. For that, we need the `main` branch to be able to calculate the file diff. Otherwise the suite will fail when calling `git_base_commit` saying: fatal: Not a valid object name refs/remotes/origin/main --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92cbc4817e..7db0a988ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,8 @@ jobs: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v6 + with: + fetch-depth: 0 - name: Install system dependencies run: TERM=dumb sudo apt install libsqlite3-dev -y From 6fed533ae155d7275cc3b0066130cdeb22d1b72f Mon Sep 17 00:00:00 2001 From: Rajesh Malviya Date: Mon, 15 Dec 2025 21:55:23 +0530 Subject: [PATCH 2/3] ci: Run flutter_version suite conditionally Flutter's new versioning depends on the latest tag pushed upstream. And we are going to add the check for Flutter version string back soon. To avoid frequent CI failures that may be caused by a new tag being pushed upstream, run the flutter_version check in CI only when there are changes in the `pubspec.yaml` or `tools/check` files. --- .github/workflows/ci.yml | 5 ++++- tools/check | 5 +---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7db0a988ba..6d1138ebd5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,5 +42,8 @@ jobs: - name: Download our dependencies (flutter pub get) run: flutter pub get - - name: Run tools/check + - name: Run tools/check (flutter_version) + run: TERM=dumb tools/check --verbose flutter_version + + - name: Run tools/check (all default suites) run: TERM=dumb tools/check --all --verbose diff --git a/tools/check b/tools/check index 407d87a30f..eeba064372 100755 --- a/tools/check +++ b/tools/check @@ -29,7 +29,6 @@ this_dir=${BASH_SOURCE[0]%/*} default_suites=( analyze test - flutter_version build_runner l10n drift pigeon icons android # This takes multiple minutes in CI, so do it last. ) @@ -225,9 +224,7 @@ run_test() { # Check the Flutter version in pubspec.yaml is commented with a commit ID, # which agrees with the version, and the commit is from upstream main. run_flutter_version() { - # Omitted from this files check: - # tools/check - files_check pubspec.yaml \ + files_check pubspec.yaml tools/check \ || return 0 local flutter_tree flutter_git From 5389e66a5151e47fffaf61f4a791c235c9997848 Mon Sep 17 00:00:00 2001 From: Rajesh Malviya Date: Thu, 16 Oct 2025 18:47:48 +0530 Subject: [PATCH 3/3] check: Update the flutter_version check to follow upstream Since https://github.com/flutter/flutter/commit/e45fd36aa the flutter tool now uses a combination of git commands, instead of using the result of `git describe` to generate the version string. So, we update the check to use the same commands here, and then do some transformations to match the string from the flutter tool: https://github.com/flutter/flutter/blob/9f383e099/packages/flutter_tools/lib/src/version.dart#L1162 Fixes: #1851 --- tools/check | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/tools/check b/tools/check index eeba064372..7d0e74f9e5 100755 --- a/tools/check +++ b/tools/check @@ -221,6 +221,71 @@ run_test() { flutter test } +# Predict a Flutter version string from the given Flutter commit SHA. +predict_flutter_version() { + local flutter_commit + flutter_commit="$1" + + local flutter_tree flutter_git + flutter_tree=$(flutter_tree) + flutter_git=( git --git-dir="${flutter_tree}"/.git ) + + # Check the version name matches the calculated version using the + # latest tag. We mimic the upstream Flutter tools's implementation here: + # https://github.com/flutter/flutter/blob/7258223ea/packages/flutter_tools/lib/src/version.dart#L1060-L1091 + local latest_tag ancestor_ref commit_count + latest_tag=$( + "${flutter_git[@]}" for-each-ref \ + --sort=-v:refname \ + --count=1 \ + --format='%(refname:short)' \ + 'refs/tags/[0-9]*.*.*' + ) || return + if [ -z "${latest_tag}" ]; then + echo >&2 "error: Failed to determine the latest tag" + return 1 + fi + ancestor_ref=$( + "${flutter_git[@]}" merge-base "${flutter_commit}" "${latest_tag}" + ) || return + if [ -z "${ancestor_ref}" ]; then + echo >&2 "error: Failed to determine merge-base between ${flutter_commit} and ${latest_tag}" + return 1 + fi + commit_count=$( + "${flutter_git[@]}" rev-list --count "${ancestor_ref}..${flutter_commit}" + ) || return + if [ -z "${commit_count}" ]; then + echo >&2 "error: Failed to count commits from ${ancestor_ref} to ${flutter_commit}" + return 1 + fi + + latest_tag_version="${latest_tag}-${commit_count}" + + # Generate a predicted Flutter version string by parsing the latest tag + # version and applying the same transformations as the upstream Flutter + # tool: + # https://github.com/flutter/flutter/blob/7258223ea/packages/flutter_tools/lib/src/version.dart#L1162 + predicted_version=$( + echo "${latest_tag_version}" \ + | perl -lne 'print if (s + # This transformation is ad hoc. + # If we find cases where it fails, we can study + # how the `flutter` tool actually decides the version name. + <^(\d+\.\d+\.\d+-) (\d+) \.\d+\.pre -(\d+)$> + <$1 . ($2 + 1) . ".0.pre-" . $3>xe)' + ) || return + if [ -z "${predicted_version}" ]; then + cat >&2 <&2 <