Skip to content

Commit cbf2b87

Browse files
committed
feat(core): re-write action to support cache and Apple Silicon
1 parent 739cfea commit cbf2b87

File tree

2 files changed

+83
-43
lines changed

2 files changed

+83
-43
lines changed

action.yml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,29 @@ branding:
44
icon: "triangle"
55
color: "blue"
66
inputs:
7-
sdk:
8-
description: "The channel to install ('stable', 'beta', 'dev')."
7+
version:
8+
description: "The version to install: Default: 3.0.2"
9+
required: false
10+
default: "3.0.2"
11+
channel:
12+
description: "The version to install. Default: stable"
913
required: false
1014
default: "stable"
11-
version:
12-
description: "The version to install"
13-
required: false
14-
default: "3.0.2"
15+
cache:
16+
description: 'Cache the installed Flutter SDK. Default: True'
17+
required: false
18+
default: "true"
19+
cache-key:
20+
description: "An explicit key for restoring and saving the Flutter SDK to/from cache"
21+
required: false
22+
default: flutter-action-setup-flutter-${{ runner.os }}-${{ inputs.version }}-${{ inputs.channel }}-${{ runner.arch }}
1523
runs:
1624
using: "composite"
1725
steps:
18-
- run: $GITHUB_ACTION_PATH/setup.sh ${{ inputs.sdk }} ${{ runner.os }} ${{ inputs.version }}
26+
- if: ${{ inputs.cache == 'true' }}
27+
uses: actions/cache@v3
28+
with:
29+
path: ${{ runner.tool_cache }}/flutter-${{ runner.os }}-${{ inputs.version }}-${{ runner.arch }}
30+
key: ${{ inputs.cache-key }}
31+
- run: $GITHUB_ACTION_PATH/setup.sh ${{ inputs.version }} ${{ inputs.channel }}
1932
shell: bash

setup.sh

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,81 @@
11
#!/bin/bash
22

3-
# Parse SDK and version args
4-
CHANNEL="${1:-stable}"
5-
VERSION="${3:-3.0.2}"
3+
# Options
4+
ARCH=$(echo "${RUNNER_ARCH:-x64}" | awk '{print tolower($0)}')
5+
OS=$(echo "${RUNNER_OS:-macOS}" | awk '{print tolower($0)}')
66

7-
# Parse OS Environment
8-
OS="${2:-Linux}"
9-
OS=$(echo "$OS" | awk '{print tolower($0)}')
7+
# Args
8+
FLUTTER_CHANNEL=${1:-stable}
9+
FLUTTER_VERSION=${2:-3.0.2}
10+
FLUTTER_OS=$OS
11+
FLUTTER_ARCH=""
1012

1113
# OS archive file extension
1214
EXT="zip"
1315
if [[ $OS == linux ]]
1416
then
15-
EXT="tar.xz"
17+
EXT="tar.xz"
18+
fi
19+
20+
# Apple Intel or Apple Silicon
21+
if [[ $OS == macos ]]
22+
then
23+
if [[ $ARCH == 'arm64' ]]
24+
then
25+
FLUTTER_ARCH="_$ARCH"
26+
fi
1627
fi
1728

1829
# Flutter runner tool cache
19-
FLUTTER_RUNNER_TOOL_CACHE="${RUNNER_TOOL_CACHE}/${VERSION}-${CHANNEL}"
30+
# path: "${{ runner.tool_cache }}/flutter-${{ runner.os }}-${{ inputs.version }}-${{ runner.arch }}"
31+
# key: flutter-action-setup-flutter-${{ runner.os }}-${{ inputs.version }}-${{ runner.arch }}
32+
FLUTTER_RUNNER_TOOL_CACHE="${RUNNER_TOOL_CACHE}/flutter-${RUNNER_OS}-${FLUTTER_VERSION}-${RUNNER_ARCH}"
2033

