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-01-06 08:40:25 +01:00
|
|
|
|
|
|
|
# convert version like 2.5.x to 2.5
|
|
|
|
normalize_version() {
|
|
|
|
if [[ $1 == *x ]]; then
|
|
|
|
echo ${1::-2}
|
|
|
|
else
|
|
|
|
echo $1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
latest_version() {
|
|
|
|
jq --arg channel "$1" '.releases | map(select(.channel==$channel)) | first'
|
|
|
|
}
|
|
|
|
|
|
|
|
wildcard_version() {
|
|
|
|
jq --arg channel "$1" --arg version "^$2" '.releases | map(select(.channel==$channel) | select(.version | test($version))) | first'
|
|
|
|
}
|
|
|
|
|
|
|
|
get_version() {
|
|
|
|
if [[ -z $2 ]]; then
|
|
|
|
latest_version $1
|
|
|
|
else
|
|
|
|
wildcard_version $1 $2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
get_version_manifest() {
|
|
|
|
releases_manifest=$(curl --silent --connect-timeout 15 --retry 5 $MANIFEST_URL)
|
|
|
|
version_manifest=$(echo $releases_manifest | get_version $1 $(normalize_version $2))
|
|
|
|
|
|
|
|
if [[ $version_manifest == null ]]; then
|
|
|
|
# fallback through legacy version format
|
|
|
|
echo $releases_manifest | wildcard_version $1 "v$(normalize_version $2)"
|
|
|
|
else
|
|
|
|
echo $version_manifest
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-01-06 09:38:04 +01:00
|
|
|
download_archive() {
|
|
|
|
archive_url="$MANIFEST_BASE_URL/$1"
|
|
|
|
archive_name=$(basename $1)
|
|
|
|
archive_local="$HOME/$archive_name"
|
|
|
|
|
|
|
|
curl --connect-timeout 15 --retry 5 $archive_url >$archive_local
|
|
|
|
|
|
|
|
if [[ $archive_name == *zip ]]; then
|
|
|
|
unzip -o "$archive_local" -d "$2"
|
|
|
|
else
|
|
|
|
tar xf "$archive_local" -C "$2"
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm $archive_local
|
|
|
|
}
|
|
|
|
|
2022-01-06 08:40:25 +01:00
|
|
|
CHANNEL="$1"
|
|
|
|
VERSION="$2"
|
|
|
|
|
2022-01-06 10:05:37 +01:00
|
|
|
if [[ $CHANNEL == master ]]; then
|
|
|
|
git clone -b master https://github.com/flutter/flutter.git "$RUNNER_TOOL_CACHE/flutter"
|
|
|
|
else
|
|
|
|
VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION)
|
2022-01-06 08:40:25 +01:00
|
|
|
|
2022-01-06 10:05:37 +01:00
|
|
|
if [[ $VERSION_MANIFEST == null ]]; then
|
|
|
|
echo "Unable to determine Flutter version for $CHANNEL $VERSION"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-01-06 09:38:04 +01:00
|
|
|
|
2022-01-06 10:05:37 +01:00
|
|
|
ARCHIVE_PATH=$(echo $VERSION_MANIFEST | jq -r '.archive')
|
|
|
|
download_archive "$ARCHIVE_PATH" "$RUNNER_TOOL_CACHE"
|
|
|
|
fi
|
2022-01-06 09:38:04 +01:00
|
|
|
|
|
|
|
if [[ $OS_NAME == windows ]]; then
|
|
|
|
FLUTTER_ROOT="${RUNNER_TOOL_CACHE}\\flutter"
|
2022-01-06 09:48:07 +01:00
|
|
|
PUBCACHE="${USERPROFILE}\\.pub-cache"
|
2022-01-06 09:38:04 +01:00
|
|
|
else
|
|
|
|
FLUTTER_ROOT="${RUNNER_TOOL_CACHE}/flutter"
|
2022-01-06 09:48:07 +01:00
|
|
|
PUBCACHE="${HOME}/.pub-cache"
|
2022-01-06 09:38:04 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "FLUTTER_ROOT=${FLUTTER_ROOT}" >>$GITHUB_ENV
|
2022-01-06 09:48:07 +01:00
|
|
|
echo "PUB_CACHE=${PUBCACHE}" >>$GITHUB_ENV
|
|
|
|
|
2022-01-06 09:38:04 +01:00
|
|
|
echo "${FLUTTER_ROOT}/bin" >>$GITHUB_PATH
|
2022-01-06 09:45:45 +01:00
|
|
|
echo "${FLUTTER_ROOT}/bin/cache/dart-sdk/bin" >>$GITHUB_PATH
|
2022-01-06 09:48:07 +01:00
|
|
|
echo "${PUBCACHE}/bin" >>$GITHUB_PATH
|