1
0
Fork 0
mirror of https://github.com/subosito/flutter-action.git synced 2024-08-16 10:19:50 +02:00

fix: specify pub cache path (#280)

This commit is contained in:
Richard Shiue 2024-03-20 12:20:53 +08:00 committed by GitHub
parent 62f096cacd
commit 1c5eb12d81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 6 deletions

View file

@ -29,6 +29,10 @@ inputs:
description: 'Flutter SDK cache path' description: 'Flutter SDK cache path'
required: false required: false
default: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:' default: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:'
pub-cache-path:
description: 'Flutter pub cache path'
required: false
default: 'default'
architecture: architecture:
description: 'The architecture of Flutter SDK executable (x64 or arm64)' description: 'The architecture of Flutter SDK executable (x64 or arm64)'
required: false required: false
@ -54,7 +58,7 @@ runs:
- run: chmod +x $GITHUB_ACTION_PATH/setup.sh - run: chmod +x $GITHUB_ACTION_PATH/setup.sh
shell: bash shell: bash
- id: flutter-action - id: flutter-action
run: $GITHUB_ACTION_PATH/setup.sh -p -c '${{ inputs.cache-path }}' -k '${{ inputs.cache-key }}' -d '${{ inputs.pub-cache-key }}' -n '${{ inputs.flutter-version }}' -a '${{ inputs.architecture }}' ${{ inputs.channel }} run: $GITHUB_ACTION_PATH/setup.sh -p -c '${{ inputs.cache-path }}' -k '${{ inputs.cache-key }}' -d '${{ inputs.pub-cache-path }}' -l '${{ inputs.pub-cache-key }}' -n '${{ inputs.flutter-version }}' -a '${{ inputs.architecture }}' ${{ inputs.channel }}
shell: bash shell: bash
- if: ${{ inputs.cache == 'true' }} - if: ${{ inputs.cache == 'true' }}
uses: actions/cache@v4 uses: actions/cache@v4

View file

@ -51,7 +51,7 @@ download_archive() {
if [[ "$archive_name" == *zip ]]; then if [[ "$archive_name" == *zip ]]; then
EXTRACT_PATH="$RUNNER_TEMP/_unzip_temp" EXTRACT_PATH="$RUNNER_TEMP/_unzip_temp"
unzip -q -o "$archive_local" -d "$EXTRACT_PATH" unzip -q -o "$archive_local" -d "$EXTRACT_PATH"
# Remove the folder again so that the move command can do a simple rename\ # Remove the folder again so that the move command can do a simple rename
# instead of moving the content into the target folder. # instead of moving the content into the target folder.
# This is a little bit of a hack since the "mv --no-target-directory" # This is a little bit of a hack since the "mv --no-target-directory"
# linux option is not available here # linux option is not available here
@ -67,17 +67,19 @@ download_archive() {
CACHE_PATH="" CACHE_PATH=""
CACHE_KEY="" CACHE_KEY=""
PUB_CACHE_PATH=""
PUB_CACHE_KEY="" PUB_CACHE_KEY=""
PRINT_ONLY="" PRINT_ONLY=""
TEST_MODE=false TEST_MODE=false
ARCH="" ARCH=""
VERSION="" VERSION=""
while getopts 'tc:k:d:pa:n:' flag; do while getopts 'tc:k:d:l:pa:n:' flag; do
case "$flag" in case "$flag" in
c) CACHE_PATH="$OPTARG" ;; c) CACHE_PATH="$OPTARG" ;;
k) CACHE_KEY="$OPTARG" ;; k) CACHE_KEY="$OPTARG" ;;
d) PUB_CACHE_KEY="$OPTARG" ;; d) PUB_CACHE_PATH="$OPTARG" ;;
l) PUB_CACHE_KEY="$OPTARG" ;;
p) PRINT_ONLY=true ;; p) PRINT_ONLY=true ;;
t) TEST_MODE=true ;; t) TEST_MODE=true ;;
a) ARCH="$(echo "$OPTARG" | awk '{print tolower($0)}')" ;; a) ARCH="$(echo "$OPTARG" | awk '{print tolower($0)}')" ;;
@ -97,8 +99,23 @@ CHANNEL="${ARR_CHANNEL[0]}"
[[ -z $CACHE_PATH ]] && CACHE_PATH="$RUNNER_TEMP/flutter/:channel:-:version:-:arch:" [[ -z $CACHE_PATH ]] && CACHE_PATH="$RUNNER_TEMP/flutter/:channel:-:version:-:arch:"
[[ -z $CACHE_KEY ]] && CACHE_KEY="flutter-:os:-:channel:-:version:-:arch:-:hash:" [[ -z $CACHE_KEY ]] && CACHE_KEY="flutter-:os:-:channel:-:version:-:arch:-:hash:"
[[ -z $PUB_CACHE_KEY ]] && PUB_CACHE_KEY="flutter-pub-:os:-:channel:-:version:-:arch:-:hash:" [[ -z $PUB_CACHE_KEY ]] && PUB_CACHE_KEY="flutter-pub-:os:-:channel:-:version:-:arch:-:hash:"
# Here we specifically use `PUB_CACHE` (and not `PUB_CACHE_PATH`), because `PUB_CACHE` is what dart (and flutter) looks for in the environment [[ -z $PUB_CACHE_PATH ]] && PUB_CACHE_PATH="default"
[[ -z $PUB_CACHE ]] && PUB_CACHE="$HOME/.pub-cache"
# `PUB_CACHE` is what Dart and Flutter looks for in the environment, while
# `PUB_CACHE_PATH` is passed in from the action.
#
# If `PUB_CACHE` is set already, then it should continue to be used. Otherwise, satisfy it
# if the action requests a custom path, or set to the Dart default values depending
# on the operating system.
if [ -z "$PUB_CACHE" ]; then
if [ "$PUB_CACHE_PATH" != "default" ]; then
PUB_CACHE="$PUB_CACHE_PATH"
elif [ "$OS_NAME" == "windows" ]; then
PUB_CACHE="$LOCALAPPDATA\\Pub\\Cache"
else
PUB_CACHE="$HOME/.pub-cache"
fi
fi
if [[ "$TEST_MODE" == true ]]; then if [[ "$TEST_MODE" == true ]]; then
RELEASE_MANIFEST=$(cat "$(dirname -- "${BASH_SOURCE[0]}")/test/$MANIFEST_JSON_PATH") RELEASE_MANIFEST=$(cat "$(dirname -- "${BASH_SOURCE[0]}")/test/$MANIFEST_JSON_PATH")