Skip to content

Re-write action to support cache and Apple Silicon #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 7 additions & 38 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ on:
branches: [main]

jobs:
test:
test-stable:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# Test latest stable, beta, dev, and main channels + last stable release
# prior to the introduction of the unified `dart` developer tool.
sdk: [stable, beta]
version: [3.0.2, 3.0.1, 3.0.0, 2.10.5]
steps:
- uses: actions/checkout@v2
- uses: ./
with:
sdk: ${{ matrix.sdk }}
channel: stable
version: ${{ matrix.version }}

- name: Dart version
run: dart --version
Expand All @@ -32,21 +31,18 @@ jobs:
echo "main() { print('hello world'); }" > hello.dart
dart hello.dart

test-dev:
test-beta:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# Test latest stable, beta, dev, and main channels + last stable release
# prior to the introduction of the unified `dart` developer tool.
sdk: [dev]
version: ["2.1.0-12.1.pre"]
version: [3.1.0, 3.1.0-9.0.pre]
steps:
- uses: actions/checkout@v2
- uses: ./
with:
sdk: ${{ matrix.sdk }}
channel: beta
version: ${{ matrix.version }}

- name: Dart version
Expand All @@ -58,30 +54,3 @@ jobs:
run: |
echo "main() { print('hello world'); }" > hello.dart
dart hello.dart

test_pub:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
sdk: [stable, beta]
steps:
- uses: actions/checkout@v2
- uses: ./
with:
sdk: ${{ matrix.sdk }}

- name: Dart version
run: dart --version
- name: Flutter version
run: flutter --version

- name: Global activate + run
run: |
dart pub global activate stagehand
mkdir testapp
cd testapp
stagehand console-simple
dart pub get
dart run
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ This [GitHub Action]() installs and sets up of a Flutter SDK for use in actions
## Inputs

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

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

## Basic example

Expand All @@ -35,10 +35,10 @@ jobs:
- uses: actions/checkout@v2

- name: Setup Flutter SDK
uses: flutter-actions/setup-flutter@v1
uses: flutter-actions/setup-flutter@v2
with:
sdk: stable
version: 2.0.2
channel: stable
version: 3.0.2

- name: Install dependencies
run: flutter pub get
Expand Down Expand Up @@ -77,10 +77,10 @@ jobs:
uses: android-actions/setup-android@v2

- name: Setup Flutter SDK
uses: flutter-actions/setup-flutter@v1
uses: flutter-actions/setup-flutter@v2
with:
sdk: stable
version: 2.0.2
channel: stable
version: 3.0.2

- name: Install dependencies
run: flutter pub get
Expand Down
27 changes: 20 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@ branding:
icon: "triangle"
color: "blue"
inputs:
sdk:
description: "The channel to install ('stable', 'beta', 'dev')."
version:
description: "The version to install: Default: 3.0.2"
required: false
default: "3.0.2"
channel:
description: "The version to install. Default: stable"
required: false
default: "stable"
version:
description: "The version to install"
required: false
default: "2.0.2"
cache:
description: 'Cache the installed Flutter SDK. Default: false'
required: false
default: "false"
cache-key:
description: "An explicit key for restoring and saving the Flutter SDK to/from cache"
required: false
default: "flutter"
runs:
using: "composite"
steps:
- run: $GITHUB_ACTION_PATH/setup.sh ${{ inputs.sdk }} ${{ runner.os }} ${{ inputs.version }}
- if: ${{ inputs.cache == 'true' }}
uses: actions/cache@v3
with:
path: ${{ runner.tool_cache }}/flutter-${{ runner.os }}-${{ inputs.version }}-${{ runner.arch }}
key: flutter-action-setup-flutter-${{ runner.os }}-${{ inputs.version }}-${{ inputs.channel }}-${{ runner.arch }}-${{ inputs.cache-key }}
- run: $GITHUB_ACTION_PATH/setup.sh ${{ inputs.version }} ${{ inputs.channel }}
shell: bash
102 changes: 66 additions & 36 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,54 +1,84 @@
#!/bin/bash

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

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

# OS archive file extension
EXT="zip"
if [[ $OS == linux ]]
then
EXT="tar.xz"
EXT="tar.xz"
fi

