subosito / flutter-action

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

Automatically get Flutter version from `pubspec.yaml` #282

Closed bartekpacia closed 8 months ago

bartekpacia commented 8 months ago

Use case

I like to define my Flutter version like this in pubspec.yaml:

name: awesome_flutter_app
description: Some random cross-platform app.
version: 1.0.0+1
publish_to: none

environment:
  sdk: ">=3.3.2 <4.0.0"
  flutter: 3.19.4

dependencies:
  # ...

This is useful and I really like it because it's very easy to retrieve the version with yq:

$ yq '.environment.flutter' pubspec.yaml
3.19.4

It avoids ambiguity and makes sure both developers and CI use the same Flutter version when building. Right now this is how I accomplish this in my workflows:

jobs:
  main:
    # ...

    steps:
      # ...

      - name: Get Flutter version
        id: get_flutter_version
        run: |
          brew install yq
          echo "result=$(yq '.environment.flutter' pubspec.yaml)" >> $GITHUB_OUTPUT

      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable
          flutter-version: ${{ steps.get_flutter_version.outputs.result }}

Proposal

It'd be great if we could do this instead:

jobs:
  main:
    # ...

    steps:
      # ...

      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable
          flutter-version-file: pubspec.yaml # path to the pubspec.yaml file

Of course, it would only work if yq '.environment.flutter' pubspec.yaml returns a valid semver version, and not something like flutter: ">=3.19.4". People who prefer things the way they are currently would not have to do anything at all, and continue using this action without any breaking changes.

This would be shorter

Both ubuntu-* and macos-* GitHub runners come with yq already installed (just like they come with jq already installed), so this small additional dependency shouldn't be blocker.

More context

yurikoles commented 8 months ago

And the principal difference between this issue and #211 with #215 is?

bartekpacia commented 8 months ago

The differences: