Skip to content

Analyze and test with both lowest and highest supported Flutter SDK versions in CI #297

Analyze and test with both lowest and highest supported Flutter SDK versions in CI

Analyze and test with both lowest and highest supported Flutter SDK versions in CI #297

Workflow file for this run

name: Code Check
on:
push:
branches: main
pull_request:
env:
FLUTTER_TEST_REPORT: ${{github.workspace}}/flutter-test-report.json
PATTERN_CHECKER: ${{github.workspace}}/scripts/pattern_checker.sh
jobs:
setup:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
flutter-file-changed: ${{ steps.filter.outputs.flutter-file-changed }}
lowest-flutter-version: ${{ steps.flutter-version-constraint.outputs.lowest }}
highest-flutter-version: ${{ steps.flutter-version-constraint.outputs.highest }}
steps:
- uses: actions/checkout@v4
- name: Filter changed files
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
flutter-file-changed:
- '**.dart'
- 'pubspec.yaml'
- 'pubspec.lock'
- name: Get Flutter SDK version constraint
id: flutter-version-constraint
run: |
sdk_constraint=$(cat pubspec.yaml | yq .environment.flutter)
lowest=$(echo "$sdk_constraint" | grep -oP '(?<=\>=)[0-9]+\.[0-9]+\.[0-9]+' | head -1)
highest=$(echo "$sdk_constraint" | grep -oP '(?<=\<)[0-9]+\.[0-9]+\.[0-9]+' | head -1)
# If no upper bound is specified, default to 3.x
if [ -z "$highest" ]; then
highest="3.x"
fi
echo "lowest=$lowest" >> "$GITHUB_OUTPUT"
echo "highest=$highest" >> "$GITHUB_OUTPUT"
- name: Print output values
run: |
echo "flutter-file-changed=${{ steps.filter.outputs.flutter-file-changed }}"
echo "lowest-flutter-version=${{ steps.flutter-version-constraint.outputs.lowest }}"
echo "highest-flutter-version=${{ steps.flutter-version-constraint.outputs.highest }}"
analysis:
needs: setup
if: ${{ needs.setup.outputs.flutter-file-changed == 'true' }}
runs-on: ubuntu-latest
strategy:
matrix:
flutter-version:
- ${{ needs.setup.outputs.lowest-flutter-version }}
- ${{ needs.setup.outputs.highest-flutter-version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Flutter
uses: ./.github/actions/setup_flutter
with:
version: ${{ matrix.flutter-version }}
- name: Format
run: dart format . -o none --set-exit-if-changed
- name: Analyze
run: dart analyze
- name: Disallowed patterns check
run: bash ${{ env.PATTERN_CHECKER }} "*.dart" "--" "debugPrint"
testing:
needs: setup
if: ${{ needs.setup.outputs.flutter-file-changed == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
checks: write
strategy:
matrix:
flutter-version:
- ${{ needs.setup.outputs.lowest-flutter-version }}
- ${{ needs.setup.outputs.highest-flutter-version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Flutter
uses: ./.github/actions/setup_flutter
with:
version: ${{ matrix.flutter-version }}
- name: Run unit tests
run: flutter test --file-reporter="json:${{ env.FLUTTER_TEST_REPORT }}"
- name: Write test report
uses: dorny/test-reporter@v1
# PRs from forks have no write permissions.
if: github.event.pull_request.head.repo.fork == false && (success() || failure())
with:
name: Test Report (with Flutter ${{ matrix.flutter-version }})
path: ${{ env.FLUTTER_TEST_REPORT }}
reporter: flutter-json
# Final results (Used for status checks)
code-check:
if: ${{ always() }}
runs-on: ubuntu-latest
needs: [analysis, testing]
steps:
# Fails if any of the previous jobs failed.
- run: exit 1
if: >-
${{
contains(needs.*.result, 'failure')
|| contains(needs.*.result, 'cancelled')
}}