Skip to content

Conversation

@beninato8
Copy link
Contributor

@beninato8 beninato8 commented Jun 9, 2025

In the caching section of the README, both CACHE-PATH and PUB-CACHE-PATH are supposed to support dynamic values, like :version: and :arch:.

I wanted to implement caching for my usage of subosito/flutter-action@v2, so I tried adding the block from the README:

- name: Set up Flutter
    uses: subosito/flutter-action@v2
    id: flutter-action
    with:
        flutter-version: "3.27.x"
        channel: "stable"
        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:"

In my action output, I saw that PUB_CACHE_PATH still contained the placeholders:

Run subosito/flutter-action@v2
with:
  flutter-version: 3.27.x
  channel: stable
  cache: true
  cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:
  cache-path: /opt/hostedtoolcache/flutter/:channel:-:version:-:arch:
  pub-cache-key: flutter-pub:os:-:channel:-:version:-:arch:-:hash:
  pub-cache-path: /opt/hostedtoolcache/flutter/:channel:-:version:-:arch:
  architecture: X64
  dry-run: false
  git-source: https://github.com/flutter/flutter.git

$GITHUB_ACTION_PATH/setup.sh -p \
  -n '3.27.x' \
  -f '' \
  -a 'X64' \
  -k 'flutter-:os:-:channel:-:version:-:arch:-:hash:' \
  -c '/opt/hostedtoolcache/flutter/:channel:-:version:-:arch:' \
  -l 'flutter-pub:os:-:channel:-:version:-:arch:-:hash:' \
  -d '/opt/hostedtoolcache/flutter/:channel:-:version:-:arch:' \
  -g 'https://github.com/flutter/flutter.git' \
  stable

Run actions/cache@v4
with:
  path: /opt/hostedtoolcache/flutter/stable-3.27.4-x64
  key: flutter-linux-stable-3.27.4-x64-d8a9f9a52e5af486f80d932e838ee93861ffd863
  enableCrossOsArchive: false
  fail-on-cache-miss: false
  lookup-only: false
  save-always: false

Run actions/cache@v4
with:
  path: /opt/hostedtoolcache/flutter/:channel:-:version:-:arch:
  key: flutter-publinux-stable-3.27.4-x64-d8a9f9a52e5af486f80d932e838ee93861ffd863-a0844170cef72d2be5a80509b7e7b13d0f906f8012f6585ea075b5ec0b48ed3f
  enableCrossOsArchive: false
  fail-on-cache-miss: false
  lookup-only: false
  save-always: false

$GITHUB_ACTION_PATH/setup.sh \
  -n '3.27.4' \
  -a 'x64' \
  -c '/opt/hostedtoolcache/flutter/stable-3.27.4-x64' \
  -d '/opt/hostedtoolcache/flutter/:channel:-:version:-:arch:' \
  stable

This PR applies the expand_key function on PUB_CACHE, updates the README to fix a missing dash in the example path (to match the default [ -z "$PUB_CACHE_KEY" ] && PUB_CACHE_KEY="flutter-pub-:os:-:channel:-:version:-:arch:-:hash:"), and adds tests for PUB_CACHE_KEY and PUB_CACHE_PATH.

Before this change:

./setup.sh -p -t -d '/opt/hostedtoolcache/flutter/:channel:-:version:-:arch:'
CHANNEL=stable
VERSION=3.7.7
ARCHITECTURE=x64
CACHE-KEY=flutter-linux-stable-3.7.7-x64-2ad6cd72c040113b47ee9055e722606a490ef0da
CACHE-PATH=/opt/hostedtoolcache/flutter/stable-3.7.7-x64
PUB-CACHE-KEY=flutter-pub-linux-stable-3.7.7-x64-2ad6cd72c040113b47ee9055e722606a490ef0da
PUB-CACHE-PATH=/opt/hostedtoolcache/flutter/:channel:-:version:-:arch:

After this change:

./setup.sh -p -t -d '/opt/hostedtoolcache/flutter/:channel:-:version:-:arch:'
CHANNEL=stable
VERSION=3.7.7
ARCHITECTURE=x64
CACHE-KEY=flutter-linux-stable-3.7.7-x64-2ad6cd72c040113b47ee9055e722606a490ef0da
CACHE-PATH=/opt/hostedtoolcache/flutter/stable-3.7.7-x64
PUB-CACHE-KEY=flutter-pub-linux-stable-3.7.7-x64-2ad6cd72c040113b47ee9055e722606a490ef0da
PUB-CACHE-PATH=/opt/hostedtoolcache/flutter/stable-3.7.7-x64

@beninato8 beninato8 changed the title Beninato/pub cache path Support dynamic values for PUB-CACHE-PATH Jun 9, 2025
Copy link
Collaborator

@bartekpacia bartekpacia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx!

@bartekpacia bartekpacia merged commit fd55f4c into subosito:main Jun 24, 2025
81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants