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

make simpler

This commit is contained in:
Alif Rachmawadi 2023-03-21 21:37:50 +07:00
parent 37734c707c
commit ed0e860e8f
No known key found for this signature in database
3 changed files with 46 additions and 119 deletions

View file

@ -93,7 +93,7 @@ jobs:
shell: bash shell: bash
- run: ./setup.sh -t -p -n 0 any | grep 'beta' - run: ./setup.sh -t -p -n 0 any | grep 'beta'
shell: bash shell: bash
- run: ./setup.sh -t -p -n 0 any | grep 'v0.11.13' - run: ./setup.sh -t -p -n 0 any | grep '0.11.13'
shell: bash shell: bash
- run: ./setup.sh -t -p | grep 'flutter-macos-stable-3.7.7-x64-2ad6cd72c040113b47ee9055e722606a490ef0da' - run: ./setup.sh -t -p | grep 'flutter-macos-stable-3.7.7-x64-2ad6cd72c040113b47ee9055e722606a490ef0da'
shell: bash shell: bash
@ -105,7 +105,7 @@ jobs:
shell: bash shell: bash
- run: ./setup.sh -t -p -n 1 any | grep 'flutter-macos-beta-1.26.0-17.8.pre-x64-044f2cf5607a26f8818dab0f766400e85c52bdff' - run: ./setup.sh -t -p -n 1 any | grep 'flutter-macos-beta-1.26.0-17.8.pre-x64-044f2cf5607a26f8818dab0f766400e85c52bdff'
shell: bash shell: bash
- run: ./setup.sh -t -p -n 0 any | grep 'flutter-macos-beta-v0.11.13-x64-58c8489fcdb4e4ef6c010117584c9b23d15221aa' - run: ./setup.sh -t -p -n 0 any | grep 'flutter-macos-beta-0.11.13-x64-58c8489fcdb4e4ef6c010117584c9b23d15221aa'
shell: bash shell: bash
- run: ./setup.sh -t -p | grep '/Users/runner/work/_temp/flutter/stable-3.7.7-x64' - run: ./setup.sh -t -p | grep '/Users/runner/work/_temp/flutter/stable-3.7.7-x64'
shell: bash shell: bash

View file

@ -11,7 +11,7 @@ steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: subosito/flutter-action@v2 - uses: subosito/flutter-action@v2
with: with:
flutter-version: '3.0.5' flutter-version: '3.7.7'
channel: 'stable' channel: 'stable'
- run: flutter --version - run: flutter --version
``` ```
@ -23,7 +23,7 @@ steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: subosito/flutter-action@v2 - uses: subosito/flutter-action@v2
with: with:
channel: 'stable' # or: 'beta', 'dev' or 'master' channel: 'stable' # or: 'beta' or 'dev'
- run: flutter --version - run: flutter --version
``` ```
@ -34,7 +34,7 @@ steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: subosito/flutter-action@v2 - uses: subosito/flutter-action@v2
with: with:
flutter-version: '1.22.x' # or, you can use 1.22 flutter-version: '1.22.x'
channel: 'dev' channel: 'dev'
- run: flutter --version - run: flutter --version
``` ```
@ -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: '3.0.5' flutter-version: '3.7.7'
- run: flutter pub get - run: flutter pub get
- run: flutter test - run: flutter test
- run: flutter build apk - run: flutter build apk

153
setup.sh
View file

