Skip to content

Instantly share code, notes, and snippets.

@gabrielfeo
Created March 22, 2022 19:25
Show Gist options
  • Save gabrielfeo/c478261a694e76bc5c29f7136cc6c88c to your computer and use it in GitHub Desktop.
Save gabrielfeo/c478261a694e76bc5c29f7136cc6c88c to your computer and use it in GitHub Desktop.
Download latest Gradle Profiler release
#!/usr/bin/env sh
# Downloads the latest prebuilt gradle-profiler release to the specified path
#
# Usage:
# download_gradle_profiler.sh <download-path>
set -eu
output_path="${1:?"Usage: download_gradle_profiler.sh <download-path>"}"
MAVEN_METADATA_URL="https://repo1.maven.org/maven2/org/gradle/profiler/gradle-profiler/maven-metadata.xml"
MAVEN_RELEASE_URL_TEMPLATE="https://repo1.maven.org/maven2/org/gradle/profiler/gradle-profiler/{version}/gradle-profiler-{version}.zip"
get_latest_version_name() {
# Decide latest version manually because <latest> and <release> might contain an alpha/beta
wget -qO /dev/stdout "$MAVEN_METADATA_URL" \
| grep -E '<version>[0-9.]+</version>' \
| sed -E 's|.*<version>(.*)</version>.*|\1|' \
| sort --version-sort \
| tail -1
}
build_release_url_for_version_name() {
version_name="$1"
echo "$MAVEN_RELEASE_URL_TEMPLATE" | sed "s/{version}/$version_name/g"
}
download_release_to_path() {
wget --output-document gradle-profiler.zip --output-file gradle-profiler-download.log "$download_url"
download_time="$(grep "100%" gradle-profiler-download.log | sed -E 's/.*=(.*)/\1/')"
echo "Download took $download_time"
unzip -q gradle-profiler.zip # Should create dir like 'gradle-profiler-0.17.0'
mv "gradle-profiler-$version_name" "$output_path"
}
version_name="$(get_latest_version_name)"
download_url="$(build_release_url_for_version_name "$version_name")"
echo "Latest version is $version_name.\nDownloading from $download_url"
download_release_to_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment