Skip to content

Commit

Permalink
add actions/cache support
Browse files Browse the repository at this point in the history
  • Loading branch information
subosito committed Jan 7, 2022
1 parent 3dae472 commit f95a8c9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/workflow.yml
Expand Up @@ -72,3 +72,22 @@ jobs:
- name: Run flutter --version
shell: bash
run: flutter --version
test_with_cache:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ${{ runner.tool_cache }}/flutter
key: flutter-2.5.0-stable
- uses: ./
with:
channel: stable
flutter-version: 2.5.0
- name: Run dart --version
shell: bash
run: dart --version
- name: Run flutter --version
shell: bash
run: flutter --version
15 changes: 15 additions & 0 deletions README.md
Expand Up @@ -146,3 +146,18 @@ jobs:
- run: flutter build macos
```

Integration with actions/cache:

```yaml
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ${{ runner.tool_cache }}/flutter
key: flutter-2.5.0-stable
- uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: 2.5.0
- run: flutter --version
```
30 changes: 16 additions & 14 deletions setup.sh
Expand Up @@ -64,20 +64,6 @@ download_archive() {
CHANNEL="$1"
VERSION="$2"

if [[ $CHANNEL == master ]]; then
git clone -b master https://github.com/flutter/flutter.git "$RUNNER_TOOL_CACHE/flutter"
else
VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION)

if [[ $VERSION_MANIFEST == null ]]; then
echo "Unable to determine Flutter version for $CHANNEL $VERSION"
exit 1
fi

ARCHIVE_PATH=$(echo $VERSION_MANIFEST | jq -r '.archive')
download_archive "$ARCHIVE_PATH" "$RUNNER_TOOL_CACHE"
fi

if [[ $OS_NAME == windows ]]; then
FLUTTER_ROOT="${RUNNER_TOOL_CACHE}\\flutter"
PUB_CACHE="${USERPROFILE}\\.pub-cache"
Expand All @@ -86,6 +72,22 @@ else
PUB_CACHE="${HOME}/.pub-cache"
fi

if [[ ! -x "${FLUTTER_ROOT}/bin/flutter" ]]; then
if [[ $CHANNEL == master ]]; then
git clone -b master https://github.com/flutter/flutter.git "$RUNNER_TOOL_CACHE/flutter"
else
VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION)

if [[ $VERSION_MANIFEST == null ]]; then
echo "Unable to determine Flutter version for $CHANNEL $VERSION"
exit 1
fi

ARCHIVE_PATH=$(echo $VERSION_MANIFEST | jq -r '.archive')
download_archive "$ARCHIVE_PATH" "$RUNNER_TOOL_CACHE"
fi
fi

echo "FLUTTER_ROOT=${FLUTTER_ROOT}" >>$GITHUB_ENV
echo "PUB_CACHE=${PUB_CACHE}" >>$GITHUB_ENV

Expand Down

3 comments on commit f95a8c9

@samandmoore
Copy link

Choose a reason for hiding this comment

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

love this improvement! caching is a big win.

I'm curious if you'd be interested in a PR that moves the integration with the caching action into the action.yml and does it all for the user. Essentially, make it so that the user can provide a cache: true|false and if it's true then this action would internally use the cache action for the user, building the cache key, etc.

@subosito
Copy link
Owner Author

Choose a reason for hiding this comment

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

Hi @samandmoore, thanks for the idea. I just implemented it on 5f0ca75 (https://github.com/subosito/flutter-action/runs/4749101843?check_suite_focus=true). So please let me know your thought, and if everything is ok, I will merge it to the main branch. Thanks.

@samandmoore
Copy link

Choose a reason for hiding this comment

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

Looks great. Thank you!

Please sign in to comment.