Skip to content

Commit 1c5eb12

Browse files
authored
fix: specify pub cache path (#280)
1 parent 62f096c commit 1c5eb12

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ inputs:
2929
description: 'Flutter SDK cache path'
3030
required: false
3131
default: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:'
32+
pub-cache-path:
33+
description: 'Flutter pub cache path'
34+
required: false
35+
default: 'default'
3236
architecture:
3337
description: 'The architecture of Flutter SDK executable (x64 or arm64)'
3438
required: false
@@ -54,7 +58,7 @@ runs:
5458
- run: chmod +x $GITHUB_ACTION_PATH/setup.sh
5559
shell: bash
5660
- id: flutter-action
57-
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 }}
61+
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 }}
5862
shell: bash
5963
- if: ${{ inputs.cache == 'true' }}
6064
uses: actions/cache@v4

setup.sh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ download_archive() {
5151
if [[ "$archive_name" == *zip ]]; then
5252
EXTRACT_PATH="$RUNNER_TEMP/_unzip_temp"
5353
unzip -q -o "$archive_local" -d "$EXTRACT_PATH"
54-
# Remove the folder again so that the move command can do a simple rename\
54+
# Remove the folder again so that the move command can do a simple rename
5555
# instead of moving the content into the target folder.
5656
# This is a little bit of a hack since the "mv --no-target-directory"
5757
# linux option is not available here
@@ -67,17 +67,19 @@ download_archive() {
6767

6868
CACHE_PATH=""
6969
CACHE_KEY=""
70+
PUB_CACHE_PATH=""
7071
PUB_CACHE_KEY=""
7172
PRINT_ONLY=""
7273
TEST_MODE=false
7374
ARCH=""
7475
VERSION=""
7576

76-
while getopts 'tc:k:d:pa:n:' flag; do
77+
while getopts 'tc:k:d:l:pa:n:' flag; do
7778
case "$flag" in
7879
c) CACHE_PATH="$OPTARG" ;;
7980
k) CACHE_KEY="$OPTARG" ;;
80-
d) PUB_CACHE_KEY="$OPTARG" ;;
81+
d) PUB_CACHE_PATH="$OPTARG" ;;
82+
l) PUB_CACHE_KEY="$OPTARG" ;;
8183
p) PRINT_ONLY=true ;;
8284
t) TEST_MODE=true ;;
8385
a) ARCH="$(echo "$OPTARG" | awk '{print tolower($0)}')" ;;
@@ -97,8 +99,23 @@ CHANNEL="${ARR_CHANNEL[0]}"
9799
[[ -z $CACHE_PATH ]] && CACHE_PATH="$RUNNER_TEMP/flutter/:channel:-:version:-:arch:"
98100
[[ -z $CACHE_KEY ]] && CACHE_KEY="flutter-:os:-:channel:-:version:-:arch:-:hash:"
99101
[[ -z $PUB_CACHE_KEY ]] && PUB_CACHE_KEY="flutter-pub-:os:-:channel:-:version:-:arch:-:hash:"
100-
# Here we specifically use `PUB_CACHE` (and not `PUB_CACHE_PATH`), because `PUB_CACHE` is what dart (and flutter) looks for in the environment
101-
[[ -z $PUB_CACHE ]] && PUB_CACHE="$HOME/.pub-cache"
102+
[[ -z $PUB_CACHE_PATH ]] && PUB_CACHE_PATH="default"
103+
104+
# `PUB_CACHE` is what Dart and Flutter looks for in the environment, while
105+
# `PUB_CACHE_PATH` is passed in from the action.
106+
#
107+
# If `PUB_CACHE` is set already, then it should continue to be used. Otherwise, satisfy it
108+
# if the action requests a custom path, or set to the Dart default values depending
109+
# on the operating system.
110+
if [ -z "$PUB_CACHE" ]; then
111+
if [ "$PUB_CACHE_PATH" != "default" ]; then
112+
PUB_CACHE="$PUB_CACHE_PATH"
113+
elif [ "$OS_NAME" == "windows" ]; then
114+
PUB_CACHE="$LOCALAPPDATA\\Pub\\Cache"
115+
else
116+
PUB_CACHE="$HOME/.pub-cache"
117+
fi
118+
fi
102119

103120
if [[ "$TEST_MODE" == true ]]; then
104121
RELEASE_MANIFEST=$(cat "$(dirname -- "${BASH_SOURCE[0]}")/test/$MANIFEST_JSON_PATH")

0 commit comments

Comments
 (0)