mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2026-08-25 17:24:01 +00:00
tools: add make analyze/test/doctor and unify gradle wrappers
- Add scripts/analyze_all.sh and scripts/test_all.sh that run flutter analyze/test across every app and report a summary - Add scripts/repo_doctor.sh that flags config drift (sdk constraint, analysis_options, pubspec name, applicationId, gradle version, docs, tracked generated files) and exits non-zero for use as a pre-commit gate - Wire these into the Makefile as 'make analyze/test/doctor' and document them in MAINTENANCE.md - Bring bmi_calculator and push_notifications gradle wrappers up to the repo-standard 9.7.0; note push_notifications as a Firebase app requiring google-services.json
This commit is contained in:
49
scripts/analyze_all.sh
Executable file
49
scripts/analyze_all.sh
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Runs `flutter analyze` in every example app and reports the results.
|
||||
# Exits non-zero if any app has analyzer issues.
|
||||
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
|
||||
|
||||
clean=0
|
||||
issues=0
|
||||
failed=0
|
||||
apps_with_issues=()
|
||||
|
||||
analyze_app() {
|
||||
local dir="$1"
|
||||
local app
|
||||
app=$(basename "$dir")
|
||||
|
||||
local out
|
||||
if ! out=$(cd "$dir" && flutter analyze 2>&1); then
|
||||
failed=$((failed + 1))
|
||||
return
|
||||
fi
|
||||
|
||||
local summary
|
||||
summary=$(echo "$out" | tail -1)
|
||||
if echo "$out" | grep -q "No issues found"; then
|
||||
clean=$((clean + 1))
|
||||
else
|
||||
issues=$((issues + 1))
|
||||
apps_with_issues+=("$app")
|
||||
printf " %-30s %s\n" "$app" "$summary"
|
||||
fi
|
||||
}
|
||||
|
||||
separator
|
||||
echo " Running flutter analyze for all Flutter apps:"
|
||||
for_each_app pubspec.yaml analyze_app
|
||||
separator
|
||||
printf " %-16s %s\n" "Clean:" "$clean"
|
||||
printf " %-16s %s\n" "With issues:" "$issues"
|
||||
printf " %-16s %s\n" "Failed to run:" "$failed"
|
||||
if [ "${#apps_with_issues[@]}" -gt 0 ]; then
|
||||
echo " Apps with issues:"
|
||||
printf " %s\n" "${apps_with_issues[@]}"
|
||||
fi
|
||||
separator
|
||||
|
||||
[ "$issues" -eq 0 ] && [ "$failed" -eq 0 ]
|
||||
104
scripts/repo_doctor.sh
Executable file
104
scripts/repo_doctor.sh
Executable file
@@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
|
||||
# Reports repository drift across all example apps.
|
||||
# Run after adding or modifying an app, or before a release.
|
||||
# Exits non-zero if any issues are found.
|
||||
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
|
||||
|
||||
STD_SDK='sdk: ">=3.0.0 <4.0.0"'
|
||||
GRADLE_MODE="9.7.0"
|
||||
|
||||
issues=0
|
||||
|
||||
report() {
|
||||
local label="$1"
|
||||
shift
|
||||
if [ "$#" -eq 0 ]; then
|
||||
return
|
||||
fi
|
||||
issues=1
|
||||
echo ""
|
||||
echo " $label:"
|
||||
for item in "$@"; do
|
||||
printf " %s\n" "$item"
|
||||
done
|
||||
}
|
||||
|
||||
collect() {
|
||||
local label="$1"
|
||||
shift
|
||||
local found=()
|
||||
for app in ./*; do
|
||||
if [ -f "$app/pubspec.yaml" ]; then
|
||||
local name
|
||||
name=$(basename "$app")
|
||||
"$@" "$app" "$name" && found+=("$name")
|
||||
fi
|
||||
done
|
||||
report "$label" "${found[@]}"
|
||||
}
|
||||
|
||||
check_sdk() {
|
||||
local app="$1" name="$2"
|
||||
! grep -qF "$STD_SDK" "$app/pubspec.yaml"
|
||||
}
|
||||
|
||||
check_lints() {
|
||||
local app="$1" name="$2"
|
||||
[ ! -f "$app/analysis_options.yaml" ] || ! grep -q "flutter_lints" "$app/pubspec.yaml"
|
||||
}
|
||||
|
||||
check_name() {
|
||||
local app="$1" name="$2"
|
||||
[ "$(grep -m1 '^name:' "$app/pubspec.yaml" | awk '{print $2}')" != "$name" ]
|
||||
}
|
||||
|
||||
check_android_id() {
|
||||
local app="$1" name="$2"
|
||||
local f="$app/android/app/build.gradle.kts"
|
||||
[ ! -f "$f" ] && return 1
|
||||
! grep -q 'namespace = "github\.nisrulz\.' "$f"
|
||||
}
|
||||
|
||||
check_gradle() {
|
||||
local app="$1" name="$2"
|
||||
local props="$app/android/gradle/wrapper/gradle-wrapper.properties"
|
||||
[ ! -f "$props" ] && return 1
|
||||
! grep -q "$GRADLE_MODE" "$props"
|
||||
}
|
||||
|
||||
check_docs() {
|
||||
local app="$1" name="$2"
|
||||
! grep -q "(/$name)" documentation/EXAMPLES.md
|
||||
}
|
||||
|
||||
separator
|
||||
echo " Repository doctor:"
|
||||
echo " Checking all apps for configuration drift."
|
||||
|
||||
collect "Apps with a non-standard SDK constraint" check_sdk
|
||||
collect "Apps missing analysis_options.yaml or flutter_lints" check_lints
|
||||
collect "Apps whose pubspec name does not match the folder" check_name
|
||||
collect "Apps not using the github.nisrulz.* Android applicationId" check_android_id
|
||||
collect "Apps not on the standard Gradle version" check_gradle
|
||||
collect "Apps missing from documentation/EXAMPLES.md (run 'make docs')" check_docs
|
||||
|
||||
# Tracked generated files that should not be in git.
|
||||
tracked_generated=$(git ls-files | grep -E "\.dart_tool/|GeneratedPluginRegistrant|\.flutter-plugins-dependencies|pubspec\.lock" || true)
|
||||
if [ -n "$tracked_generated" ]; then
|
||||
issues=1
|
||||
echo ""
|
||||
echo " Tracked generated files (remove with 'git rm --cached'):"
|
||||
echo "$tracked_generated" | sed 's/^/ /'
|
||||
fi
|
||||
|
||||
separator
|
||||
if [ "$issues" -eq 0 ]; then
|
||||
echo " All checks passed."
|
||||
else
|
||||
echo " Issues found. Fix them before committing."
|
||||
exit 1
|
||||
fi
|
||||
separator
|
||||
45
scripts/test_all.sh
Executable file
45
scripts/test_all.sh
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Runs `flutter test` in every example app that has a test directory.
|
||||
# Exits non-zero if any test run fails.
|
||||
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
|
||||
|
||||
passed=0
|
||||
failed=0
|
||||
skipped=0
|
||||
failed_apps=()
|
||||
|
||||
run_tests() {
|
||||
local dir="$1"
|
||||
local app
|
||||
app=$(basename "$dir")
|
||||
|
||||
if [ ! -d "$dir/test" ]; then
|
||||
skipped=$((skipped + 1))
|
||||
return
|
||||
fi
|
||||
|
||||
if (cd "$dir" && flutter test >/dev/null 2>&1); then
|
||||
passed=$((passed + 1))
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
failed_apps+=("$app")
|
||||
fi
|
||||
}
|
||||
|
||||
separator
|
||||
echo " Running flutter test for all Flutter apps:"
|
||||
for_each_app pubspec.yaml run_tests
|
||||
separator
|
||||
printf " %-16s %s\n" "Passed:" "$passed"
|
||||
printf " %-16s %s\n" "Failed:" "$failed"
|
||||
printf " %-16s %s\n" "No tests:" "$skipped"
|
||||
if [ "${#failed_apps[@]}" -gt 0 ]; then
|
||||
echo " Failed apps:"
|
||||
printf " %s\n" "${failed_apps[@]}"
|
||||
fi
|
||||
separator
|
||||
|
||||
[ "$failed" -eq 0 ]
|
||||
Reference in New Issue
Block a user