2022-01-06 08:40:25 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-01-06 08:51:59 +01:00
|
|
|
OS_NAME=$(echo "$RUNNER_OS" | awk '{print tolower($0)}')
|
2022-01-06 09:38:04 +01:00
|
|
|
MANIFEST_BASE_URL="https://storage.googleapis.com/flutter_infra_release/releases"
|
|
|
|
MANIFEST_URL="${MANIFEST_BASE_URL}/releases_${OS_NAME}.json"
|
2022-07-24 14:19:31 +02:00
|
|
|
MANIFEST_TEST_PATH="test/releases_${OS_NAME}.json"
|
|
|
|
RELEASE_MANIFEST=""
|
|
|
|
VERSION_MANIFEST=null
|
2022-01-06 08:40:25 +01:00
|
|
|
|
|
|
|
# convert version like 2.5.x to 2.5
|
|
|
|
normalize_version() {
|
2022-07-24 14:19:31 +02:00
|
|
|
if [[ $1 == *.x ]]; then
|
|
|
|
echo "${1/.x/}"
|
2022-01-06 08:40:25 +01:00
|
|
|
else
|
2022-07-24 14:19:31 +02:00
|
|
|
echo "$1"
|
2022-01-06 08:40:25 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
latest_version() {
|
2022-06-05 11:06:25 +02:00
|
|
|
jq --arg arch "$ARCH" '.releases | map(select(.dart_sdk_arch == null or .dart_sdk_arch == $arch)) | first'
|
|
|
|
}
|
|
|
|
|
|
|
|
latest_channel_version() {
|
2022-04-19 11:08:46 +02:00
|
|
|
jq --arg channel "$1" --arg arch "$ARCH" '.releases | map(select(.channel==$channel) | select(.dart_sdk_arch == null or .dart_sdk_arch == $arch)) | first'
|
2022-01-06 08:40:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
wildcard_version() {
|
2022-07-24 14:19:31 +02:00
|
|
|
if [[ $2 == *"v"* ]]; then # is legacy version format
|
2022-04-19 11:08:46 +02:00
|
|
|
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
|
2022-04-29 02:52:26 +02:00
|
|
|
jq --arg version "$2" --arg arch "$ARCH" '.releases | map(select(.version | startswith($version)) | select(.dart_sdk_arch == null or .dart_sdk_arch == $arch)) | first'
|
2022-01-06 10:17:20 +01:00
|
|
|
else
|
2022-04-19 11:08:46 +02:00
|
|
|
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'
|
2022-01-06 10:17:20 +01:00
|
|
|
fi
|
2022-01-06 08:40:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get_version() {
|
2022-06-05 11:06:25 +02:00
|
|
|
if [[ $1 == any && $2 == any ]]; then
|
|
|
|
latest_version
|
|
|
|
elif [[ $2 == any ]]; then
|
|
|
|
latest_channel_version $1
|
2022-01-06 08:40:25 +01:00
|
|
|
else
|
|
|
|
wildcard_version $1 $2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
get_version_manifest() {
|
2022-07-24 14:19:31 +02:00
|
|
|
version_manifest=$(echo $RELEASE_MANIFEST | get_version $1 $(normalize_version $2))
|
2022-01-06 08:40:25 +01:00
|
|
|
|
|
|
|
if [[ $version_manifest == null ]]; then
|
|
|
|
# fallback through legacy version format
|
2022-07-24 14:19:31 +02:00
|
|
|
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}'
|
2022-01-06 08:40:25 +01:00
|
|
|
else
|
2022-07-24 14:19:31 +02:00
|
|
|
echo "$version_manifest"
|
2022-01-06 08:40:25 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-01-06 09:38:04 +01:00
|
|
|
download_archive() {
|
|
|
|
archive_url="$MANIFEST_BASE_URL/$1"
|
|
|
|
archive_name=$(basename $1)
|
2022-02-03 23:50:07 +01:00
|
|
|
archive_local="$RUNNER_TEMP/$archive_name"
|
2022-01-06 09:38:04 +01:00
|
|
|
|
|
|
|
curl --connect-timeout 15 --retry 5 $archive_url >$archive_local
|
|
|
|
|
2022-02-04 15:12:44 +01:00
|
|
|
# Create the target folder
|
|
|
|
mkdir -p "$2"
|
|
|
|
|
2022-01-06 09:38:04 +01:00
|
|
|
if [[ $archive_name == *zip ]]; then
|
2022-02-03 23:50:07 +01:00
|
|
|
unzip -q -o "$archive_local" -d "$RUNNER_TEMP"
|
2022-02-04 15:12:44 +01:00
|
|
|
# Remove the folder again so that the move command can do a simple rename
|
|
|
|
# instead of moving the content into the target folder.
|
|
|
|
# This is a little bit of a hack since the "mv --no-target-directory"
|
|
|
|
# linux option is not available here
|
|
|
|
rm -r "$2"
|
|
|
|
mv ${RUNNER_TEMP}/flutter "$2"
|
2022-01-06 09:38:04 +01:00
|
|
|
else
|
2022-01-13 11:10:55 +01:00
|
|
|
tar xf "$archive_local" -C "$2" --strip-components=1
|
2022-01-06 09:38:04 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
rm $archive_local
|
|
|
|
}
|
|
|
|
|
2022-01-13 11:10:55 +01:00
|
|
|
transform_path() {
|
|
|
|
if [[ $OS_NAME == windows ]]; then
|
2022-07-24 14:19:31 +02:00
|
|
|
echo "$1" | sed -e 's/^\///' -e 's/\//\\/g'
|
2022-01-13 11:10:55 +01:00
|
|
|
else
|
2022-07-24 14:19:31 +02:00
|
|
|
echo "$1"
|
2022-01-13 11:10:55 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-07-24 14:19:31 +02:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2022-07-19 07:00:34 +02:00
|
|
|
check_command() {
|
2022-07-24 14:19:31 +02:00
|
|
|
command -v "$1" >/dev/null 2>&1
|
2022-07-19 07:00:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ! check_command jq; then
|
2022-07-19 01:32:29 +02:00
|
|
|
echo "jq not found, please install it, https://stedolan.github.io/jq/download/"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-03-31 07:45:08 +02:00
|
|
|
CACHE_PATH=""
|
2022-07-24 14:19:31 +02:00
|
|
|
CACHE_KEY=""
|
|
|
|
PRINT_MODE=""
|
2022-01-13 11:10:55 +01:00
|
|
|
|
2022-07-24 14:19:31 +02:00
|
|
|
while getopts 'c:k:p:' flag; do
|
2022-01-13 11:10:55 +01:00
|
|
|
case "${flag}" in
|
2022-03-31 07:45:08 +02:00
|
|
|
c) CACHE_PATH="$OPTARG" ;;
|
2022-07-24 14:19:31 +02:00
|
|
|
k) CACHE_KEY="$OPTARG" ;;
|
|
|
|
p) PRINT_MODE="$OPTARG" ;;
|
2022-01-13 11:10:55 +01:00
|
|
|
?) exit 2 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
CHANNEL="${@:$OPTIND:1}"
|
|
|
|
VERSION="${@:$OPTIND+1:1}"
|
2022-04-29 02:52:26 +02:00
|
|
|
ARCH=$(echo "${@:$OPTIND+2:1}" | awk '{print tolower($0)}')
|
2022-01-06 08:40:25 +01:00
|
|
|
|
2022-07-24 14:19:31 +02:00
|
|
|
# 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:"
|
|
|
|
|
|
|
|
if [[ -n "$PRINT_MODE" ]]; then
|
|
|
|
if [[ "$CHANNEL" == master ]]; then
|
|
|
|
if [[ "$PRINT_MODE" == version ]]; then
|
|
|
|
echo "master:master:$ARCH|master:master:$ARCH"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$PRINT_MODE" == cache-key ]]; then
|
|
|
|
# MASTER_HASH=$(git ls-remote https://github.com/flutter/flutter.git | head -n 1 | awk '{print $1}')
|
|
|
|
|
|
|
|
VERSION_MANIFEST="{
|
|
|
|
\"channel\":\"$CHANNEL\",
|
|
|
|
\"version\":\"$CHANNEL\",
|
|
|
|
\"dart_sdk_arch\":\"$ARCH\",
|
|
|
|
\"hash\":\"$CHANNEL\",
|
|
|
|
\"sha256\":\"$CHANNEL\"
|
|
|
|
}"
|
|
|
|
|
|
|
|
EXPANDED_KEY=$(expand_key "$CACHE_KEY")
|
|
|
|
echo "$EXPANDED_KEY"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
RELEASE_MANIFEST=$(cat "$MANIFEST_TEST_PATH")
|
|
|
|
VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION)
|
|
|
|
|
|
|
|
if [[ $VERSION_MANIFEST == null ]]; then
|
|
|
|
not_found_error $CHANNEL $VERSION $ARCH
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$PRINT_MODE" == version ]]; then
|
|
|
|
VERSION_DEBUG=$(echo "$VERSION_MANIFEST" | jq -j '.channel,":",.version,":",.dart_sdk_arch')
|
|
|
|
|
|
|
|
echo "$CHANNEL:$VERSION:$ARCH|$VERSION_DEBUG"
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$PRINT_MODE" == cache-key ]]; then
|
|
|
|
EXPANDED_KEY=$(expand_key "$CACHE_KEY")
|
|
|
|
|
|
|
|
echo "$EXPANDED_KEY"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
CACHE_PATH=$(transform_path "$CACHE_PATH")
|
|
|
|
SDK_CACHE=$(expand_key "$CACHE_PATH")
|
|
|
|
PUB_CACHE=$(expand_key "${SDK_CACHE}/.pub-cache")
|
2022-01-06 09:38:04 +01:00
|
|
|
|
2022-01-13 11:10:55 +01:00
|
|
|
if [[ ! -x "${SDK_CACHE}/bin/flutter" ]]; then
|
2022-01-07 05:47:25 +01:00
|
|
|
if [[ $CHANNEL == master ]]; then
|
2022-01-13 11:10:55 +01:00
|
|
|
git clone -b master https://github.com/flutter/flutter.git "$SDK_CACHE"
|
2022-01-07 05:47:25 +01:00
|
|
|
else
|
2022-07-24 14:19:31 +02:00
|
|
|
RELEASE_MANIFEST=$(curl --silent --connect-timeout 15 --retry 5 "$MANIFEST_URL")
|
2022-01-07 05:47:25 +01:00
|
|
|
VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION)
|
|
|
|
if [[ $VERSION_MANIFEST == null ]]; then
|
2022-07-24 14:19:31 +02:00
|
|
|
not_found_error $CHANNEL $VERSION $ARCH
|
2022-01-07 05:47:25 +01:00
|
|
|
exit 1
|
2022-07-24 14:19:31 +02:00
|
|
|
fi
|
2022-01-07 05:47:25 +01:00
|
|
|
ARCHIVE_PATH=$(echo $VERSION_MANIFEST | jq -r '.archive')
|
2022-01-13 11:10:55 +01:00
|
|
|
download_archive "$ARCHIVE_PATH" "$SDK_CACHE"
|
2022-01-07 05:47:25 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-01-13 11:10:55 +01:00
|
|
|
echo "FLUTTER_ROOT=${SDK_CACHE}" >>$GITHUB_ENV
|
2022-01-06 11:46:35 +01:00
|
|
|
echo "PUB_CACHE=${PUB_CACHE}" >>$GITHUB_ENV
|
2022-01-06 09:48:07 +01:00
|
|
|
|
2022-01-13 11:10:55 +01:00
|
|
|
echo "${SDK_CACHE}/bin" >>$GITHUB_PATH
|
|
|
|
echo "${SDK_CACHE}/bin/cache/dart-sdk/bin" >>$GITHUB_PATH
|
2022-01-06 11:46:35 +01:00
|
|
|
echo "${PUB_CACHE}/bin" >>$GITHUB_PATH
|