From c30358aafe5ae8e54d1ee4cbba0220fb4b311958 Mon Sep 17 00:00:00 2001 From: Alif Rachmawadi Date: Tue, 26 Jul 2022 12:08:35 +0700 Subject: [PATCH] dynamic cache path --- .github/workflows/workflow.yml | 42 ++++++++++++++++++++++------------ README.md | 8 +++---- action.yml | 11 +++++---- setup.sh | 33 +++++++++++++++++++------- 4 files changed, 64 insertions(+), 30 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 4174ccf..211ad9b 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -79,35 +79,49 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v3 - - run: ./setup.sh -p cache-key | grep -x 'flutter-macos-x64-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1' + - run: ./setup.sh -p cache-key | grep -x 'flutter-macos-stable-3.0.5-x64-f1875d570e39de09040c8f79aa13cc56baab8db1' shell: bash - - run: ./setup.sh -p cache-key stable | grep -x 'flutter-macos-x64-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1' + - run: ./setup.sh -p cache-key stable | grep -x 'flutter-macos-stable-3.0.5-x64-f1875d570e39de09040c8f79aa13cc56baab8db1' shell: bash - - run: ./setup.sh -p cache-key beta | grep -x 'flutter-macos-x64-beta-3.1.0-9.0.pre-f28e570c8cb12a004fae2d796d0d9cd46603bde9' + - run: ./setup.sh -p cache-key beta | grep -x 'flutter-macos-beta-3.1.0-9.0.pre-x64-f28e570c8cb12a004fae2d796d0d9cd46603bde9' shell: bash - - run: ./setup.sh -p cache-key master | grep -x 'flutter-macos-x64-master-master-master' + - run: ./setup.sh -p cache-key master | grep -x 'flutter-macos-master-master-x64-master' shell: bash - - run: ./setup.sh -p cache-key stable 2 | grep -x 'flutter-macos-x64-stable-2.10.5-5464c5bac742001448fe4fc0597be939379f88ea' + - run: ./setup.sh -p cache-key stable 2 | grep -x 'flutter-macos-stable-2.10.5-x64-5464c5bac742001448fe4fc0597be939379f88ea' shell: bash - - run: ./setup.sh -p cache-key beta 2 | grep -x 'flutter-macos-x64-beta-2.13.0-0.4.pre-25caf1461b8f643092a9f6f5b224453b5c057d10' + - run: ./setup.sh -p cache-key beta 2 | grep -x 'flutter-macos-beta-2.13.0-0.4.pre-x64-25caf1461b8f643092a9f6f5b224453b5c057d10' shell: bash - - run: ./setup.sh -p cache-key any 2 | grep -x 'flutter-macos-x64-beta-2.13.0-0.4.pre-25caf1461b8f643092a9f6f5b224453b5c057d10' + - run: ./setup.sh -p cache-key any 2 | grep -x 'flutter-macos-beta-2.13.0-0.4.pre-x64-25caf1461b8f643092a9f6f5b224453b5c057d10' shell: bash - - run: ./setup.sh -p cache-key any 3 | grep -x 'flutter-macos-x64-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1' + - run: ./setup.sh -p cache-key any 3 | grep -x 'flutter-macos-stable-3.0.5-x64-f1875d570e39de09040c8f79aa13cc56baab8db1' shell: bash - - run: ./setup.sh -p cache-key any 3 arm64 | grep -x 'flutter-macos-arm64-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1' + - run: ./setup.sh -p cache-key any 3 arm64 | grep -x 'flutter-macos-stable-3.0.5-arm64-f1875d570e39de09040c8f79aa13cc56baab8db1' shell: bash - - run: ./setup.sh -p cache-key stable any arm64 | grep -x 'flutter-macos-arm64-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1' + - run: ./setup.sh -p cache-key stable any arm64 | grep -x 'flutter-macos-stable-3.0.5-arm64-f1875d570e39de09040c8f79aa13cc56baab8db1' shell: bash - - run: ./setup.sh -p cache-key stable 1 | grep -x 'flutter-macos-x64-stable-1.22.6-9b2d32b605630f28625709ebd9d78ab3016b2bf6' + - run: ./setup.sh -p cache-key stable 1 | grep -x 'flutter-macos-stable-1.22.6-x64-9b2d32b605630f28625709ebd9d78ab3016b2bf6' shell: bash - - run: ./setup.sh -p cache-key stable v1 | grep -x 'flutter-macos-x64-stable-v1.12.13+hotfix.9-f139b11009aeb8ed2a3a3aa8b0066e482709dde3' + - run: ./setup.sh -p cache-key stable v1 | grep -x 'flutter-macos-stable-v1.12.13+hotfix.9-x64-f139b11009aeb8ed2a3a3aa8b0066e482709dde3' shell: bash - - run: ./setup.sh -p cache-key any 0 | grep -x 'flutter-macos-x64-beta-v0.11.13-58c8489fcdb4e4ef6c010117584c9b23d15221aa' + - run: ./setup.sh -p cache-key any 0 | grep -x 'flutter-macos-beta-v0.11.13-x64-58c8489fcdb4e4ef6c010117584c9b23d15221aa' shell: bash - - run: ./setup.sh -p cache-key any v0 | grep -x 'flutter-macos-x64-beta-v0.11.13-58c8489fcdb4e4ef6c010117584c9b23d15221aa' + - run: ./setup.sh -p cache-key any v0 | grep -x 'flutter-macos-beta-v0.11.13-x64-58c8489fcdb4e4ef6c010117584c9b23d15221aa' shell: bash - run: ./setup.sh -p cache-key -k 'custom-:channel:-:version:-:hash:' | grep -x 'custom-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1' shell: bash - run: ./setup.sh -p cache-key -k 'custom-:channel:-:version:-:sha256:' | grep -x 'custom-stable-3.0.5-e79a04dcfd1b583e5831433fc200800ba0d1e9fe4567cb661479bd2542d4c685' shell: bash + test_cache_path: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: ./setup.sh -p cache-path | grep -x '/home/runner/work/_temp/flutter/stable-3.0.5-x64' + shell: bash + - run: ./setup.sh -p cache-path stable | grep -x '/home/runner/work/_temp/flutter/stable-3.0.5-x64' + shell: bash + - run: ./setup.sh -p cache-path beta | grep -x '/home/runner/work/_temp/flutter/beta-3.1.0-9.0.pre-x64' + shell: bash + - run: ./setup.sh -p cache-path master | grep -x '/home/runner/work/_temp/flutter/master-master-x64' + shell: bash + - run: ./setup.sh -p cache-path -c '/tmp/flutter/:channel:-:version:-:hash:' | grep -x '/tmp/flutter/stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1' + shell: bash diff --git a/README.md b/README.md index 1024cfa..177c31e 100644 --- a/README.md +++ b/README.md @@ -157,17 +157,17 @@ steps: with: channel: 'stable' cache: true - cache-key: 'flutter-:os:-:arch:-:channel:-:version:-:hash:' # optional, change this to force refresh cache - cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path + cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' # optional, change this to force refresh cache + cache-path: ${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch: # optional, change this to specify the cache path architecture: x64 # optional, x64 or arm64 - run: flutter --version ``` -Note: `cache-key` has support for several dynamic values: +Note: `cache-key` and `cache-path` has support for several dynamic values: - `:os:` -- `:arch:` - `:channel:` - `:version:` +- `:arch:` - `:hash:` - `:sha256:` diff --git a/action.yml b/action.yml index 88ca09d..e38784f 100644 --- a/action.yml +++ b/action.yml @@ -19,11 +19,11 @@ inputs: cache-key: description: 'Identifier for the Flutter SDK cache' required: false - default: 'flutter-:os:-:arch:-:channel:-:version:-:hash:' + default: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' cache-path: description: 'Flutter SDK cache path' required: false - default: ${{ runner.tool_cache }}/flutter + default: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:' architecture: description: 'The architecture of Flutter SDK executable (x64 or arm64)' required: false @@ -31,6 +31,9 @@ inputs: runs: using: 'composite' steps: + - id: flutter-action-cache-path-builder + run: echo "::set-output name=cache-path::$($GITHUB_ACTION_PATH/setup.sh -p cache-path -c '${{ inputs.cache-path }}' ${{ inputs.channel }} ${{ inputs.flutter-version }} ${{ inputs.architecture }})" + shell: bash - if: ${{ inputs.cache == 'true' }} id: flutter-action-cache-key-builder run: echo "::set-output name=cache-key::$($GITHUB_ACTION_PATH/setup.sh -p cache-key -k ${{ inputs.cache-key }} ${{ inputs.channel }} ${{ inputs.flutter-version }} ${{ inputs.architecture }})" @@ -38,7 +41,7 @@ runs: - if: ${{ inputs.cache == 'true' }} uses: actions/cache@v3 with: - path: ${{ inputs.cache-path }} + path: ${{ steps.flutter-action-cache-path-builder.outputs.cache-path }} key: ${{ steps.flutter-action-cache-key-builder.outputs.cache-key }} - - run: $GITHUB_ACTION_PATH/setup.sh -c "${{ inputs.cache-path }}" ${{ inputs.channel }} ${{ inputs.flutter-version }} ${{ inputs.architecture }} + - run: $GITHUB_ACTION_PATH/setup.sh -c '${{ steps.flutter-action-cache-path-builder.outputs.cache-path }}' ${{ inputs.channel }} ${{ inputs.flutter-version }} ${{ inputs.architecture }} shell: bash diff --git a/setup.sh b/setup.sh index 191855c..e4ff025 100755 --- a/setup.sh +++ b/setup.sh @@ -109,8 +109,8 @@ ARCH=$(echo "${ARR_ARCH[0]}" | awk '{print tolower($0)}') [[ -z $CHANNEL ]] && CHANNEL=stable [[ -z $VERSION ]] && VERSION=any [[ -z $ARCH ]] && ARCH=x64 -[[ -z $CACHE_PATH ]] && CACHE_PATH=/tmp -[[ -z $CACHE_KEY ]] && CACHE_KEY="flutter-:os:-:arch:-:channel:-:version:-:hash:" +[[ -z $CACHE_PATH ]] && CACHE_PATH="$RUNNER_TEMP/flutter/:channel:-:version:-:arch:" +[[ -z $CACHE_KEY ]] && CACHE_KEY="flutter-:os:-:channel:-:version:-:arch:-:hash:" RELEASE_MANIFEST="" VERSION_MANIFEST="" @@ -165,11 +165,20 @@ if [[ -n "$PRINT_MODE" ]]; then exit 0 fi - if [[ "$PRINT_MODE" == cache-key ]]; then - VERSION_MANIFEST="{\"channel\":\"$CHANNEL\",\"version\":\"$CHANNEL\",\"dart_sdk_arch\":\"$ARCH\",\"hash\":\"$CHANNEL\",\"sha256\":\"$CHANNEL\"}" - EXPANDED_KEY=$(expand_key "$CACHE_KEY") + VERSION_MANIFEST="{\"channel\":\"$CHANNEL\",\"version\":\"$CHANNEL\",\"dart_sdk_arch\":\"$ARCH\",\"hash\":\"$CHANNEL\",\"sha256\":\"$CHANNEL\"}" - echo "$EXPANDED_KEY" + if [[ "$PRINT_MODE" == cache-key ]]; then + expanded_key=$(expand_key "$CACHE_KEY") + + echo "$expanded_key" + exit 0 + fi + + if [[ "$PRINT_MODE" == cache-path ]]; then + cache_path=$(transform_path "$CACHE_PATH") + expanded_path=$(expand_key "$cache_path") + + echo "$expanded_path" exit 0 fi @@ -190,9 +199,17 @@ if [[ -n "$PRINT_MODE" ]]; then fi if [[ "$PRINT_MODE" == cache-key ]]; then - EXPANDED_KEY=$(expand_key "$CACHE_KEY") + expanded_key=$(expand_key "$CACHE_KEY") - echo "$EXPANDED_KEY" + echo "$expanded_key" + exit 0 + fi + + if [[ "$PRINT_MODE" == cache-path ]]; then + cache_path=$(transform_path "$CACHE_PATH") + expanded_path=$(expand_key "$cache_path") + + echo "$expanded_path" exit 0 fi