Skip to content

Commit

Permalink
add cache path option
Browse files Browse the repository at this point in the history
  • Loading branch information
subosito committed Jan 13, 2022
1 parent 03e576d commit 4f5d1c6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ jobs:
channel: stable
flutter-version: 2.5.0
cache: true
cache-key: key-20220110
cache-key: key-20220113
cache-path: ${{ runner.tool_cache }}/flutter/2.5.0-stable
- name: Run dart --version
shell: bash
run: dart --version
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,6 @@ steps:
flutter-version: 2.5.0
cache: true
cache-key: flutter # optional, change this to force refresh cache
cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path
- run: flutter --version
```
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ inputs:
description: 'Identifier for the Flutter SDK cache'
required: false
default: 'flutter'
cache-path:
description: 'Flutter SDK cache path'
required: false
default: ${{ runner.tool_cache }}/flutter
runs:
using: 'composite'
steps:
- if: ${{ inputs.cache == 'true' }}
uses: actions/cache@v2
with:
path: ${{ runner.tool_cache }}/flutter
path: ${{ inputs.cache-path }}
key: ${{ inputs.cache-key }}-${{ inputs.channel }}-${{ inputs.flutter-version }}
- run: $GITHUB_ACTION_PATH/setup.sh ${{ inputs.channel }} ${{ inputs.flutter-version }}
- run: $GITHUB_ACTION_PATH/setup.sh -c "${{ inputs.cache-path }}" ${{ inputs.channel }} ${{ inputs.flutter-version }}
shell: bash
44 changes: 32 additions & 12 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,48 @@ download_archive() {
curl --connect-timeout 15 --retry 5 $archive_url >$archive_local

if [[ $archive_name == *zip ]]; then
unzip -o "$archive_local" -d "$2"
unzip -o "$archive_local" -d "$HOME"
shopt -s dotglob
mv ${HOME}/flutter/* "$2"
shopt -u dotglob
else
tar xf "$archive_local" -C "$2"
tar xf "$archive_local" -C "$2" --strip-components=1
fi

rm $archive_local
}

CHANNEL="$1"
VERSION="$2"
transform_path() {
if [[ $OS_NAME == windows ]]; then
echo $1 | sed -e 's/^\///' -e 's/\//\\/g'
else
echo $1
fi
}

SDK_CACHE=""

while getopts 'c:' flag; do
case "${flag}" in
c) SDK_CACHE="$(transform_path $OPTARG)" ;;
?) exit 2 ;;
esac
done

CHANNEL="${@:$OPTIND:1}"
VERSION="${@:$OPTIND+1:1}"

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
mkdir -p "$SDK_CACHE"

if [[ ! -x "${SDK_CACHE}/bin/flutter" ]]; 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 "$SDK_CACHE"
else
VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION)

Expand All @@ -84,13 +104,13 @@ if [[ ! -x "${FLUTTER_ROOT}/bin/flutter" ]]; then
fi

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

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

echo "${FLUTTER_ROOT}/bin" >>$GITHUB_PATH
echo "${FLUTTER_ROOT}/bin/cache/dart-sdk/bin" >>$GITHUB_PATH
echo "${SDK_CACHE}/bin" >>$GITHUB_PATH
echo "${SDK_CACHE}/bin/cache/dart-sdk/bin" >>$GITHUB_PATH
echo "${PUB_CACHE}/bin" >>$GITHUB_PATH

0 comments on commit 4f5d1c6

Please sign in to comment.