Skip to content
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

feat: support to set architecture of SDK executable #147

Merged
merged 15 commits into from Apr 19, 2022
139 changes: 71 additions & 68 deletions .github/workflows/workflow.yml
Expand Up @@ -10,92 +10,95 @@ jobs:
test_channel:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
channel: [stable, beta]
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: ./
with:
channel: ${{ matrix.channel }}
- name: Print FLUTTER_ROOT
shell: bash
run: echo "FLUTTER_ROOT set to $FLUTTER_ROOT"
- name: Print PUB_CACHE
shell: bash
run: echo "PUB_CACHE set to $PUB_CACHE"
- name: Run dart --version
shell: bash
run: dart --version
- name: Run flutter --version
shell: bash
run: flutter --version
- name: Checkout
uses: actions/checkout@v2
- uses: ./
with:
channel: ${{ matrix.channel }}
- name: Print FLUTTER_ROOT
shell: bash
run: echo "FLUTTER_ROOT set to $FLUTTER_ROOT"
- name: Print PUB_CACHE
shell: bash
run: echo "PUB_CACHE set to $PUB_CACHE"
- name: Run dart --version
shell: bash
run: dart --version
- name: Run flutter --version
shell: bash
run: flutter --version
test_version:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: [ 2.5.3, 2.x, 1, v1.12 ]
version: [2.5.3, 2.x, 1, v1.12]
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: ./
with:
channel: stable
flutter-version: ${{ matrix.version }}
- name: Run dart --version
shell: bash
run: dart --version
- name: Run flutter --version
shell: bash
run: flutter --version
- name: Checkout
uses: actions/checkout@v2
- uses: ./
with:
channel: stable
flutter-version: ${{ matrix.version }}
- name: Run dart --version
shell: bash
run: dart --version
- name: Run flutter --version
shell: bash
run: flutter --version
test_master_channel:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: ./
with:
channel: master
- name: Run dart --version
shell: bash
run: dart --version
- name: Run flutter --version
shell: bash
run: flutter --version
- name: Checkout
uses: actions/checkout@v2
- uses: ./
with:
channel: master
- name: Run dart --version
shell: bash
run: dart --version
- name: Run flutter --version
shell: bash
run: flutter --version
test_any_channel:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: ./
with:
channel: any
flutter-version: 2
- name: Run dart --version
shell: bash
run: dart --version
- name: Run flutter --version
shell: bash
run: flutter --version
- name: Checkout
uses: actions/checkout@v2
- uses: ./
with:
channel: any
flutter-version: 2
- name: Run dart --version
shell: bash
run: dart --version
- name: Run flutter --version
shell: bash
run: flutter --version
test_cache:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: ./
with:
channel: stable
flutter-version: 2.5.0
cache: true
cache-key: key-20220113
cache-path: ${{ runner.tool_cache }}/flutter/2.5.0-stable
- name: Run dart --version
shell: bash
run: dart --version
- name: Run flutter --version
shell: bash
run: flutter --version
- name: Checkout
uses: actions/checkout@v2
- uses: ./
with:
channel: stable
flutter-version: 2.5.0
cache: true
cache-key: key-20220113
cache-path: ${{ runner.tool_cache }}/flutter/2.5.0-stable
- name: Run dart --version
shell: bash
run: dart --version
- name: Run flutter --version
shell: bash
run: flutter --version
11 changes: 7 additions & 4 deletions README.md
Expand Up @@ -62,7 +62,7 @@ steps:
java-version: '11'
- uses: subosito/flutter-action@v2
with:
flutter-version: '2.5.3'
flutter-version: '2.10.4'
- run: flutter pub get
- run: flutter test
- run: flutter build apk
Expand All @@ -79,7 +79,8 @@ jobs:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v2
with:
flutter-version: '2.5.3'
flutter-version: '2.10.4'
architecture: x64
- run: flutter pub get
- run: flutter test
- run: flutter build ios --release --no-codesign
Expand All @@ -92,7 +93,7 @@ steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v2
with:
flutter-version: '2.5.3'
flutter-version: '2.10.4'
- run: flutter pub get
- run: flutter test
- run: flutter build web
Expand Down Expand Up @@ -142,6 +143,7 @@ jobs:
- uses: subosito/flutter-action@v2
with:
channel: 'beta'
architecture: x64
- run: flutter config --enable-macos-desktop
- run: flutter build macos
```
Expand All @@ -153,10 +155,11 @@ steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v2
with:
flutter-version: '2.5.0'
flutter-version: '2.10.x'
channel: 'stable'
cache: true
cache-key: flutter # optional, change this to force refresh cache
cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path
architecture: x64 # optional, x64 or arm64
- run: flutter --version
```
7 changes: 6 additions & 1 deletion action.yml
Expand Up @@ -8,6 +8,7 @@ inputs:
flutter-version:
description: 'The Flutter version to make available on the path'
required: false
default: 'any'
channel:
description: 'The Flutter build release channel'
required: false
Expand All @@ -23,6 +24,10 @@ inputs:
description: 'Flutter SDK cache path'
required: false
default: ${{ runner.tool_cache }}/flutter
architecture:
description: 'The architecture of Flutter SDK executable (x64 or arm64)'
required: false
default: 'x64'
runs:
using: 'composite'
steps:
Expand All @@ -31,5 +36,5 @@ runs:
with:
path: ${{ inputs.cache-path }}
key: ${{ inputs.cache-key }}-${{ inputs.channel }}-${{ inputs.flutter-version }}
- run: $GITHUB_ACTION_PATH/setup.sh -c "${{ inputs.cache-path }}" ${{ inputs.channel }} ${{ inputs.flutter-version }}
- run: $GITHUB_ACTION_PATH/setup.sh -c "${{ inputs.cache-path }}" ${{ inputs.channel }} ${{ inputs.flutter-version }} ${{ inputs.architecture }}
shell: bash
32 changes: 18 additions & 14 deletions setup.sh
Expand Up @@ -14,29 +14,34 @@ normalize_version() {
}

latest_version() {
jq --arg channel "$1" '.releases | map(select(.channel==$channel)) | first'
jq --arg channel "$1" --arg dart_sdk_arch "$ARCHITECTURE" '.releases | map(select(.channel==$channel) | select(.dart_sdk_arch==$dart_sdk_arch)) | first'
SiongSng marked this conversation as resolved.
Show resolved Hide resolved
}

wildcard_version() {
if [[ $1 == any ]]; then
jq --arg version "^$2" '.releases | map(select(.version | test($version))) | first'
if [[ $2 == *"v"* ]] || [[ $2 == 1 ]] || [[ $2 == 0 ]]; then # is legacy version format
SiongSng marked this conversation as resolved.
Show resolved Hide resolved
if [[ $1 == any ]]; then
jq --arg version "$2" '.releases | map(select(.version | startswith($version) )) | first'
else
jq --arg channel "$1" --arg version "$2" '.releases | map(select(.channel==$channel) | select(.version | startswith($version) )) | first'
fi
elif [[ $1 == any ]]; then
jq --arg version "$2" --arg dart_sdk_arch "$ARCHITECTURE" '.releases | map(select(.version | startswith($version)) | select(.dart_sdk_arch==$dart_sdk_arch)) | first'
else
jq --arg channel "$1" --arg version "^$2" '.releases | map(select(.channel==$channel) | select(.version | test($version))) | first'
jq --arg channel "$1" --arg version "$2" --arg dart_sdk_arch "$ARCHITECTURE" '.releases | map(select(.channel==$channel) | select(.version | startswith($version) ) | select(.dart_sdk_arch==$dart_sdk_arch)) | first'
fi
}

get_version() {
if [[ -z $2 ]]; then
if [[ $2 == any ]]; then
latest_version $1
else
wildcard_version $1 $2
fi
}

get_version_manifest() {
releases_manifest=$(curl --silent --connect-timeout 15 --retry 5 $MANIFEST_URL)
version_manifest=$(echo $releases_manifest | get_version $1 $(normalize_version $2))

releases_manifest=$(curl --silent --connect-timeout 15 --retry 5 $MANIFEST_URL)
SiongSng marked this conversation as resolved.
Show resolved Hide resolved
version_manifest=$(echo $releases_manifest | get_version $1 $(normalize_version $2))
if [[ $version_manifest == null ]]; then
# fallback through legacy version format
echo $releases_manifest | wildcard_version $1 "v$(normalize_version $2)"
Expand Down Expand Up @@ -89,6 +94,7 @@ done

CHANNEL="${@:$OPTIND:1}"
VERSION="${@:$OPTIND+1:1}"
ARCHITECTURE="${@:$OPTIND+2:1}"
SiongSng marked this conversation as resolved.
Show resolved Hide resolved

SDK_CACHE="$(transform_path ${CACHE_PATH})"
PUB_CACHE="$(transform_path ${CACHE_PATH}/.pub-cache)"
Expand All @@ -98,12 +104,10 @@ if [[ ! -x "${SDK_CACHE}/bin/flutter" ]]; then
git clone -b master https://github.com/flutter/flutter.git "$SDK_CACHE"
else
VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION)

if [[ $VERSION_MANIFEST == null ]]; then
echo "Unable to determine Flutter version for $CHANNEL $VERSION"
exit 1
fi

if [[ $VERSION_MANIFEST == null ]]; then
SiongSng marked this conversation as resolved.
Show resolved Hide resolved
echo "Unable to determine Flutter version for channel: $CHANNEL version: $VERSION architecture: $ARCHITECTURE"
exit 1
fi
ARCHIVE_PATH=$(echo $VERSION_MANIFEST | jq -r '.archive')
download_archive "$ARCHIVE_PATH" "$SDK_CACHE"
fi
Expand Down