Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
heart

GitHub Action

hrk-setup-flutter

v1.2.0

hrk-setup-flutter

heart

hrk-setup-flutter

Composite GitHub Action to setup and cache the Flutter SDK

Installation

Copy and paste the following snippet into your .yml file.

              

- name: hrk-setup-flutter

uses: hrishikesh-kadam/setup-flutter@v1.2.0

Learn more about this action in hrishikesh-kadam/setup-flutter

Choose a version

setup-flutter

CI

Composite GitHub Action to setup and cache the Flutter SDK.

This action is intended for the Hosted Runners.
It does the following:

  • Checks the SHA of the requested input ref (defaults to stable) from the GitHub flutter repo and stores in $FLUTTER_REF_HEAD.
  • Checks for the cache entry with key flutter-${{ runner.os }}-${{ inputs.ref }}-${{ env.FLUTTER_REF_HEAD }}.
  • If the cache hit is true then it restores in the $RUNNER_TOOL_CACHE/flutter folder.
  • If the cache hit is false then it downloads the Flutter from the GitHub repo to $RUNNER_TOOL_CACHE/flutter folder.
  • Adds $RUNNER_TOOL_CACHE/flutter/bin folder to the $GITHUB_PATH.
  • Runs flutter --version.
  • If the cache hit was false then post job success, it caches $RUNNER_TOOL_CACHE/flutter folder using the key flutter-${{ runner.os }}-${{ inputs.ref }}-${{ env.FLUTTER_REF_HEAD }}.

Caching Flutter will help to save some minutes.
Private repositories with Free plan has only 2,000 automation minutes/month.
And the minutes are counted as -
Linux - 1 minute counted as 1 regular minute.
Windows - 1 minute counted as 2 regular minutes.
macOS - 1 minute counted as 10 regular minutes.
Usage for the month can be seen in https://github.com/settings/billing

Stats from workflow runs of before and after caching -

Step Job Time
Setup Flutter (Before caching) test-setup-flutter (ubuntu-latest) 48s
test-setup-flutter (windows-latest) 1m 54s
test-setup-flutter (macos-latest) 1m 2s
Setup Flutter (After caching) test-setup-flutter (ubuntu-latest) 9s
test-setup-flutter (windows-latest) 32s
test-setup-flutter (macos-latest) 13s

Note that GitHub will remove any cache entries that have not been accessed in over 7 days.

Usage

Basic -

steps:
  - uses: actions/checkout@v2
  - name: Setup Flutter
    uses: hrishikesh-kadam/setup-flutter@v1
  - run: # Run your flutter or dart command here

ref:
    description: 'channel (stable, beta or master), version(2.8.1) or any git reference(2.9.0-0.1.pre).'
    required: false
    default: 'stable'

steps:
  - uses: actions/checkout@v2
  - name: Setup Flutter
    uses: hrishikesh-kadam/setup-flutter@v1
    with:
      ref: beta # or 2.8.1 or 2.9.0-0.1.pre,

setFlutterRootPath:
    description: 'Set FLUTTER_ROOT to path where Flutter is installed.'
    required: false
    default: 'false'

steps:
  - uses: actions/checkout@v2
  - name: Setup Flutter
    uses: hrishikesh-kadam/setup-flutter@v1
    with:
      setFlutterRootPath: 'true'

setPubCachePath:
    description: 'Set PUB_CACHE to desired path, where pub saves dependencies.'
    required: false
    default: ''

my-job:
  runs-on: ${{ matrix.runner }}
  strategy:
    fail-fast: false
    matrix:
      runner: [ ubuntu-latest, macos-latest ]
      pubCachePath: [ '$HOME/.pub-cache' ]
      include:
        - runner: windows-latest
          pubCachePath: '$LOCALAPPDATA\Pub\Cache'
  steps:
    - uses: actions/checkout@v2
    - name: Setup Flutter
      uses: hrishikesh-kadam/setup-flutter@v1
      with:
        setPubCachePath: ${{ matrix.pubCachePath }}

addPubCacheBinToPath:
    description: 'Add PUB_CACHE bin to PATH.
        Note: On Windows, activated global packages can be run by without specifying
        dart pub global run only on pwsh, cmd and powershell.'
    required: false
    default: 'false'

steps:
  - uses: actions/checkout@v2
  - name: Setup Flutter
    uses: hrishikesh-kadam/setup-flutter@v1
    with:
      addPubCacheBinToPath: 'true'
  - run: |
      dart pub global activate devtools
      devtools --help