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
- run: ./setup.sh -t -p -n 0 any | grep 'beta'
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
- run: ./setup.sh -t -p | grep 'flutter-macos-stable-3.7.7-x64-2ad6cd72c040113b47ee9055e722606a490ef0da'
shell: bash
@ -105,7 +105,7 @@ jobs:
shell: bash
- run: ./setup.sh -t -p -n 1 any | grep 'flutter-macos-beta-1.26.0-17.8.pre-x64-044f2cf5607a26f8818dab0f766400e85c52bdff'
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
- run: ./setup.sh -t -p | grep '/Users/runner/work/_temp/flutter/stable-3.7.7-x64'
shell: bash

View file

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

153
setup.sh
View file

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