From f95a8c953b15637d76e6c0988b765c93f472a5d8 Mon Sep 17 00:00:00 2001 From: Alif Rachmawadi Date: Fri, 7 Jan 2022 04:47:25 +0000 Subject: [PATCH] add actions/cache support --- .github/workflows/workflow.yml | 19 +++++++++++++++++++ README.md | 15 +++++++++++++++ setup.sh | 30 ++++++++++++++++-------------- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 7e23033..7d78d0b 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -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 diff --git a/README.md b/README.md index 4bbb554..fd765b8 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/setup.sh b/setup.sh index 23a560c..4cb4e81 100755 --- a/setup.sh +++ b/setup.sh @@ -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