2134
# Check if Flutter SDK already exists
2235
# Otherwise download and install
36+
# https://storage.googleapis.com/flutter_infra_release/releases/stable/macos/flutter_macos_arm64_3.0.2-stable.zip
37+
FLUTTER_RELEASE_URL="https://storage.googleapis.com/flutter_infra_release/releases"
38+
39+
2340
if [ ! -d "${FLUTTER_RUNNER_TOOL_CACHE}" ]; then
24-
echo "Installing Flutter SDK version \"${VERSION}\" from the ${CHANNEL} channel on ${OS}"
25-
26-
# Calculate download Url. Based on:
27-
# https://flutter.dev/docs/development/tools/sdk/releases
28-
PREFIX="https://storage.googleapis.com/flutter_infra_release/releases"
29-
BUILD="flutter_${OS}_${VERSION}-${CHANNEL}.${EXT}"
30-
31-
URL="${PREFIX}/${CHANNEL}/${OS}/${BUILD}"
32-
echo "Downloading ${URL}..."
33-
34-
# Download installation archive
35-
curl --connect-timeout 15 --retry 5 "$URL" > "/tmp/${BUILD}"
36-
37-
# Prepare tool cache folder
38-
mkdir -p "${FLUTTER_RUNNER_TOOL_CACHE}"
39-
40-
# Extracting installation archive
41-
if [[ $OS == linux ]]
42-
then
43-
tar -C "${FLUTTER_RUNNER_TOOL_CACHE}" -xf "/tmp/${BUILD}" > /dev/null
44-
else
45-
unzip "/tmp/${BUILD}" -d "${FLUTTER_RUNNER_TOOL_CACHE}" > /dev/null
46-
fi
47-
48-
if [ $? -ne 0 ]; then
49-
echo -e "::error::Download failed! Please check passed arguments."
50-
exit 1
51-
fi
41+
echo "Installing Flutter SDK version \"${FLUTTER_VERSION}\" from the ${FLUTTER_CHANNEL} channel on ${FLUTTER_OS}"
42+
43+
# Linux
44+
# /stable /linux/ flutter_linux_2.10.2-stable.tar.xz
45+
# /beta /linux/ flutter_linux_3.1.0-9.0.pre-beta.tar.xz
46+
47+
# macOS
48+
# /stable /macos/ flutter_macos_3.0.2-stable.zip
49+
# /stable /macos/ flutter_macos_arm64_3.0.2-stable.zip
50+
# /beta /macos/ flutter_macos_arm64_3.1.0-9.0.pre-beta.zip
51+
# /beta /macos/ flutter_macos_3.1.0-9.0.pre-beta.zip
52+
53+
# Windows
54+
# /stable /windows/ flutter_windows_3.0.2-stable.zip
55+
# /beta /windows/ flutter_windows_3.1.0-9.0.pre-beta.zip
56+
FLUTTER_BUILD="flutter_${FLUTTER_OS}${FLUTTER_ARCH}_${FLUTTER_VERSION}-${FLUTTER_CHANNEL}.${EXT}"
57+
FLUTTER_DOWNLOAD_URL="${FLUTTER_RELEASE_URL}/${FLUTTER_CHANNEL}/${FLUTTER_OS}/${FLUTTER_BUILD}"
58+
59+
echo "Downloading ${FLUTTER_DOWNLOAD_URL}"
60+
61+
# Download installation archive
62+
curl --connect-timeout 15 --retry 5 "$FLUTTER_DOWNLOAD_URL" > "/tmp/${FLUTTER_BUILD}"
63+
64+
# Prepare tool cache folder
65+
mkdir -p "${FLUTTER_RUNNER_TOOL_CACHE}"
66+
67+
# Extracting installation archive
68+
if [[ $OS == linux ]]
69+
then
70+
tar -C "${FLUTTER_RUNNER_TOOL_CACHE}" -xf "/tmp/${BUILD}" > /dev/null
71+
else
72+
unzip "/tmp/${BUILD}" -d "${FLUTTER_RUNNER_TOOL_CACHE}" > /dev/null
73+
fi
74+
75+
if [ $? -ne 0 ]; then
76+
echo -e "::error::Download failed! Please check passed arguments."
77+
exit 1
78+
fi
5279
fi
5380

5481
# Configure pub to use a fixed location.

0 commit comments

Comments
 (0)