Skip to content

Commit

Permalink
check: Add selectivity with --diff/--all options, on suite drift
Browse files Browse the repository at this point in the history
Other suites still run all the time, effectively using the `--all`
behavior unconditionally.
  • Loading branch information
gnprice committed Oct 3, 2023
1 parent e9e628f commit 9b15528
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
run: flutter pub get

- name: Run tools/check
run: TERM=dumb tools/check
run: TERM=dumb tools/check --all
58 changes: 55 additions & 3 deletions tools/check
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
# function.
set -euo pipefail

this_dir=${BASH_SOURCE[0]%/*}

# shellcheck source=tools/lib/git.sh
. "${this_dir}"/lib/git.sh


## CLI PARSING

Expand All @@ -29,21 +34,40 @@ usage: tools/check [OPTION]... [SUITE]...
Run our tests.
By default, run only on files changed in this branch
as compared to the upstream \`main\`.
By default, run ${#default_suites[@]} suite(s):
${default_suites[*]}
and skip ${#extra_suites[@]} suite(s):
${extra_suites[*]}
Options:
What tests to run:
--all-files
Run on all files, not only changed files.
--diff COMMIT
Run only on files that differ from the given commit.
(E.g., \`--diff @\` for files with uncommitted changes;
\`--diff @~10\` for files changed in last 10 commits; or see
\`git help revisions\` for many more ways to name a commit.)
--all In the given suites, run on all files. If no list of suites
was specified, run all suites.
Extra things to do:
--fix Fix issues found, where possible.
EOF
exit 2
}

opt_files=branch
opt_all=
opt_fix=
opt_suites=()
while (( $# )); do
case "$1" in
--diff) shift; opt_files=diff:"$1"; shift;;
--all-files) opt_files=all; shift;;
--all) opt_files=all; opt_all=1; shift;;
--fix) opt_fix=1; shift;;
analyze|test|build_runner|drift)
opt_suites+=("$1"); shift;;
Expand All @@ -52,16 +76,37 @@ while (( $# )); do
done

if (( ! "${#opt_suites[@]}" )); then
opt_suites=( "${default_suites[@]}" )
if [ -n "${opt_all}" ]; then
opt_suites=( "${default_suites[@]}" "${extra_suites[@]}" )
else
opt_suites=( "${default_suites[@]}" )
fi
fi

files_base_commit=
# shellcheck disable=SC2119 # this is a silly warning
case "$opt_files" in
all) ;;
branch) files_base_commit="$(git_base_commit)";;
diff:*) files_base_commit="${opt_files#diff:}";;
esac


## EXECUTION

rootdir=$(git rev-parse --show-toplevel)
cd "$rootdir"

. tools/lib/git.sh
# True just if $opt_files intersects the given set of paths.
files_check() {
case "$opt_files" in
all)
;;
branch | diff:*)
! git diff --quiet "${files_base_commit}" -- "$@"
;;
esac
}

# usage: check_no_changes CHANGE_DESCRIPTION [GIT_PATHSPECS...]
#
Expand Down Expand Up @@ -132,6 +177,13 @@ run_build_runner() {
run_drift() {
local schema_dir=test/model/schemas/

# We omit from this files_check some files that in principle can affect
# the outcome of this suite, but are expected to more often just cause noise
# by rerunning it on changes that cannot actually affect it:
# pubspec.{yaml,lock} tools/check
files_check lib/model/database{,.g}.dart "${schema_dir}" \
|| return 0

check_no_uncommitted_or_untracked "${schema_dir}" \
|| return

Expand Down

0 comments on commit 9b15528

Please sign in to comment.