feat: support to set architecture of SDK executable (#147)

* 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
This commit is contained in:
菘菘
2022-04-19 17:08:46 +08:00
committed by GitHub
parent f0cc0311e0
commit 6a13bd0836
3 changed files with 27 additions and 14 deletions

View File

@@ -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
@@ -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
@@ -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
@@ -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
```
@@ -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
```

View File

@@ -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
@@ -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:
@@ -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

View File

@@ -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
@@ -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)"
@@ -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