|
8 | 8 | # Maintainer: The Dev Container spec maintainers |
9 | 9 | DOTNET_SCRIPTS=$(dirname "${BASH_SOURCE[0]}") |
10 | 10 | DOTNET_INSTALL_SCRIPT="$DOTNET_SCRIPTS/vendor/dotnet-install.sh" |
| 11 | +DOTNET_RELEASES_INDEX_URL="https://builds.dotnet.microsoft.com/dotnet/release-metadata/releases-index.json" |
11 | 12 |
|
12 | | -# Prints the latest dotnet version in the specified channel |
13 | | -# Usage: fetch_latest_version_in_channel <channel> [<runtime>] |
14 | | -# Example: fetch_latest_version_in_channel "LTS" |
15 | | -# Example: fetch_latest_version_in_channel "6.0" "dotnet" |
16 | | -# Example: fetch_latest_version_in_channel "6.0" "aspnetcore" |
17 | | -fetch_latest_version_in_channel() { |
18 | | - local channel="$1" |
19 | | - local runtime="$2" |
20 | | - if [ "$runtime" = "dotnet" ]; then |
21 | | - wget -qO- "https://builds.dotnet.microsoft.com/dotnet/Runtime/$channel/latest.version" |
22 | | - elif [ "$runtime" = "aspnetcore" ]; then |
23 | | - wget -qO- "https://builds.dotnet.microsoft.com/dotnet/aspnetcore/Runtime/$channel/latest.version" |
24 | | - else |
25 | | - wget -qO- "https://builds.dotnet.microsoft.com/dotnet/Sdk/$channel/latest.version" |
26 | | - fi |
27 | | -} |
28 | | - |
29 | | -# Prints the latest dotnet version |
30 | | -# Usage: fetch_latest_version [<runtime>] |
| 13 | +# Prints the latest active dotnet version from the releases index. |
| 14 | +# Usage: fetch_latest_version [<target>] |
| 15 | +# With no target, resolves the latest SDK version. |
| 16 | +# With "sdk", resolves the latest SDK version explicitly. |
| 17 | +# With "dotnet" or "aspnetcore", resolves the latest runtime version. |
| 18 | +# Note: the upstream releases index only distinguishes SDK vs runtime for |
| 19 | +# latest resolution, so "dotnet" and "aspnetcore" currently resolve to the |
| 20 | +# same version. |
31 | 21 | # Example: fetch_latest_version |
| 22 | +# Example: fetch_latest_version "sdk" |
32 | 23 | # Example: fetch_latest_version "dotnet" |
33 | 24 | # Example: fetch_latest_version "aspnetcore" |
34 | 25 | fetch_latest_version() { |
35 | | - local runtime="$1" |
36 | | - local sts_version |
37 | | - local lts_version |
38 | | - sts_version=$(fetch_latest_version_in_channel "STS" "$runtime") |
39 | | - lts_version=$(fetch_latest_version_in_channel "LTS" "$runtime") |
40 | | - if [[ "$sts_version" > "$lts_version" ]]; then |
41 | | - echo "$sts_version" |
42 | | - else |
43 | | - echo "$lts_version" |
44 | | - fi |
| 26 | + local target="$1" |
| 27 | + local version_field="" |
| 28 | + local releases_index="" |
| 29 | + |
| 30 | + case "$target" in |
| 31 | + ""|sdk) |
| 32 | + version_field="latest-sdk" |
| 33 | + ;; |
| 34 | + dotnet|aspnetcore) |
| 35 | + version_field="latest-runtime" |
| 36 | + ;; |
| 37 | + *) |
| 38 | + echo "Unsupported target '$target'. Expected 'sdk', 'dotnet', or 'aspnetcore'." >&2 |
| 39 | + return 1 |
| 40 | + ;; |
| 41 | + esac |
| 42 | + |
| 43 | + releases_index="$(wget -qO- "$DOTNET_RELEASES_INDEX_URL")" || return $? |
| 44 | + |
| 45 | + printf '%s\n' "$releases_index" \ |
| 46 | + | jq -er --arg version_field "$version_field" ' |
| 47 | + .["releases-index"] |
| 48 | + | map( |
| 49 | + select(."support-phase" == "active") |
| 50 | + | .[$version_field] |
| 51 | + ) |
| 52 | + | .[0] |
| 53 | + ' |
45 | 54 | } |
46 | 55 |
|
47 | 56 | # Installs a version of the .NET SDK |
|
0 commit comments