Skip to content

Commit

Permalink
feat: support to set architecture of SDK executable (#147)
Browse files Browse the repository at this point in the history
* feat: support to set architecture of SDK executable

* docs: update

* fix: try fix tests

* ci: set `fail-fast` to false

* fix: get latest version sdk

* fix: test any version

* fix: legacy version format

* fix: tests

* revert changes for `.github/workflows/workflow.yml`

* Update workflow.yml

* rename `ARCHITECTURE` to `ARCH`

* follow the existing spacing

* style: simplified code

* Update setup.sh

* style
  • Loading branch information
SiongSng committed Apr 19, 2022
1 parent f0cc031 commit 6a13bd0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
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
23 changes: 14 additions & 9 deletions setup.sh
Expand Up @@ -14,19 +14,25 @@ normalize_version() {
}

latest_version() {
jq --arg channel "$1" '.releases | map(select(.channel==$channel)) | first'
jq --arg channel "$1" --arg arch "$ARCH" '.releases | map(select(.channel==$channel) | select(.dart_sdk_arch == null or .dart_sdk_arch == $arch)) | first'
}

wildcard_version() {
if [[ $1 == any ]]; then
jq --arg version "^$2" '.releases | map(select(.version | test($version))) | first'
if [ $2 == *"v"* ]; then # is legacy version format
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 arch "$ARCH" '.releases | map(select(.version | startswith($version)) | select(.dart_sdk_arch == null or .dart_sdk_arch == $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 arch "$ARCH" '.releases | map(select(.channel==$channel) | select(.version | startswith($version) ) | select(.dart_sdk_arch == null or .dart_sdk_arch == $arch)) | first'
fi
}

get_version() {
if [[ -z $2 ]]; then
if [[ $2 == any ]]; then
latest_version $1
else
wildcard_version $1 $2
Expand Down Expand Up @@ -89,6 +95,7 @@ done

CHANNEL="${@:$OPTIND:1}"
VERSION="${@:$OPTIND+1:1}"
ARCH="${@:$OPTIND+2:1}"

SDK_CACHE="$(transform_path ${CACHE_PATH})"
PUB_CACHE="$(transform_path ${CACHE_PATH}/.pub-cache)"
Expand All @@ -98,12 +105,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"
echo "Unable to determine Flutter version for channel: $CHANNEL version: $VERSION architecture: $ARCH"
exit 1
fi

fi
ARCHIVE_PATH=$(echo $VERSION_MANIFEST | jq -r '.archive')
download_archive "$ARCHIVE_PATH" "$SDK_CACHE"
fi
Expand Down

0 comments on commit 6a13bd0

Please sign in to comment.