diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 87ac6e7f0..389009b7e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -76,6 +76,42 @@ jobs: run: bash prebuild.sh working-directory: scripts + - name: Verify committed generated files are up to date + run: | + # build_runner always replaces conflicting outputs, which can take + # the gitignored app config too (source_gen claims .dart -> + # .g.dart for every input), and ensure_test_app_config.sh's stub + # is not the configured app, so put the configured file back and + # leave the script as the fallback. + SAVED_APP_CONFIG="${RUNNER_TEMP:-/tmp}/app_config.g.dart.saved" + cp lib/app_config.g.dart "$SAVED_APP_CONFIG" + dart run build_runner build + cp "$SAVED_APP_CONFIG" lib/app_config.g.dart + bash scripts/ensure_test_app_config.sh + # hive_ce emits a registrar nothing here imports; never delete it if + # someone has committed it. + if [ -f lib/hive_registrar.g.dart ] \ + && ! git ls-files --error-unmatch lib/hive_registrar.g.dart >/dev/null 2>&1; then + rm -f lib/hive_registrar.g.dart + fi + # Committed generated files are kept dart format clean (the format + # step above checks them like any other changed file), but the + # generators format with their own dart_style, so compare formatted + # output. + git ls-files -m -o --exclude-standard -- '*.mocks.dart' '*.g.dart' \ + | while read -r f; do if [ -f "$f" ]; then echo "$f"; fi; done \ + | sort -u | xargs -r dart format + + # build.yaml never runs build_runner, so releases are compiled from + # the committed *.g.dart; stale isar/drift output has to fail the job + # here or nothing checks it at all. + GENERATED_STATUS=$(git status --porcelain -- '*.mocks.dart' '*.g.dart') + if [ -n "$GENERATED_STATUS" ]; then + echo "$GENERATED_STATUS" + echo "::error::Committed generated files differ from build_runner output; re-run scripts/dev/build_runner.sh, dart format the changed files and commit the result." + exit 1 + fi + # - name: Analyze # run: flutter analyze - name: Test