diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92cbc4817e..6d1138ebd5 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 @@ -40,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..7d0e74f9e5 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. ) @@ -222,12 +221,75 @@ 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 <