add actions/cache support

This commit is contained in:
Alif Rachmawadi
2022-01-07 04:47:25 +00:00
parent 3dae472464
commit e405f57356
3 changed files with 50 additions and 14 deletions

View File

@@ -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

View File

@@ -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
```

View File

@@ -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"
@@ -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