1
0
Fork 0
mirror of https://github.com/subosito/flutter-action.git synced 2024-08-16 10:19:50 +02:00

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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 14 deletions

View file

@ -62,7 +62,7 @@ steps:
java-version: '11' java-version: '11'
- uses: subosito/flutter-action@v2 - uses: subosito/flutter-action@v2
with: with:
flutter-version: '2.5.3' flutter-version: '2.10.4'
- run: flutter pub get - run: flutter pub get
- run: flutter test - run: flutter test
- run: flutter build apk - run: flutter build apk
@ -79,7 +79,8 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: subosito/flutter-action@v2 - uses: subosito/flutter-action@v2
with: with:
flutter-version: '2.5.3' flutter-version: '2.10.4'
architecture: x64
- run: flutter pub get - run: flutter pub get
- run: flutter test - run: flutter test
- run: flutter build ios --release --no-codesign - run: flutter build ios --release --no-codesign
@ -92,7 +93,7 @@ steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: subosito/flutter-action@v2 - uses: subosito/flutter-action@v2
with: with:
flutter-version: '2.5.3' flutter-version: '2.10.4'
- run: flutter pub get - run: flutter pub get
- run: flutter test - run: flutter test
- run: flutter build web - run: flutter build web
@ -142,6 +143,7 @@ jobs:
- uses: subosito/flutter-action@v2 - uses: subosito/flutter-action@v2
with: with:
channel: 'beta' channel: 'beta'
architecture: x64
- run: flutter config --enable-macos-desktop - run: flutter config --enable-macos-desktop
- run: flutter build macos - run: flutter build macos
``` ```
@ -153,10 +155,11 @@ steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: subosito/flutter-action@v2 - uses: subosito/flutter-action@v2
with: with:
flutter-version: '2.5.0' flutter-version: '2.10.x'
channel: 'stable' channel: 'stable'
cache: true cache: true
cache-key: flutter # optional, change this to force refresh cache cache-key: flutter # optional, change this to force refresh cache
cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path
architecture: x64 # optional, x64 or arm64
- run: flutter --version - run: flutter --version
``` ```

View file

@ -8,6 +8,7 @@ inputs:
flutter-version: flutter-version:
description: 'The Flutter version to make available on the path' description: 'The Flutter version to make available on the path'
required: false required: false
default: 'any'
channel: channel:
description: 'The Flutter build release channel' description: 'The Flutter build release channel'
required: false required: false
@ -23,6 +24,10 @@ inputs:
description: 'Flutter SDK cache path' description: 'Flutter SDK cache path'
required: false required: false
default: ${{ runner.tool_cache }}/flutter default: ${{ runner.tool_cache }}/flutter
architecture:
description: 'The architecture of Flutter SDK executable (x64 or arm64)'
required: false
default: 'x64'
runs: runs:
using: 'composite' using: 'composite'
steps: steps:
@ -31,5 +36,5 @@ runs:
with: with:
path: ${{ inputs.cache-path }} path: ${{ inputs.cache-path }}
key: ${{ inputs.cache-key }}-${{ inputs.channel }}-${{ inputs.flutter-version }} 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 shell: bash

View file

@ -14,19 +14,25 @@ normalize_version() {
} }
latest_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() { wildcard_version() {
if [ $2 == *"v"* ]; then # is legacy version format
if [[ $1 == any ]]; then if [[ $1 == any ]]; then
jq --arg version "^$2" '.releases | map(select(.version | test($version))) | first' jq --arg version "$2" '.releases | map(select(.version | startswith($version) )) | first'
else 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" '.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" --arg arch "$ARCH" '.releases | map(select(.channel==$channel) | select(.version | startswith($version) ) | select(.dart_sdk_arch == null or .dart_sdk_arch == $arch)) | first'
fi fi
} }
get_version() { get_version() {
if [[ -z $2 ]]; then if [[ $2 == any ]]; then
latest_version $1 latest_version $1
else else
wildcard_version $1 $2 wildcard_version $1 $2
@ -89,6 +95,7 @@ done
CHANNEL="${@:$OPTIND:1}" CHANNEL="${@:$OPTIND:1}"
VERSION="${@:$OPTIND+1:1}" VERSION="${@:$OPTIND+1:1}"
ARCH="${@:$OPTIND+2:1}"
SDK_CACHE="$(transform_path ${CACHE_PATH})" SDK_CACHE="$(transform_path ${CACHE_PATH})"
PUB_CACHE="$(transform_path ${CACHE_PATH}/.pub-cache)" 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" git clone -b master https://github.com/flutter/flutter.git "$SDK_CACHE"
else else
VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION) VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION)
if [[ $VERSION_MANIFEST == null ]]; then 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 exit 1
fi fi
ARCHIVE_PATH=$(echo $VERSION_MANIFEST | jq -r '.archive') ARCHIVE_PATH=$(echo $VERSION_MANIFEST | jq -r '.archive')
download_archive "$ARCHIVE_PATH" "$SDK_CACHE" download_archive "$ARCHIVE_PATH" "$SDK_CACHE"
fi fi