Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,28 @@ steps:
run: flutter build apk
```

### Using custom cache actions

If you'd like to use a caching action other than `actions/cache` (the GitHub default), you can provide custom actions like this:

```yaml
- name: Configure Flutter
id: config-flutter
uses: subosito/flutter-action@v2
with:
channel: stable
cache: true
custom-pub-cache-action: my-organization/actions/repository-scoped-cache@main
custom-cache-action: my-organization/actions/global-cache@main
```

Both custom actions must be drop-in replacements for `actions/cache`: they should accept the same inputs and expose the same outputs.

Notes:

- **custom-pub-cache-action** — Recommended to use a repository-scoped cache action (or narrower) as the cache key incorporates a hash of your project's `pubspec.yaml` files. The default `actions/cache` is repository-scoped and also branch-scoped.
- **custom-cache-action** — Recommended to use a global-scoped cache action here to increase hit rates across multiple Flutter repositories that use the same Flutter version.

## Outputs

Use outputs from `flutter-action`:
Expand Down
34 changes: 23 additions & 11 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ inputs:
description: Git clone source
required: false
default: "https://github.com/flutter/flutter.git"
custom-cache-action:
description: Path to a custom caching action that will be executed for flutter cache instead of the default caching mechanism. It must be a drop-in replacement for actions/cache.
required: false
default: ""
custom-pub-cache-action:
description: Path to a custom caching action that will be executed for pub cache instead of the default caching mechanism. It must be a drop-in replacement for actions/cache.
required: false
default: ""

outputs:
CHANNEL:
Expand Down Expand Up @@ -81,10 +89,10 @@ outputs:
value: "${{ steps.flutter-action.outputs.GIT_SOURCE }}"
description: Git source of Flutter SDK repository to clone
CACHE-HIT:
value: "${{ steps.cache-flutter.outputs.cache-hit }}"
value: "${{ fromJSON(steps.cache-flutter.outputs.outputs || '{}').cache-hit }}"
description: "`true` if the flutter cache was a hit"
PUB-CACHE-HIT:
value: "${{ steps.cache-pub.outputs.cache-hit }}"
value: "${{ fromJSON(steps.cache-pub.outputs.outputs || '{}').cache-hit }}"
description: "`true` if the pub cache was a hit"

runs:
Expand Down Expand Up @@ -120,19 +128,23 @@ runs:

- name: Cache Flutter
id: cache-flutter
uses: actions/cache@v5
if: ${{ inputs.cache == 'true' }}
with:
path: ${{ steps.flutter-action.outputs.CACHE-PATH }}
key: ${{ steps.flutter-action.outputs.CACHE-KEY }}
uses: jenseng/dynamic-uses@v1
if: ${{ inputs.cache == 'true' || inputs.custom-cache-action != '' }}
with:
uses: ${{ inputs.custom-cache-action == '' && 'actions/cache@v5' || inputs.custom-cache-action }}
with: |
path: ${{ toJSON(steps.flutter-action.outputs.CACHE-PATH) }}
key: '${{ steps.flutter-action.outputs.CACHE-KEY }}'

- name: Cache pub dependencies
uses: actions/cache@v5
id: cache-pub
if: ${{ (inputs.pub-cache == '' && inputs.cache == 'true') || inputs.pub-cache == 'true' }}
if: ${{ ((inputs.pub-cache == '' && inputs.cache == 'true') || inputs.pub-cache == 'true') || inputs.custom-pub-cache-action != '' }}
uses: jenseng/dynamic-uses@v1
with:
path: ${{ steps.flutter-action.outputs.PUB-CACHE-PATH }}
key: ${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}-${{ hashFiles('**/pubspec.lock') }}
uses: ${{ inputs.custom-pub-cache-action == '' && 'actions/cache@v5' || inputs.custom-pub-cache-action }}
with: |
path: ${{ toJSON(steps.flutter-action.outputs.PUB-CACHE-PATH) }}
key: '${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}-${{ hashFiles('**/pubspec.lock') }}'

- name: Run setup script
shell: bash
Expand Down