@ -11,41 +11,19 @@ fi
OS_NAME=$(echo "$RUNNER_OS" | awk '{print tolower($0)}') OS_NAME=$(echo "$RUNNER_OS" | awk '{print tolower($0)}')
MANIFEST_BASE_URL="https://storage.googleapis.com/flutter_infra_release/releases" MANIFEST_BASE_URL="https://storage.googleapis.com/flutter_infra_release/releases"
MANIFEST_URL="$MANIFEST_BASE_URL/releases_$OS_NAME.json" MANIFEST_JSON_PATH="releases_$OS_NAME.json"
MANIFEST_TEST_FIXTURE="$(dirname -- "${BASH_SOURCE[0]}")/test/releases_$OS_NAME.json" MANIFEST_URL="$MANIFEST_BASE_URL/$MANIFEST_JSON_PATH"
legacy_wildcard_version() { filter_by_channel() {
if [[ $1 == any ]]; then jq --arg channel "$1" '[.releases[] | select($channel == "any" or .channel == $channel)]'
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
} }
wildcard_version() { filter_by_arch() {
if [[ $1 == any ]]; then jq --arg dart_sdk_arch "$1" '[.[] | select(.dart_sdk_arch? | (., "x64") | index($dart_sdk_arch))]'
jq --arg version "$2" --arg arch "$3" '.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 "$3" '.releases | map(select(.channel==$channel) | select(.version | startswith($version) ) | select(.dart_sdk_arch == null or .dart_sdk_arch == $arch)) | first'
fi
} }
get_version() { filter_by_version() {
if [[ "$1" == any && "$2" == any ]]; then # latest_version jq --arg version "$1" '.[].version |= gsub("^v"; "") | (if $version == "any" then .[0] else (map(select(.version == $version or (.version | startswith(($version | sub("\\.x$"; "")) + ".")) and .version != $version)) | .[0]) end)'
jq --arg arch "$3" '.releases | map(select(.dart_sdk_arch == null or .dart_sdk_arch == $arch)) | first'
elif [[ "$2" == any ]]; then # latest channel version
jq --arg channel "$1" --arg arch "$3" '.releases | map(select(.channel==$channel) | select(.dart_sdk_arch == null or .dart_sdk_arch == $arch)) | first'
else
wildcard_version "$1" "$2" "$3"
fi
}
normalize_version() {
if [[ "$1" == *.x ]]; then
echo "${1/.x/}"
else
echo "$1"
fi
} }
not_found_error() { not_found_error() {
@ -86,8 +64,8 @@ download_archive() {
CACHE_PATH="" CACHE_PATH=""
CACHE_KEY="" CACHE_KEY=""
PRINT_MODE="" PRINT_ONLY=""
USE_TEST_FIXTURE=false TEST_MODE=false
ARCH="" ARCH=""
VERSION="" VERSION=""
@ -95,8 +73,8 @@ while getopts 'tc:k:pa:n:' flag; do
case "$flag" in case "$flag" in
c) CACHE_PATH="$OPTARG" ;; c) CACHE_PATH="$OPTARG" ;;
k) CACHE_KEY="$OPTARG" ;; k) CACHE_KEY="$OPTARG" ;;
p) PRINT_MODE=true ;; p) PRINT_ONLY=true ;;
t) USE_TEST_FIXTURE=true ;; t) TEST_MODE=true ;;
a) ARCH="$(echo "$OPTARG" | awk '{print tolower($0)}')" ;; a) ARCH="$(echo "$OPTARG" | awk '{print tolower($0)}')" ;;
n) VERSION="$OPTARG" ;; n) VERSION="$OPTARG" ;;
?) exit 2 ;; ?) exit 2 ;;
@ -112,34 +90,23 @@ CHANNEL="${ARR_CHANNEL[0]}"
[[ -z $CACHE_PATH ]] && CACHE_PATH="$RUNNER_TEMP/flutter/:channel:-:version:-:arch:" [[ -z $CACHE_PATH ]] && CACHE_PATH="$RUNNER_TEMP/flutter/:channel:-:version:-:arch:"
[[ -z $CACHE_KEY ]] && CACHE_KEY="flutter-:os:-:channel:-:version:-:arch:-:hash:" [[ -z $CACHE_KEY ]] && CACHE_KEY="flutter-:os:-:channel:-:version:-:arch:-:hash:"
RELEASE_MANIFEST="" if [[ "$TEST_MODE" == true ]]; then
VERSION_MANIFEST="" RELEASE_MANIFEST=$(cat "$(dirname -- "${BASH_SOURCE[0]}")/test/$MANIFEST_JSON_PATH")
else
RELEASE_MANIFEST=$(curl --silent --connect-timeout 15 --retry 5 "$MANIFEST_URL")
fi
get_version_manifest() { VERSION_MANIFEST=$(echo "$RELEASE_MANIFEST" | filter_by_channel "$CHANNEL" | filter_by_arch "$ARCH" | filter_by_version "$VERSION")
version_normalized=$(normalize_version "$VERSION")
version_manifest=$(echo "$RELEASE_MANIFEST" | get_version "$CHANNEL" "$version_normalized" "$ARCH")
if [[ "$version_manifest" == null ]]; then if [[ "$VERSION_MANIFEST" == *null* ]]; then
version_manifest=$(echo "$RELEASE_MANIFEST" | legacy_wildcard_version "$CHANNEL" "v$version_normalized") not_found_error "$CHANNEL" "$VERSION" "$ARCH"
fi exit 1
fi
version_arch=$(echo "$version_manifest" | jq -r '.dart_sdk_arch')
if [[ "$version_arch" == null ]]; then
if [[ "$ARCH" == x64 ]]; then
echo "$version_manifest" | jq --arg dart_sdk_arch x64 '.+={dart_sdk_arch:$dart_sdk_arch}'
else
echo ""
fi
else
echo "$version_manifest"
fi
}
expand_key() { expand_key() {
version_channel=$(echo "$VERSION_MANIFEST" | jq -r '.channel') version_channel=$(echo "$VERSION_MANIFEST" | jq -r '.channel')
version_version=$(echo "$VERSION_MANIFEST" | jq -r '.version') version_version=$(echo "$VERSION_MANIFEST" | jq -r '.version')
version_arch=$(echo "$VERSION_MANIFEST" | jq -r '.dart_sdk_arch') version_arch=$(echo "$VERSION_MANIFEST" | jq -r '.dart_sdk_arch // "x64"')
version_hash=$(echo "$VERSION_MANIFEST" | jq -r '.hash') version_hash=$(echo "$VERSION_MANIFEST" | jq -r '.hash')
version_sha_256=$(echo "$VERSION_MANIFEST" | jq -r '.sha256') version_sha_256=$(echo "$VERSION_MANIFEST" | jq -r '.sha256')
@ -153,44 +120,22 @@ expand_key() {
echo "$expanded_key" echo "$expanded_key"
} }
if [[ "$PRINT_MODE" == true ]]; then CACHE_KEY=$(expand_key "$CACHE_KEY")
if [[ "$USE_TEST_FIXTURE" == true ]]; then CACHE_PATH=$(expand_key "$(transform_path "$CACHE_PATH")")
RELEASE_MANIFEST=$(cat "$MANIFEST_TEST_FIXTURE")
else
RELEASE_MANIFEST=$(curl --silent --connect-timeout 15 --retry 5 "$MANIFEST_URL")
fi
if [[ "$CHANNEL" == master ]]; then if [[ "$PRINT_ONLY" == true ]]; then
VERSION_MANIFEST="{\"channel\":\"$CHANNEL\",\"version\":\"$CHANNEL\",\"dart_sdk_arch\":\"$ARCH\",\"hash\":\"$CHANNEL\",\"sha256\":\"$CHANNEL\"}" version_info=$(echo "$VERSION_MANIFEST" | jq -j '.channel,":",.version,":",.dart_sdk_arch // "x64"')
else
VERSION_MANIFEST=$(get_version_manifest)
fi
if [[ -z "$VERSION_MANIFEST" ]]; then
not_found_error "$CHANNEL" "$VERSION" "$ARCH"
exit 1
fi
version_info=$(echo "$VERSION_MANIFEST" | jq -j '.channel,":",.version,":",.dart_sdk_arch')
if [[ "$version_info" == *null* ]]; then
not_found_error "$CHANNEL" "$VERSION" "$ARCH"
exit 1
fi
info_channel=$(echo "$version_info" | awk -F ':' '{print $1}') info_channel=$(echo "$version_info" | awk -F ':' '{print $1}')
info_version=$(echo "$version_info" | awk -F ':' '{print $2}') info_version=$(echo "$version_info" | awk -F ':' '{print $2}')
info_architecture=$(echo "$version_info" | awk -F ':' '{print $3}') info_architecture=$(echo "$version_info" | awk -F ':' '{print $3}')
expanded_key=$(expand_key "$CACHE_KEY")
cache_path=$(transform_path "$CACHE_PATH")
expanded_path=$(expand_key "$cache_path")
if [[ "$USE_TEST_FIXTURE" == true ]]; then if [[ "$TEST_MODE" == true ]]; then
echo "CHANNEL=$info_channel" echo "CHANNEL=$info_channel"
echo "VERSION=$info_version" echo "VERSION=$info_version"
echo "ARCHITECTURE=$info_architecture" echo "ARCHITECTURE=$info_architecture"
echo "CACHE-KEY=$expanded_key" echo "CACHE-KEY=$CACHE_KEY"
echo "CACHE-PATH=$expanded_path" echo "CACHE-PATH=$CACHE_PATH"
exit 0 exit 0
fi fi
@ -199,40 +144,22 @@ if [[ "$PRINT_MODE" == true ]]; then
echo "VERSION=$info_version" echo "VERSION=$info_version"
echo "ARCHITECTURE=$info_architecture" echo "ARCHITECTURE=$info_architecture"
echo "CACHE-KEY=$expanded_key" echo "CACHE-KEY=$expanded_key"
echo "CACHE-PATH=$expanded_path" echo "CACHE-PATH=$CACHE_PATH"
} >> "$GITHUB_OUTPUT" } >>"$GITHUB_OUTPUT"
exit 0
fi fi
CACHE_PATH=$(transform_path "$CACHE_PATH") if [[ ! -x "$CACHE_PATH/bin/flutter" ]]; then
SDK_CACHE=$(expand_key "$CACHE_PATH") archive_url=$(echo "$VERSION_MANIFEST" | jq -r '.archive')
PUB_CACHE=$(expand_key "$SDK_CACHE/.pub-cache") download_archive "$archive_url" "$CACHE_PATH"
if [[ ! -x "$SDK_CACHE/bin/flutter" ]]; then
if [[ $CHANNEL == master ]]; then
git clone -b master https://github.com/flutter/flutter.git "$SDK_CACHE"
else
RELEASE_MANIFEST=$(curl --silent --connect-timeout 15 --retry 5 "$MANIFEST_URL")
VERSION_MANIFEST=$(get_version_manifest)
if [[ -z "$VERSION_MANIFEST" ]]; then
not_found_error "$CHANNEL" "$VERSION" "$ARCH"
exit 1
fi
ARCHIVE_PATH=$(echo "$VERSION_MANIFEST" | jq -r '.archive')
download_archive "$ARCHIVE_PATH" "$SDK_CACHE"
fi
fi fi
{ {
echo "FLUTTER_ROOT=$SDK_CACHE" echo "FLUTTER_ROOT=$CACHE_PATH"
echo "PUB_CACHE=$PUB_CACHE" echo "PUB_CACHE=$CACHE_PATH/.pub-cache"
} >>"$GITHUB_ENV" } >>"$GITHUB_ENV"
{ {
echo "$SDK_CACHE/bin" echo "$CACHE_PATH/bin"
echo "$SDK_CACHE/bin/cache/dart-sdk/bin" echo "$CACHE_PATH/bin/cache/dart-sdk/bin"
echo "$PUB_CACHE/bin" echo "$CACHE_PATH/.pub-cache/bin"
} >>"$GITHUB_PATH" } >>"$GITHUB_PATH"