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 - name: Run flutter --version
shell: bash shell: bash
run: flutter --version 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 - 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,6 +64,15 @@ download_archive() {
CHANNEL="$1" CHANNEL="$1"
VERSION="$2" VERSION="$2"
if [[ $OS_NAME == windows ]]; then
FLUTTER_ROOT="${RUNNER_TOOL_CACHE}\\flutter"
PUB_CACHE="${USERPROFILE}\\.pub-cache"
else
FLUTTER_ROOT="${RUNNER_TOOL_CACHE}/flutter"
PUB_CACHE="${HOME}/.pub-cache"
fi
if [[ ! -x "${FLUTTER_ROOT}/bin/flutter" ]]; then
if [[ $CHANNEL == master ]]; then if [[ $CHANNEL == master ]]; then
git clone -b master https://github.com/flutter/flutter.git "$RUNNER_TOOL_CACHE/flutter" git clone -b master https://github.com/flutter/flutter.git "$RUNNER_TOOL_CACHE/flutter"
else else
@@ -77,13 +86,6 @@ else
ARCHIVE_PATH=$(echo $VERSION_MANIFEST | jq -r '.archive') ARCHIVE_PATH=$(echo $VERSION_MANIFEST | jq -r '.archive')
download_archive "$ARCHIVE_PATH" "$RUNNER_TOOL_CACHE" download_archive "$ARCHIVE_PATH" "$RUNNER_TOOL_CACHE"
fi fi
if [[ $OS_NAME == windows ]]; then
FLUTTER_ROOT="${RUNNER_TOOL_CACHE}\\flutter"
PUB_CACHE="${USERPROFILE}\\.pub-cache"
else
FLUTTER_ROOT="${RUNNER_TOOL_CACHE}/flutter"
PUB_CACHE="${HOME}/.pub-cache"
fi fi
echo "FLUTTER_ROOT=${FLUTTER_ROOT}" >>$GITHUB_ENV echo "FLUTTER_ROOT=${FLUTTER_ROOT}" >>$GITHUB_ENV