Skip to content

Commit 35d198e

Browse files
authored
Merge pull request #3 from flutter-actions/feature/rework-setup-flutter
Re-write action to support cache and Apple Silicon
2 parents 99ad5cd + dd79e67 commit 35d198e

File tree

4 files changed

+101
-89
lines changed

4 files changed

+101
-89
lines changed

.github/workflows/dart.yml

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ on:
77
branches: [main]
88

99
jobs:
10-
test:
10+
test-stable:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
fail-fast: false
1414
matrix:
1515
os: [ubuntu-latest, macos-latest, windows-latest]
16-
# Test latest stable, beta, dev, and main channels + last stable release
17-
# prior to the introduction of the unified `dart` developer tool.
18-
sdk: [stable, beta]
16+
version: [3.0.2, 3.0.1, 3.0.0, 2.10.5]
1917
steps:
2018
- uses: actions/checkout@v2
2119
- uses: ./
2220
with:
23-
sdk: ${{ matrix.sdk }}
21+
channel: stable
22+
version: ${{ matrix.version }}
2423

2524
- name: Dart version
2625
run: dart --version
@@ -32,21 +31,18 @@ jobs:
3231
echo "main() { print('hello world'); }" > hello.dart
3332
dart hello.dart
3433
35-
test-dev:
34+
test-beta:
3635
runs-on: ${{ matrix.os }}
3736
strategy:
3837
fail-fast: false
3938
matrix:
4039
os: [ubuntu-latest, macos-latest, windows-latest]
41-
# Test latest stable, beta, dev, and main channels + last stable release
42-
# prior to the introduction of the unified `dart` developer tool.
43-
sdk: [dev]
44-
version: ["2.1.0-12.1.pre"]
40+
version: [3.1.0, 3.1.0-9.0.pre]
4541
steps:
4642
- uses: actions/checkout@v2
4743
- uses: ./
4844
with:
49-
sdk: ${{ matrix.sdk }}
45+
channel: beta
5046
version: ${{ matrix.version }}
5147

5248
- name: Dart version
@@ -58,30 +54,3 @@ jobs:
5854
run: |
5955
echo "main() { print('hello world'); }" > hello.dart
6056
dart hello.dart
61-
62-
test_pub:
63-
runs-on: ${{ matrix.os }}
64-
strategy:
65-
fail-fast: false
66-
matrix:
67-
os: [ubuntu-latest, macos-latest, windows-latest]
68-
sdk: [stable, beta]
69-
steps:
70-
- uses: actions/checkout@v2
71-
- uses: ./
72-
with:
73-
sdk: ${{ matrix.sdk }}
74-
75-
- name: Dart version
76-
run: dart --version
77-
- name: Flutter version
78-
run: flutter --version
79-
80-
- name: Global activate + run
81-
run: |
82-
dart pub global activate stagehand
83-
mkdir testapp
84-
cd testapp
85-
stagehand console-simple
86-
dart pub get
87-
dart run

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ This [GitHub Action]() installs and sets up of a Flutter SDK for use in actions
88
## Inputs
99

1010
The action takes the following inputs:
11-
* `sdk`: A release channel, which will install the latest build from that channel.
11+
* `channel`: A release channel, which will install the latest build from that channel.
1212
Available channels are `stable`, `beta`, `dev`. See
1313
https://flutter.dev/docs/development/tools/sdk/releases for details.
1414

15-
* `version`: A specific SDK version, e.g. `2.0.2` or `2.1.0-12.1.pre`
15+
* `version`: A specific SDK version, e.g. `3.0.2` or `3.1.0-9.0.pre`
1616

1717
## Basic example
1818

@@ -35,10 +35,10 @@ jobs:
3535
- uses: actions/checkout@v2
3636

3737
- name: Setup Flutter SDK
38-
uses: flutter-actions/setup-flutter@v1
38+
uses: flutter-actions/setup-flutter@v2
3939
with:
40-
sdk: stable
41-
version: 2.0.2
40+
channel: stable
41+
version: 3.0.2
4242

4343
- name: Install dependencies
4444
run: flutter pub get
@@ -77,10 +77,10 @@ jobs:
7777
uses: android-actions/setup-android@v2
7878

7979
- name: Setup Flutter SDK
80-
uses: flutter-actions/setup-flutter@v1
80+
uses: flutter-actions/setup-flutter@v2
8181
with:
82-
sdk: stable
83-
version: 2.0.2
82+
channel: stable
83+
version: 3.0.2
8484

8585
- name: Install dependencies
8686
run: flutter pub get

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: "2.0.2"
15+
cache:
16+
description: 'Cache the installed Flutter SDK. Default: false'
17+
required: false
18+
default: "false"
19+
cache-key:
20+
description: "An explicit key for restoring and saving the Flutter SDK to/from cache"
21+
required: false
22+
default: "flutter"
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: flutter-action-setup-flutter-${{ runner.os }}-${{ inputs.version }}-${{ inputs.channel }}-${{ runner.arch }}-${{ inputs.cache-key }}
31+
- run: $GITHUB_ACTION_PATH/setup.sh ${{ inputs.version }} ${{ inputs.channel }}
1932
shell: bash

setup.sh

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

3-
# Parse SDK and version args
4-
CHANNEL="${1:-stable}"
5-
VERSION="${3:-2.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_VERSION=${1:-3.0.2}
9+
FLUTTER_CHANNEL=${2:-stable}
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+
DOWNLOAD_PATH="/tmp/${FLUTTER_BUILD}"
63+
curl --connect-timeout 15 --retry 5 "$FLUTTER_DOWNLOAD_URL" > ${DOWNLOAD_PATH}
64+
65+
# Prepare tool cache folder
66+
mkdir -p "${FLUTTER_RUNNER_TOOL_CACHE}"
67+
68+
# Extracting installation archive
69+
if [[ $OS == linux ]]
70+
then
71+
tar -C "${FLUTTER_RUNNER_TOOL_CACHE}" -xf ${DOWNLOAD_PATH} > /dev/null
72+
else
73+
unzip ${DOWNLOAD_PATH} -d "${FLUTTER_RUNNER_TOOL_CACHE}" > /dev/null
74+
fi
75+
76+
if [ $? -ne 0 ]; then
77+
echo -e "::error::Download failed! Please check passed arguments."
78+
exit 1
79+
fi
80+
else
81+
echo "Cache restored Flutter SDK version \"${FLUTTER_VERSION}\" from the ${FLUTTER_CHANNEL} channel on ${FLUTTER_OS}"
5282
fi
5383

5484
# Configure pub to use a fixed location.

0 commit comments

Comments
 (0)