subosito / flutter-action

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

Allow to automatically run `flutter precache` #256

Closed bartekpacia closed 6 months ago

bartekpacia commented 10 months ago

I often have the following code in my workflows

- name: Set up Flutter
  uses: subosito/flutter-action@v2
  with:
    flutter-version: ${{ matrix.flutter-version }}
    channel: ${{ matrix.flutter-channel }}

- name: Preload Flutter artifacts
  run: flutter precache

I wish I could so something like:

- name: Set up Flutter
  uses: subosito/flutter-action@v2
  with:
    flutter-version: ${{ matrix.flutter-version }}
    channel: ${{ matrix.flutter-channel }}
    precache: true

Possibly it should also allow for more granular selection of artifacts to precache, e.g. flutter precache --android --ios would translate to:

- name: Set up Flutter
  uses: subosito/flutter-action@v2
  with:
    flutter-version: ${{ matrix.flutter-version }}
    channel: ${{ matrix.flutter-channel }}
    precache: ['android', 'ios']
subosito commented 7 months ago

I like this idea @bartekpacia, I would be happy to merge the PR.

bartekpacia commented 7 months ago

awesome, I'll start on it :)

bartekpacia commented 7 months ago

GitHub Actions doesn't support passing arrays to actions. For example, I would want to have this API:

- name: Set up Flutter
  uses: subosito/flutter-action@v2
  with:
    channel: stable
    flutter-version: '3.19.0'
    precache: [android, ios]

but it doesn't work:

Screenshot 2024-03-02 at 04 36 11

Only strings, integers, or booleans can be passed, so that's how actually the API would look like:

- name: Set up Flutter
  uses: subosito/flutter-action@v2
  with:
    channel: stable
    flutter-version: '3.19.0'
    precache: '[android, ios]'

I think it's pretty ugly. So right now I'm leaning toward making precache a boolean.

- name: Set up Flutter
  uses: subosito/flutter-action@v2
  with:
    channel: stable
    flutter-version: '3.19.0'
    precache: true

Someone can contribute the more complex version later, and meanwhile they can continue with calling flutter precache manually.

yurikoles commented 7 months ago

What about nested booleans?

precache:
  ios: true
  android: false
bartekpacia commented 7 months ago

That's some solution, thanks! However it results in quite "tall" code.

bartekpacia commented 6 months ago

I think this would be cool:

Precache artifacts for all currently enabled platforms:

precache: true

OR

precache artifacts for specific platforms:

precache:
  ios: true
  android: false

Both syntaxes would be correct. I'm not sure if GitHub Actions supports this though (mixed type: value vs list of values).

@yurikoles what do you think?

yurikoles commented 6 months ago

This feature is mostly for GitHub-hosted runners only. Self-hosted runners retain their state, so precaching seems less important for them. Cheaper Linux runners are preferred due to higher billing multipliers for macOS and Windows runners. Most users require only iOS support on macOS runners. Therefore, I propose to implement one boolean, which will run flutter precache with no options on Linux, flutter precache --windows on Windows, and flutter precache --ios on macOS.

bartekpacia commented 6 months ago

see https://github.com/subosito/flutter-action/pull/276#issuecomment-2028826138