Skip to content

Add cache hit outputs #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

beninato8
Copy link

This PR addresses the changes requested in #346 from earlier this year, as I also would like to be able to use this feature.

It adds 2 new outputs: CACHE-HIT and PUB-CACHE-HIT. These just pass along the cache-hit output from actions/cache@v4 for the cache-flutter and cache-pub steps. These can be used for increasing workflow efficiency through steps like conditionally installing dependencies when the cache is invalid. The README is also updated with example usage to skip melos bootstrap if PUB-CACHE-HIT was not true.

I tested the outputs here: https://github.com/beninato8-forks/flutter-action/actions/runs/15627281250/job/44023816175

Cache restored successfully
Cache restored from key: flutter-linux-stable-3.27.4-x64-d8a9f9a52e5af486f80d932e838ee93861ffd863
...
Cache restored successfully
Cache restored from key: flutter-pub-linux-stable-3.27.4-x64-d8a9f9a52e5af486f80d932e838ee93861ffd863-
...
Cache Hit: true
Pub Cache Hit: true

Output from the following steps (after a previous run was cached):

- name: Flutter Action 1
  uses: ./
  id: flutter-action-1
  with:
    flutter-version: '3.27.x'
    channel: 'stable'
    cache: true

- name: Print Action Outputs 1
  run: |
    echo "Cache Hit: ${{ steps.flutter-action-1.outputs.CACHE-HIT }}"
    echo "Pub Cache Hit: ${{ steps.flutter-action-1.outputs.PUB-CACHE-HIT }}"

Comment on lines -366 to +404
[Alif Rachmawadi]: https://github.com/subosito
[Bartek Pacia]: https://github.com/bartekpacia

[Alif Rachmawadi](https://github.com/subosito)

[Bartek Pacia](https://github.com/bartekpacia)
Copy link
Author

Choose a reason for hiding this comment

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

these lines did not show up in the README, so i changed to links that do show up

Copy link
Collaborator

Choose a reason for hiding this comment

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

thank you!

@jogboms
Copy link

jogboms commented Jun 20, 2025

@bartekpacia 👀

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.

LGTM, thank you! just some tiny changes and it's ready to be merged

Comment on lines +322 to +325
Note: `PUB-CACHE-HIT` and `CACHE-HIT` directly use the `cache-hit` output from `actions/cache@v4`, which is the following:
> - `cache-hit` - A string value to indicate an exact match was found for the key.
> - If there's a cache hit, this will be 'true' or 'false' to indicate if there's an exact match for `key`.
> - If there's a cache miss, this will be an empty string.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use this syntax to make it look nicer :)

> - If there's a cache hit, this will be 'true' or 'false' to indicate if there's an exact match for `key`.
> - If there's a cache miss, this will be an empty string.

Example usage (inspired by [actions/cache@v4](https://github.com/actions/cache?tab=readme-ov-file#skipping-steps-based-on-cache-hit) and [#346](https://github.com/subosito/flutter-action/pull/346)) to skip `melos bootstrap` if there was a pub cache hit:
Copy link
Collaborator

Choose a reason for hiding this comment

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

pin the link to a specific commit so the link doesn't become broken in the future

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.

4 participants