From 00d3eda27524a190af0ce4fbe72743e98a2dc888 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Sat, 14 Mar 2026 18:25:43 -0300 Subject: [PATCH 1/2] feat: custom cache support Adding support for custom cache actions. They must be a drop in replacement for actions/cache for it to work properly --- action.yaml | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/action.yaml b/action.yaml index 644170e..8b87d05 100644 --- a/action.yaml +++ b/action.yaml @@ -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: @@ -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: @@ -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 From 33ae9affc39e867f682260859873c00d7ff038d0 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Tue, 17 Mar 2026 14:23:18 -0300 Subject: [PATCH 2/2] docs: adding readme entry for custom cache --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index d33e1a6..a6b498f 100644 --- a/README.md +++ b/README.md @@ -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`: