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

Easily infer Flutter version from `pubspec.yaml` to avoid duplication #244

Closed bartekpacia closed 8 months ago

bartekpacia commented 9 months ago

The actions/setup-go action provides a way to use the version from the go.mod file (equivalent of pubspec.yaml):

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

I'd like this action to be able to do the same:

- name: Set up Flutter
  uses: subosito/flutter-action@v2
  with:
    channel: stable
    flutter-version-file: pubspec.yaml
    architecture: x64

pubspec.yaml also allows version constraints (see discussion #215). To avoid complexity it brings, using flutter-version-file would require the Flutter version constraint to be a single version, for example:

# pubspec.yaml
environment:
  sdk: '>=3.1.0 <4.0.0'
  flutter: '3.13.0' # no constraint allowed here

The version can be easily retrieved using yq:

yq '.environment.flutter' pubspec.yaml
braniii commented 8 months ago

Until this feature is added, it can be achieved with GITHUB_ENV, e.g., if the pubspec.yaml contains

  flutter: ">=3.13.7"

The version can be extracted with:

    steps:
      - name: ⬇️ Checkout repository
        uses: actions/checkout@v3
      - name: Set Flutter version
        run: |
          export FLUTTER_VERSION="$(sed -E -n -e 's/^.*flutter:\ ">=([0-9.]+)"/\1/p' pubspec.yaml)"
          echo "FLUTTER_VERSION=$FLUTTER_VERSION" >> $GITHUB_ENV
      - name: ⚙️ Setup Flutter
        uses: subosito/flutter-action@v2
        with:
          flutter-version: "${{ env.FLUTTER_VERSION }}"
          channel: 'stable'
          cache: true
        id: flutter

For an example you can check my gh-action.yml

subosito commented 8 months ago

Until we have a standard definition in pubspec.yaml for flutter version, please use the yq and/or shell script, as @braniii mentioned.