subosito / flutter-action

Flutter environment for use in GitHub Actions. It works on Linux, Windows, and macOS.
MIT License
2.16k stars 193 forks source link

Infer Flutter version from `pubspec.yaml` #211

Closed bartekpacia closed 1 year ago

bartekpacia commented 1 year ago

I find it a bit annoying that whenever I update Flutter, I have to change the version in pubspec.yaml and in my GitHub Actions workflows.

I think it'd be great if this action would infer Flutter version from pubspec.yaml:

- name: Set up Flutter
  uses: subosito/flutter-action@v2
  with:
    # channel: stable  # not needed - stable would be used by default
    # flutter-version: '3.7.0' # not needed - would be inferred `pubspec.yaml`
    architecture: x64
    cache: true

This approach is used in, for example, the actions/setup-go:

- uses: actions/setup-go@v4
  with:
    go-version-file: go.mod

Of course, it'd still be possible to explicitly specify the Flutter version to use.

kuhnroyal commented 1 year ago

Which version would you infer from >= 3.5.0 <4.0.0? I suggest you look at https://github.com/fluttertools/fvm and https://github.com/kuhnroyal/flutter-fvm-config-action if you want to manage the version in one place.

bartekpacia commented 1 year ago

@kuhnroyal Thanks for showing https://github.com/kuhnroyal/flutter-fvm-config-action – looks nice and like something that is a way to solve this problem.

Which version would you infer from >= 3.5.0 <4.0.0?

The minimum one. It's a good practice to keep the lower bound of flutter version constraint the same as the Flutter version you use. Try to set an upper bound on flutter in a package's pubspec.yaml and after running flutter pub publish --dry-run you'll see:

Package validation found the following potential issue:
* The Flutter constraint should not have an upper bound.
  In your pubspec.yaml the constraint is currently `>=3.3.0 <4.0.0`.

  You can replace that with just the lower bound: `>=3.3.0`.

  See https://dart.dev/go/flutter-upper-bound-deprecation

So for using current stable version of Flutter, it'd be:

environment:
  sdk: '>=2.19.4 <4.0.0'
  flutter: '>=3.7.7'

At work, when we upgrade a project to a newer Flutter version, we also update lower bound of flutter in pubspec.yaml, and I think it's a good practice.