subosito/flutter-action

repository·main·Indexed 25 days ago

https://github.com/subosito/flutter-action

A GitHub Action to set up the Flutter environment on Linux, Windows, and macOS runners. It supports specifying Flutter versions and channels (stable, beta, master, main), loading versions from pubspec.yaml or FVM config, using wildcard version patterns, and configuring alternative git sources or mirrors. The action includes integrated caching for the Flutter SDK and pub dependencies, and provides outputs to conditionally skip steps based on pub cache hits.

Tokens
2.2K
Snippets
12
Records
12
Agent score
33%

What's inside flutter-action

  1. Use Flutter version from pubspec.yaml or FVM config

    main

    Set the Flutter version automatically by pointing to a configuration file like pubspec.yaml, .fvmrc, or .fvm/fvm_config.json using the flutter-version-file input.

    Requirement: For pubspec.yaml, the version must be an exact match in the environment.flutter field (e.g., 3.19.0), not a range (e.g., ">= 3.19.0 <4.0.0").

    Note: This feature requires yq, which the action installs automatically if needed.

    steps:
      - name: Clone repository
        uses: actions/checkout@v6
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable
          flutter-version-file: pubspec.yaml
      - run: flutter --version
  2. Use an alternative Flutter repository

    main

    You can use alternative Flutter repositories (forks) by providing the git-source input.

    steps:
      - name: Clone repository
        uses: actions/checkout@v6
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: master
          flutter-version: 3.24.0
          git-source: https://github.com/join-the-flock/flock.git
      - run: flutter --version
  3. Use a particular version on any channel

    main

    To target a specific version regardless of the channel, set channel: any and provide the flutter-version (e.g., 3.x).

    steps:
      - name: Clone repository
        uses: actions/checkout@v6
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: any
          flutter-version: 3.x
      - run: flutter --version
  4. Use latest release for a channel

    main

    To use the latest available release for a specific channel, omit the flutter-version input.

    steps:
      - name: Clone repository
        uses: actions/checkout@v6
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable # or: beta, master (or: main)
      - run: flutter --version
  5. Use a git reference on the master channel

    main

    When using the master channel, you can specify a particular git tag, commit hash, or branch name as the flutter-version.

    steps:
      - name: Clone repository
        uses: actions/checkout@v6
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: master
          flutter-version: 5b12b74
      - run: flutter --version
  6. Specify Flutter version and channel

    main

    You can configure the Flutter environment by specifying a specific version and a release channel (e.g., stable, beta, master, or main).

    steps:
      - name: Clone repository
        uses: actions/checkout@v6
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable
          flutter-version: 3.19.0
      - run: flutter --version
  7. Use latest release for a specific version pattern and channel

    main

    You can use wildcard patterns (e.g., 1.22.x) to target the latest release within a specific version range on a given channel.

    steps:
      - name: Clone repository
        uses: actions/checkout@v6
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: dev
          flutter-version: 1.22.x
      - run: flutter --version
  8. Configure a Flutter mirror via environment variable

    main

    To use a Flutter mirror (useful for users in certain regions), set the FLUTTER_STORAGE_BASE_URL environment variable in the step.

    steps:
      - name: Clone repository
        uses: actions/checkout@v6
      - name: Set up Flutter
        env:
          FLUTTER_STORAGE_BASE_URL: https://storage.flutter-io.cn
        uses: subosito/flutter-action@v2
        with:
          channel: master
          flutter-version: 5b12b74
      - run: flutter --version
  9. Apply a patch to the Flutter SDK

    main

    To apply a custom patch to the Flutter SDK, use the ${{ env.FLUTTER_ROOT }} environment variable to locate the SDK directory and apply the patch using git apply.

    steps:
    - name: Clone repository
      uses: actions/checkout@v6
    - uses: subosito/flutter-action@v2
      with:
        flutter-version: 3.22.2
        channel: stable
    - run: |
        flutter --version
        cd ${{ env.FLUTTER_ROOT }}
        curl https://patch-diff.githubusercontent.com/raw/flutter/flutter/pull/137874.patch | git apply
        git status
  10. Configure caching for Flutter SDK and pub dependencies

    main

    The action integrates with actions/cache@v5 to speed up workflows.

    • cache: Controls whether to cache the Flutter SDK installation. Defaults to false if not specified.
    • pub-cache: Controls whether to cache pub dependencies. If not specified, it defaults to the value of cache (backward compatibility).

    Dynamic values for keys and paths: :os:, :channel:, :version:, :arch:, :hash:, :sha256:

    steps:
      - name: Clone repository
        uses: actions/checkout@v6
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable
          cache: true
          pub-cache: true
          cache-key: "flutter-:os:-:channel:-:version:-:arch:-:hash:"
          cache-path: "${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:"
          pub-cache-key: "flutter-pub-:os:-:channel:-:version:-:arch:-:hash:"
          pub-cache-path: "${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:"
      - run: flutter --version
  11. Skip steps based on pub cache hit

    main

    You can use the PUB-CACHE-HIT output to conditionally skip expensive steps like melos bootstrap if the dependencies are already cached.

    steps:
      - name: Checkout repository
        uses: actions/checkout@v6
    
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        id: flutter-action
        with:
          channel: stable
          cache: true
    
      - name: Conditionally run melos bootstrap
        if: steps.flutter-action.outputs.PUB-CACHE-HIT != 'true'
        run: melos bootstrap
    
      - name: Continue with build
        run: flutter build apk
  12. Access Flutter action outputs

    main

    The action provides several outputs that can be accessed in subsequent steps. You can also use dry-run: true to retrieve these outputs without installing the Flutter SDK.

    # Available outputs:
    CACHE-PATH
    CACHE-KEY
    CHANNEL
    VERSION
    ARCHITECTURE
    PUB-CACHE-PATH
    PUB-CACHE-KEY
    CACHE-HIT
    PUB-CACHE-HIT