Flutter CI, except 'e2e_test' #644
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyright 2025 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 | |
| # | |
| # http://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. | |
| name: Flutter CI, except 'e2e_test' | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: "0 * * * *" # hourly | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| jobs: | |
| matrix: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.generate_matrix.outputs.matrix }} | |
| flutter_version: ${{ steps.generate_matrix.outputs.flutter_version }} | |
| steps: | |
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 | |
| with: | |
| persist-credentials: false | |
| - name: Generate testing matrix | |
| id: generate_matrix | |
| run: | | |
| DIRS_TO_TEST=$(find samples -name pubspec.yaml -not -path "*/.dart_tool/*" -not -path "*/e2e_test/*" -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 '/' '_') | |
| package_path="$dir" | |
| JSON_MATRIX="$JSON_MATRIX{\"name\":\"$package_name\",\"path\":\"$package_path\"}" | |
| done | |
| JSON_MATRIX="$JSON_MATRIX]" | |
| echo "matrix=$JSON_MATRIX" >> $GITHUB_OUTPUT | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| echo 'flutter_version=["stable"]' >> $GITHUB_OUTPUT | |
| else | |
| echo 'flutter_version=["beta", "stable"]' >> $GITHUB_OUTPUT | |
| fi | |
| cycle-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 | |
| with: | |
| persist-credentials: false | |
| - uses: ./.github/actions/setup-dart | |
| - name: Check for cycles across packages | |
| run: | | |
| dart pub global activate layerlens | |
| DIRS=$(find samples -name pubspec.yaml -not -path "*/.dart_tool/*" -not -path "*/e2e_test/*" -exec dirname {} \;) | |
| for dir in $DIRS; do | |
| echo "Checking cycles in $dir..." | |
| (cd "$dir" && dart pub get && layerlens --fail-on-cycles --except "lib/src/schema" --except "lib/src/core") | |
| done | |
| analyze_and_test: | |
| needs: matrix | |
| name: ${{ matrix.package.name }} (${{ matrix.flutter_version }}) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| package: ${{ fromJson(needs.matrix.outputs.matrix) }} | |
| flutter_version: ${{ fromJson(needs.matrix.outputs.flutter_version) }} | |
| os: [ubuntu-latest] | |
| steps: | |
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 | |
| with: | |
| persist-credentials: false | |
| - uses: ./.github/actions/setup-dart | |
| with: | |
| channel: ${{ matrix.flutter_version }} | |
| - name: Print Flutter version | |
| run: flutter --version | |
| - name: Update submodules | |
| working-directory: ${{ matrix.package.path }} | |
| run: git submodule update --init --recursive | |
| - 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: flutter analyze --fatal-infos | |
| - name: Run tests | |
| working-directory: ${{ matrix.package.path }} | |
| run: | | |
| if [ -d "test" ]; then | |
| flutter test --test-randomize-ordering-seed=random | |
| else | |
| echo "No 'test' directory found in ${{ matrix.package.path }}, skipping tests." | |
| fi |