# Apple Intel or Apple Silicon
if [[ $OS == macos ]]
then
if [[ $ARCH == 'arm64' ]]
then
FLUTTER_ARCH="_$ARCH"
fi
fi

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

# Check if Flutter SDK already exists
# Otherwise download and install
# https://storage.googleapis.com/flutter_infra_release/releases/stable/macos/flutter_macos_arm64_3.0.2-stable.zip
FLUTTER_RELEASE_URL="https://storage.googleapis.com/flutter_infra_release/releases"


if [ ! -d "${FLUTTER_RUNNER_TOOL_CACHE}" ]; then
echo "Installing Flutter SDK version \"${VERSION}\" from the ${CHANNEL} channel on ${OS}"

# Calculate download Url. Based on:
# https://flutter.dev/docs/development/tools/sdk/releases
PREFIX="https://storage.googleapis.com/flutter_infra_release/releases"
BUILD="flutter_${OS}_${VERSION}-${CHANNEL}.${EXT}"

URL="${PREFIX}/${CHANNEL}/${OS}/${BUILD}"
echo "Downloading ${URL}..."

# Download installation archive
curl --connect-timeout 15 --retry 5 "$URL" > "/tmp/${BUILD}"

# Prepare tool cache folder
mkdir -p "${FLUTTER_RUNNER_TOOL_CACHE}"

# Extracting installation archive
if [[ $OS == linux ]]
then
tar -C "${FLUTTER_RUNNER_TOOL_CACHE}" -xf "/tmp/${BUILD}" > /dev/null
else
unzip "/tmp/${BUILD}" -d "${FLUTTER_RUNNER_TOOL_CACHE}" > /dev/null
fi

if [ $? -ne 0 ]; then
echo -e "::error::Download failed! Please check passed arguments."
exit 1
fi
echo "Installing Flutter SDK version \"${FLUTTER_VERSION}\" from the ${FLUTTER_CHANNEL} channel on ${FLUTTER_OS}"

# Linux
# /stable /linux/ flutter_linux_2.10.2-stable.tar.xz
# /beta /linux/ flutter_linux_3.1.0-9.0.pre-beta.tar.xz

# macOS
# /stable /macos/ flutter_macos_3.0.2-stable.zip
# /stable /macos/ flutter_macos_arm64_3.0.2-stable.zip
# /beta /macos/ flutter_macos_arm64_3.1.0-9.0.pre-beta.zip
# /beta /macos/ flutter_macos_3.1.0-9.0.pre-beta.zip

# Windows
# /stable /windows/ flutter_windows_3.0.2-stable.zip
# /beta /windows/ flutter_windows_3.1.0-9.0.pre-beta.zip
FLUTTER_BUILD="flutter_${FLUTTER_OS}${FLUTTER_ARCH}_${FLUTTER_VERSION}-${FLUTTER_CHANNEL}.${EXT}"
FLUTTER_DOWNLOAD_URL="${FLUTTER_RELEASE_URL}/${FLUTTER_CHANNEL}/${FLUTTER_OS}/${FLUTTER_BUILD}"

echo "Downloading ${FLUTTER_DOWNLOAD_URL}"

# Download installation archive
DOWNLOAD_PATH="/tmp/${FLUTTER_BUILD}"
curl --connect-timeout 15 --retry 5 "$FLUTTER_DOWNLOAD_URL" > ${DOWNLOAD_PATH}

# Prepare tool cache folder
mkdir -p "${FLUTTER_RUNNER_TOOL_CACHE}"

# Extracting installation archive
if [[ $OS == linux ]]
then
tar -C "${FLUTTER_RUNNER_TOOL_CACHE}" -xf ${DOWNLOAD_PATH} > /dev/null
else
unzip ${DOWNLOAD_PATH} -d "${FLUTTER_RUNNER_TOOL_CACHE}" > /dev/null
fi

if [ $? -ne 0 ]; then
echo -e "::error::Download failed! Please check passed arguments."
exit 1
fi
else
echo "Cache restored Flutter SDK version \"${FLUTTER_VERSION}\" from the ${FLUTTER_CHANNEL} channel on ${FLUTTER_OS}"
fi

# Configure pub to use a fixed location.
Expand Down