Skip to content

Commit

Permalink
check: Add option --verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Oct 3, 2023
1 parent 019e721 commit 73577eb
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 11 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 --all
run: TERM=dumb tools/check --all --verbose
87 changes: 77 additions & 10 deletions tools/check
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,27 @@ What tests to run:
Extra things to do:
--fix Fix issues found, where possible.
Modifying this script's output:
--verbose Print more details about everything.
EOF
exit 2
}

orig_cmdline="$0 $*"

opt_files=branch
opt_all=
opt_fix=
opt_verbose=
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;;
--verbose) opt_verbose=1; shift;;
analyze|test|build_runner|drift|icons|shellcheck)
opt_suites+=("$1"); shift;;
*) usage;;
Expand Down Expand Up @@ -98,6 +105,20 @@ esac
rootdir=$(git rev-parse --show-toplevel)
cd "$rootdir"

divider_line='================================================================'

# usage: if_verbose COMMAND...
#
# Run the given command just if $opt_verbose; else do nothing.
#
# This is a convenience shorthand for simple commands. For more complex logic,
# write `if [ -n "${opt_verbose}" ]` directly.
if_verbose() {
if [ -n "${opt_verbose}" ]; then
"$@"
fi
}

# True just if $opt_files intersects the given set of paths.
#
# On what paths to include in this check (and more generally, how to write
Expand Down Expand Up @@ -169,10 +190,12 @@ check_no_changes() {
}

run_analyze() {
# no `flutter analyze --verbose` even when $opt_verbose; it's *very* verbose
flutter analyze
}

run_test() {
# no `flutter test --verbose` even when $opt_verbose; it's *very* verbose
flutter test
}

Expand Down Expand Up @@ -206,16 +229,25 @@ run_build_runner() {
check_no_uncommitted_or_untracked '*.g.dart' \
|| return

# build_runner has a --verbose, but lacks a --quiet.
# So we filter out "[INFO]" messages ourselves.
dart run build_runner build --delete-conflicting-outputs \
| perl -lne '
BEGIN { my $silence = 0 }
if (/^\[INFO\]/) { $silence = 1 }
elsif (/^\[[A-Z]/) { $silence = 0 }
print if (!$silence)
' \
|| return
local build_runner_cmd=(
dart run build_runner build --delete-conflicting-outputs
)
if [ -n "${opt_verbose}" ]; then
# No --verbose needed; build_runner is verbose enough by default.
"${build_runner_cmd[@]}" \
|| return
else
# build_runner lacks a --quiet, and is fairly verbose to begin with.
# So we filter out "[INFO]" messages ourselves.
"${build_runner_cmd[@]}" \
| perl -lne '
BEGIN { my $silence = 0 }
if (/^\[INFO\]/) { $silence = 1 }
elsif (/^\[[A-Z]/) { $silence = 0 }
print if (!$silence)
' \
|| return
fi

check_no_changes "updates to *.g.dart files" '*.g.dart'
}
Expand Down Expand Up @@ -283,11 +315,45 @@ EOF
return 1
fi

if_verbose shellcheck --version
shellcheck -x --shell=bash -- "${targets[@]}"
}

describe_git_head() {
local name="$1" repo_path="$2"
local commit_data
commit_data=$(
TZ=UTC \
git --git-dir "${repo_path}" \
log -1 --format="%h • %cd" \
--abbrev=9 --date=iso8601-local
)
echo "${name} ${commit_data}"
}

print_header() {
local flutter_executable flutter_tree

echo "Test command: ${orig_cmdline}"

echo "Time now: $(date --utc +'%F %T %z')"

describe_git_head "zulip-flutter" .git/

# We avoid `flutter --version` because, weirdly, when run in a
# GitHub Actions step it takes about 30 seconds. (The first time;
# it's fast subsequent times.) That's even after `flutter precache`.
flutter_executable=$(readlink -f "$(type -p flutter)")
flutter_tree=${flutter_executable%/bin/flutter}
describe_git_head "flutter/flutter" "${flutter_tree}"/.git

dart --version
}

if_verbose print_header
failed=()
for suite in "${opt_suites[@]}"; do
if_verbose echo "${divider_line}"
echo "Running $suite..."
case "$suite" in
analyze) run_analyze ;;
Expand All @@ -299,6 +365,7 @@ for suite in "${opt_suites[@]}"; do
*) echo >&2 "Internal error: unknown suite $suite" ;;
esac || failed+=( "$suite" )
done
if_verbose echo "${divider_line}"

if (( ${#failed[@]} )); then
cat >&2 <<EOF
Expand Down

0 comments on commit 73577eb

Please sign in to comment.