mirror of
https://github.com/subosito/flutter-action.git
synced 2024-08-16 10:19:50 +02:00
tidy up
This commit is contained in:
parent
e09ab0131a
commit
d8cf9a8ccc
1 changed files with 91 additions and 93 deletions
184
setup.sh
184
setup.sh
|
@ -1,67 +1,64 @@
|
|||
#!/bin/bash
|
||||
|
||||
check_command() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
if ! check_command jq; then
|
||||
echo "jq not found, please install it, https://stedolan.github.io/jq/download/"
|
||||
exit 1
|
||||
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_PATH="test/releases_$OS_NAME.json"
|
||||
RELEASE_MANIFEST=""
|
||||
VERSION_MANIFEST=null
|
||||
MANIFEST_TEST_FIXTURE="test/releases_$OS_NAME.json"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
wildcard_version() {
|
||||
if [[ "${2::1}" == v ]]; then
|
||||
legacy_wildcard_version "$1" "$2"
|
||||
elif [[ $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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
# convert version like 2.5.x to 2.5
|
||||
normalize_version() {
|
||||
if [[ $1 == *.x ]]; then
|
||||
if [[ "$1" == *.x ]]; then
|
||||
echo "${1/.x/}"
|
||||
else
|
||||
echo "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
latest_version() {
|
||||
jq --arg arch "$ARCH" '.releases | map(select(.dart_sdk_arch == null or .dart_sdk_arch == $arch)) | first'
|
||||
not_found_error() {
|
||||
echo "Unable to determine Flutter version for channel: $1 version: $2 architecture: $3"
|
||||
}
|
||||
|
||||
latest_channel_version() {
|
||||
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 [[ $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'
|
||||
transform_path() {
|
||||
if [[ "$OS_NAME" == windows ]]; then
|
||||
echo "$1" | sed -e 's/^\///' -e 's/\//\\/g'
|
||||
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
|
||||
}
|
||||
|
||||
get_version() {
|
||||
if [[ $1 == any && $2 == any ]]; then
|
||||
latest_version
|
||||
elif [[ $2 == any ]]; then
|
||||
latest_channel_version "$1"
|
||||
else
|
||||
wildcard_version "$1" "$2"
|
||||
fi
|
||||
}
|
||||
|
||||
get_version_manifest() {
|
||||
version_manifest=$(echo "$RELEASE_MANIFEST" | get_version "$1" "$(normalize_version "$2")")
|
||||
|
||||
if [[ $version_manifest == null ]]; then
|
||||
# fallback through legacy version format
|
||||
version_manifest=$(echo "$RELEASE_MANIFEST" | wildcard_version "$1" "v$(normalize_version "$2")")
|
||||
fi
|
||||
|
||||
version_arch=$(echo "$version_manifest" | jq -r '.dart_sdk_arch')
|
||||
|
||||
if [[ "$version_arch" == null ]]; then
|
||||
echo "$version_manifest" | jq --arg dart_sdk_arch x64 '.+={dart_sdk_arch:$dart_sdk_arch}'
|
||||
else
|
||||
echo "$version_manifest"
|
||||
echo "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -75,7 +72,7 @@ download_archive() {
|
|||
# Create the target folder
|
||||
mkdir -p "$2"
|
||||
|
||||
if [[ $archive_name == *zip ]]; then
|
||||
if [[ "$archive_name" == *zip ]]; then
|
||||
unzip -q -o "$archive_local" -d "$RUNNER_TEMP"
|
||||
# Remove the folder again so that the move command can do a simple rename
|
||||
# instead of moving the content into the target folder.
|
||||
|
@ -90,44 +87,6 @@ download_archive() {
|
|||
rm "$archive_local"
|
||||
}
|
||||
|
||||
transform_path() {
|
||||
if [[ $OS_NAME == windows ]]; then
|
||||
echo "$1" | sed -e 's/^\///' -e 's/\//\\/g'
|
||||
else
|
||||
echo "$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_hash=$(echo "$VERSION_MANIFEST" | jq -r '.hash')
|
||||
version_sha_256=$(echo "$VERSION_MANIFEST" | jq -r '.sha256')
|
||||
|
||||
expanded_key="${1/:channel:/$version_channel}"
|
||||
expanded_key="${expanded_key/:version:/$version_version}"
|
||||
expanded_key="${expanded_key/:arch:/$version_arch}"
|
||||
expanded_key="${expanded_key/:hash:/$version_hash}"
|
||||
expanded_key="${expanded_key/:sha256:/$version_sha_256}"
|
||||
expanded_key="${expanded_key/:os:/$OS_NAME}"
|
||||
|
||||
echo "$expanded_key"
|
||||
}
|
||||
|
||||
not_found_error() {
|
||||
echo "Unable to determine Flutter version for channel: $1 version: $2 architecture: $3"
|
||||
}
|
||||
|
||||
check_command() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
if ! check_command jq; then
|
||||
echo "jq not found, please install it, https://stedolan.github.io/jq/download/"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CACHE_PATH=""
|
||||
CACHE_KEY=""
|
||||
PRINT_MODE=""
|
||||
|
@ -149,13 +108,50 @@ CHANNEL="${ARR_CHANNEL[0]}"
|
|||
VERSION="${ARR_VERSION[0]}"
|
||||
ARCH=$(echo "${ARR_ARCH[0]}" | awk '{print tolower($0)}')
|
||||
|
||||
# default values
|
||||
[[ -z $CHANNEL ]] && CHANNEL=stable
|
||||
[[ -z $VERSION ]] && VERSION=any
|
||||
[[ -z $ARCH ]] && ARCH=x64
|
||||
[[ -z $CACHE_PATH ]] && CACHE_PATH=/tmp
|
||||
[[ -z $CACHE_KEY ]] && CACHE_KEY="flutter-:os:-:arch:-:channel:-:version:-:hash:"
|
||||
|
||||
RELEASE_MANIFEST=""
|
||||
VERSION_MANIFEST=""
|
||||
|
||||
get_version_manifest() {
|
||||
version_manifest=$(echo "$RELEASE_MANIFEST" | get_version "$CHANNEL" "$(normalize_version "$VERSION")" "$ARCH")
|
||||
if [[ "$version_manifest" == null ]]; then
|
||||
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() {
|
||||
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_hash=$(echo "$VERSION_MANIFEST" | jq -r '.hash')
|
||||
version_sha_256=$(echo "$VERSION_MANIFEST" | jq -r '.sha256')
|
||||
|
||||
expanded_key="${1/:channel:/$version_channel}"
|
||||
expanded_key="${expanded_key/:version:/$version_version}"
|
||||
expanded_key="${expanded_key/:arch:/$version_arch}"
|
||||
expanded_key="${expanded_key/:hash:/$version_hash}"
|
||||
expanded_key="${expanded_key/:sha256:/$version_sha_256}"
|
||||
expanded_key="${expanded_key/:os:/$OS_NAME}"
|
||||
|
||||
echo "$expanded_key"
|
||||
}
|
||||
|
||||
if [[ -n "$PRINT_MODE" ]]; then
|
||||
if [[ "$CHANNEL" == master ]]; then
|
||||
if [[ "$PRINT_MODE" == version ]]; then
|
||||
|
@ -174,10 +170,10 @@ if [[ -n "$PRINT_MODE" ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
RELEASE_MANIFEST=$(cat "$MANIFEST_TEST_PATH")
|
||||
VERSION_MANIFEST=$(get_version_manifest "$CHANNEL" "$VERSION")
|
||||
RELEASE_MANIFEST=$(cat "$MANIFEST_TEST_FIXTURE")
|
||||
VERSION_MANIFEST=$(get_version_manifest)
|
||||
|
||||
if [[ $VERSION_MANIFEST == null ]]; then
|
||||
if [[ -z "$VERSION_MANIFEST" ]]; then
|
||||
not_found_error "$CHANNEL" "$VERSION" "$ARCH"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -208,11 +204,13 @@ if [[ ! -x "$SDK_CACHE/bin/flutter" ]]; 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 "$CHANNEL" "$VERSION")
|
||||
if [[ $VERSION_MANIFEST == null ]]; then
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue