diff --git a/.github/workflows/dart_packages_test.yml b/.github/workflows/dart_packages_test.yml new file mode 100644 index 0000000000..6cf6529eed --- /dev/null +++ b/.github/workflows/dart_packages_test.yml @@ -0,0 +1,100 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Analyzes, formats and tests the pure Dart packages under dart/. +# +# The Flutter workflow builds its matrix from samples/, so the packages that +# ship to pub.dev were not covered by any job. This workflow holds them to the +# same bar the samples are held to: formatting, analysis with --fatal-infos, +# and the package's own tests. +name: Dart CI + +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name || github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.generate_matrix.outputs.matrix }} + steps: + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + with: + persist-credentials: false + + - name: Generate testing matrix + id: generate_matrix + run: | + DIRS_TO_TEST=$(find dart -name pubspec.yaml -not -path "*/.dart_tool/*" -exec dirname {} \;) + + JSON_MATRIX="[" + FIRST=true + for dir in $DIRS_TO_TEST; do + if [ "$FIRST" = false ]; then + JSON_MATRIX="$JSON_MATRIX," + fi + FIRST=false + package_name=$(echo "$dir" | tr '/' '_') + JSON_MATRIX="$JSON_MATRIX{\"name\":\"$package_name\",\"path\":\"$dir\"}" + done + JSON_MATRIX="$JSON_MATRIX]" + + echo "matrix=$JSON_MATRIX" >> $GITHUB_OUTPUT + + analyze_and_test: + needs: matrix + name: ${{ matrix.package.name }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + package: ${{ fromJson(needs.matrix.outputs.matrix) }} + steps: + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + with: + persist-credentials: false + + # The packages resolve through the monorepo workspace, whose root pubspec + # declares a Flutter SDK constraint, so a Dart-only SDK cannot resolve + # them. See https://github.com/a2ui-project/a2ui/issues/2463. + - uses: ./.github/actions/setup-dart + + - name: Install dependencies + working-directory: ${{ matrix.package.path }} + run: dart pub get + + - name: Check formatting + working-directory: ${{ matrix.package.path }} + run: dart format --output=none --set-exit-if-changed . + + - name: Analyze code + working-directory: ${{ matrix.package.path }} + run: dart analyze --fatal-infos + + - name: Run tests + working-directory: ${{ matrix.package.path }} + run: dart test diff --git a/dart/a2ui_core/test/conformance/message_processor_conformance_test.dart b/dart/a2ui_core/test/conformance/message_processor_conformance_test.dart index 7ba11b9a51..7694ea9d72 100644 --- a/dart/a2ui_core/test/conformance/message_processor_conformance_test.dart +++ b/dart/a2ui_core/test/conformance/message_processor_conformance_test.dart @@ -157,9 +157,11 @@ void _checkComponents( List> expected, String reason, ) { - expect(surface.componentsModel.all.map((c) => c.id).toSet(), { - for (final Map entry in expected) entry['id'], - }, reason: '$reason: component ids'); + expect( + surface.componentsModel.all.map((c) => c.id).toSet(), + {for (final Map entry in expected) entry['id']}, + reason: '$reason: component ids', + ); for (final entry in expected) { final id = entry['id']! as String; diff --git a/dart/a2ui_core/test/validator_test.dart b/dart/a2ui_core/test/validator_test.dart index 2efb3849f8..b30a4a7502 100644 --- a/dart/a2ui_core/test/validator_test.dart +++ b/dart/a2ui_core/test/validator_test.dart @@ -509,9 +509,11 @@ void main() { }, }); - expect(extractComponentRefFields(inlined)['Card']!.single, { - 'child', - }, reason: 'id must not be read as a child reference'); + expect( + extractComponentRefFields(inlined)['Card']!.single, + {'child'}, + reason: 'id must not be read as a child reference', + ); final A2uiValidator validator = A2uiValidator( catalogs: [inlined],