Merge branch 'master' into master

This commit is contained in:
Stanley Goldman 2019-11-08 17:15:28 +01:00 committed by GitHub
commit 474fe34688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 262 additions and 145 deletions

View File

@ -1,5 +1,5 @@
name: Main workflow name: Main workflow
on: [push] on: [push, pull_request]
jobs: jobs:
run: run:
name: Run name: Run

1
.gitignore vendored
View File

@ -92,3 +92,4 @@ typings/
.dynamodb/ .dynamodb/
.vscode/* .vscode/*
node_modules

View File

@ -4,7 +4,7 @@
<a href="https://github.com/actions/setup-dotnet"><img alt="GitHub Actions status" src="https://github.com/actions/setup-dotnet/workflows/Main%20workflow/badge.svg"></a> <a href="https://github.com/actions/setup-dotnet"><img alt="GitHub Actions status" src="https://github.com/actions/setup-dotnet/workflows/Main%20workflow/badge.svg"></a>
</p> </p>
This action sets up a dotnet environment for use in actions by: This action sets up a [dotnet core cli](https://github.com/dotnet/cli) environment for use in actions by:
- optionally downloading and caching a version of dotnet by SDK version and adding to PATH - optionally downloading and caching a version of dotnet by SDK version and adding to PATH
- registering problem matchers for error output - registering problem matchers for error output
@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-16.04 runs-on: ubuntu-16.04
strategy: strategy:
matrix: matrix:
dotnet: [ '2.2.103', '3.0.100-preview8-013656', '4.5.1' ] dotnet: [ '2.2.103', '3.0.100', '3.1.100-preview1-014459' ]
name: Dotnet ${{ matrix.dotnet }} sample name: Dotnet ${{ matrix.dotnet }} sample
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@master

View File

@ -37,15 +37,13 @@
.PARAMETER SharedRuntime .PARAMETER SharedRuntime
This parameter is obsolete and may be removed in a future version of this script. This parameter is obsolete and may be removed in a future version of this script.
The recommended alternative is '-Runtime dotnet'. The recommended alternative is '-Runtime dotnet'.
Default: false
Installs just the shared runtime bits, not the entire SDK. Installs just the shared runtime bits, not the entire SDK.
This is equivalent to specifying `-Runtime dotnet`.
.PARAMETER Runtime .PARAMETER Runtime
Installs just a shared runtime, not the entire SDK. Installs just a shared runtime, not the entire SDK.
Possible values: Possible values:
- dotnet - the Microsoft.NETCore.App shared runtime - dotnet - the Microsoft.NETCore.App shared runtime
- aspnetcore - the Microsoft.AspNetCore.App shared runtime - aspnetcore - the Microsoft.AspNetCore.App shared runtime
- windowsdesktop - the Microsoft.WindowsDesktop.App shared runtime
.PARAMETER DryRun .PARAMETER DryRun
If set it will not perform installation but instead display what command line to use to consistently install If set it will not perform installation but instead display what command line to use to consistently install
currently requested version of dotnet cli. In example if you specify version 'latest' it will display a link currently requested version of dotnet cli. In example if you specify version 'latest' it will display a link
@ -76,14 +74,18 @@
Skips installing non-versioned files if they already exist, such as dotnet.exe. Skips installing non-versioned files if they already exist, such as dotnet.exe.
.PARAMETER NoCdn .PARAMETER NoCdn
Disable downloading from the Azure CDN, and use the uncached feed directly. Disable downloading from the Azure CDN, and use the uncached feed directly.
.PARAMETER JSonFile
Determines the SDK version from a user specified global.json file
Note: global.json must have a value for 'SDK:Version'
#> #>
[cmdletbinding()] [cmdletbinding()]
param( param(
[string]$Channel="LTS", [string]$Channel="LTS",
[string]$Version="Latest", [string]$Version="Latest",
[string]$JSonFile,
[string]$InstallDir="<auto>", [string]$InstallDir="<auto>",
[string]$Architecture="<auto>", [string]$Architecture="<auto>",
[ValidateSet("dotnet", "aspnetcore", IgnoreCase = $false)] [ValidateSet("dotnet", "aspnetcore", "windowsdesktop", IgnoreCase = $false)]
[string]$Runtime, [string]$Runtime,
[Obsolete("This parameter may be removed in a future version of this script. The recommended alternative is '-Runtime dotnet'.")] [Obsolete("This parameter may be removed in a future version of this script. The recommended alternative is '-Runtime dotnet'.")]
[switch]$SharedRuntime, [switch]$SharedRuntime,
@ -257,7 +259,6 @@ function GetHTTPResponse([Uri] $Uri)
}) })
} }
function Get-Latest-Version-Info([string]$AzureFeed, [string]$Channel, [bool]$Coherent) { function Get-Latest-Version-Info([string]$AzureFeed, [string]$Channel, [bool]$Coherent) {
Say-Invocation $MyInvocation Say-Invocation $MyInvocation
@ -268,6 +269,10 @@ function Get-Latest-Version-Info([string]$AzureFeed, [string]$Channel, [bool]$Co
elseif ($Runtime -eq "aspnetcore") { elseif ($Runtime -eq "aspnetcore") {
$VersionFileUrl = "$UncachedFeed/aspnetcore/Runtime/$Channel/latest.version" $VersionFileUrl = "$UncachedFeed/aspnetcore/Runtime/$Channel/latest.version"
} }
# Currently, the WindowsDesktop runtime is manufactured with the .Net core runtime
elseif ($Runtime -eq "windowsdesktop") {
$VersionFileUrl = "$UncachedFeed/Runtime/$Channel/latest.version"
}
elseif (-not $Runtime) { elseif (-not $Runtime) {
if ($Coherent) { if ($Coherent) {
$VersionFileUrl = "$UncachedFeed/Sdk/$Channel/latest.coherent.version" $VersionFileUrl = "$UncachedFeed/Sdk/$Channel/latest.coherent.version"
@ -299,20 +304,64 @@ function Get-Latest-Version-Info([string]$AzureFeed, [string]$Channel, [bool]$Co
return $VersionInfo return $VersionInfo
} }
function Parse-Jsonfile-For-Version([string]$JSonFile) {
function Get-Specific-Version-From-Version([string]$AzureFeed, [string]$Channel, [string]$Version) {
Say-Invocation $MyInvocation Say-Invocation $MyInvocation
switch ($Version.ToLower()) { If (-Not (Test-Path $JSonFile)) {
{ $_ -eq "latest" } { throw "Unable to find '$JSonFile'"
$LatestVersionInfo = Get-Latest-Version-Info -AzureFeed $AzureFeed -Channel $Channel -Coherent $False exit 0
return $LatestVersionInfo.Version }
try {
$JSonContent = Get-Content($JSonFile) -Raw | ConvertFrom-Json | Select-Object -expand "sdk" -ErrorAction SilentlyContinue
}
catch {
throw "Json file unreadable: '$JSonFile'"
exit 0
}
if ($JSonContent) {
try {
$JSonContent.PSObject.Properties | ForEach-Object {
$PropertyName = $_.Name
if ($PropertyName -eq "version") {
$Version = $_.Value
Say-Verbose "Version = $Version"
}
}
} }
{ $_ -eq "coherent" } { catch {
$LatestVersionInfo = Get-Latest-Version-Info -AzureFeed $AzureFeed -Channel $Channel -Coherent $True throw "Unable to parse the SDK node in '$JSonFile'"
return $LatestVersionInfo.Version exit 0
} }
default { return $Version } }
else {
throw "Unable to find the SDK node in '$JSonFile'"
exit 0
}
If ($Version -eq $null) {
throw "Unable to find the SDK:version node in '$JSonFile'"
exit 0
}
return $Version
}
function Get-Specific-Version-From-Version([string]$AzureFeed, [string]$Channel, [string]$Version, [string]$JSonFile) {
Say-Invocation $MyInvocation
if (-not $JSonFile) {
switch ($Version.ToLower()) {
{ $_ -eq "latest" } {
$LatestVersionInfo = Get-Latest-Version-Info -AzureFeed $AzureFeed -Channel $Channel -Coherent $False
return $LatestVersionInfo.Version
}
{ $_ -eq "coherent" } {
$LatestVersionInfo = Get-Latest-Version-Info -AzureFeed $AzureFeed -Channel $Channel -Coherent $True
return $LatestVersionInfo.Version
}
default { return $Version }
}
}
else {
return Parse-Jsonfile-For-Version $JSonFile
} }
} }
@ -325,6 +374,9 @@ function Get-Download-Link([string]$AzureFeed, [string]$SpecificVersion, [string
elseif ($Runtime -eq "aspnetcore") { elseif ($Runtime -eq "aspnetcore") {
$PayloadURL = "$AzureFeed/aspnetcore/Runtime/$SpecificVersion/aspnetcore-runtime-$SpecificVersion-win-$CLIArchitecture.zip" $PayloadURL = "$AzureFeed/aspnetcore/Runtime/$SpecificVersion/aspnetcore-runtime-$SpecificVersion-win-$CLIArchitecture.zip"
} }
elseif ($Runtime -eq "windowsdesktop") {
$PayloadURL = "$AzureFeed/Runtime/$SpecificVersion/windowsdesktop-runtime-$SpecificVersion-win-$CLIArchitecture.zip"
}
elseif (-not $Runtime) { elseif (-not $Runtime) {
$PayloadURL = "$AzureFeed/Sdk/$SpecificVersion/dotnet-sdk-$SpecificVersion-win-$CLIArchitecture.zip" $PayloadURL = "$AzureFeed/Sdk/$SpecificVersion/dotnet-sdk-$SpecificVersion-win-$CLIArchitecture.zip"
} }
@ -374,23 +426,6 @@ function Resolve-Installation-Path([string]$InstallDir) {
return $InstallDir return $InstallDir
} }
function Get-Version-Info-From-Version-File([string]$InstallRoot, [string]$RelativePathToVersionFile) {
Say-Invocation $MyInvocation
$VersionFile = Join-Path -Path $InstallRoot -ChildPath $RelativePathToVersionFile
Say-Verbose "Local version file: $VersionFile"
if (Test-Path $VersionFile) {
$VersionText = cat $VersionFile
Say-Verbose "Local version file text: $VersionText"
return Get-Version-Info-From-Version-Text $VersionText
}
Say-Verbose "Local version file not found."
return $null
}
function Is-Dotnet-Package-Installed([string]$InstallRoot, [string]$RelativePathToPackage, [string]$SpecificVersion) { function Is-Dotnet-Package-Installed([string]$InstallRoot, [string]$RelativePathToPackage, [string]$SpecificVersion) {
Say-Invocation $MyInvocation Say-Invocation $MyInvocation
@ -526,7 +561,7 @@ function Prepend-Sdk-InstallRoot-To-Path([string]$InstallRoot, [string]$BinFolde
} }
$CLIArchitecture = Get-CLIArchitecture-From-Architecture $Architecture $CLIArchitecture = Get-CLIArchitecture-From-Architecture $Architecture
$SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -Channel $Channel -Version $Version $SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -Channel $Channel -Version $Version -JSonFile $JSonFile
$DownloadLink = Get-Download-Link -AzureFeed $AzureFeed -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture $DownloadLink = Get-Download-Link -AzureFeed $AzureFeed -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture
$LegacyDownloadLink = Get-LegacyDownload-Link -AzureFeed $AzureFeed -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture $LegacyDownloadLink = Get-LegacyDownload-Link -AzureFeed $AzureFeed -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture
@ -564,6 +599,10 @@ elseif ($Runtime -eq "aspnetcore") {
$assetName = "ASP.NET Core Runtime" $assetName = "ASP.NET Core Runtime"
$dotnetPackageRelativePath = "shared\Microsoft.AspNetCore.App" $dotnetPackageRelativePath = "shared\Microsoft.AspNetCore.App"
} }
elseif ($Runtime -eq "windowsdesktop") {
$assetName = ".NET Core Windows Desktop Runtime"
$dotnetPackageRelativePath = "shared\Microsoft.WindowsDesktop.App"
}
elseif (-not $Runtime) { elseif (-not $Runtime) {
$assetName = ".NET Core SDK" $assetName = ".NET Core SDK"
$dotnetPackageRelativePath = "sdk" $dotnetPackageRelativePath = "sdk"

View File

@ -148,7 +148,7 @@ get_linux_platform_name() {
return 0 return 0
elif [ -e /etc/redhat-release ]; then elif [ -e /etc/redhat-release ]; then
local redhatRelease=$(</etc/redhat-release) local redhatRelease=$(</etc/redhat-release)
if [[ $redhatRelease == "CentOS release 6."* || $redhatRelease == "Red Hat Enterprise Linux Server release 6."* ]]; then if [[ $redhatRelease == "CentOS release 6."* || $redhatRelease == "Red Hat Enterprise Linux "*" release 6."* ]]; then
echo "rhel.6" echo "rhel.6"
return 0 return 0
fi fi
@ -435,11 +435,52 @@ get_latest_version_info() {
return $? return $?
} }
# args:
# json_file - $1
parse_jsonfile_for_version() {
eval $invocation
local json_file="$1"
if [ ! -f "$json_file" ]; then
say_err "Unable to find \`$json_file\`"
return 1
fi
sdk_section=$(cat $json_file | awk '/"sdk"/,/}/')
if [ -z "$sdk_section" ]; then
say_err "Unable to parse the SDK node in \`$json_file\`"
return 1
fi
sdk_list=$(echo $sdk_section | awk -F"[{}]" '{print $2}')
sdk_list=${sdk_list//[\" ]/}
sdk_list=${sdk_list//,/$'\n'}
sdk_list="$(echo -e "${sdk_list}" | tr -d '[[:space:]]')"
local version_info=""
while read -r line; do
IFS=:
while read -r key value; do
if [[ "$key" == "version" ]]; then
version_info=$value
fi
done <<< "$line"
done <<< "$sdk_list"
if [ -z "$version_info" ]; then
say_err "Unable to find the SDK:version node in \`$json_file\`"
return 1
fi
echo "$version_info"
return 0
}
# args: # args:
# azure_feed - $1 # azure_feed - $1
# channel - $2 # channel - $2
# normalized_architecture - $3 # normalized_architecture - $3
# version - $4 # version - $4
# json_file - $5
get_specific_version_from_version() { get_specific_version_from_version() {
eval $invocation eval $invocation
@ -447,27 +488,35 @@ get_specific_version_from_version() {
local channel="$2" local channel="$2"
local normalized_architecture="$3" local normalized_architecture="$3"
local version="$(to_lowercase "$4")" local version="$(to_lowercase "$4")"
local json_file="$5"
case "$version" in if [ -z "$json_file" ]; then
latest) case "$version" in
local version_info latest)
version_info="$(get_latest_version_info "$azure_feed" "$channel" "$normalized_architecture" false)" || return 1 local version_info
say_verbose "get_specific_version_from_version: version_info=$version_info" version_info="$(get_latest_version_info "$azure_feed" "$channel" "$normalized_architecture" false)" || return 1
echo "$version_info" | get_version_from_version_info say_verbose "get_specific_version_from_version: version_info=$version_info"
return 0 echo "$version_info" | get_version_from_version_info
;; return 0
coherent) ;;
local version_info coherent)
version_info="$(get_latest_version_info "$azure_feed" "$channel" "$normalized_architecture" true)" || return 1 local version_info
say_verbose "get_specific_version_from_version: version_info=$version_info" version_info="$(get_latest_version_info "$azure_feed" "$channel" "$normalized_architecture" true)" || return 1
echo "$version_info" | get_version_from_version_info say_verbose "get_specific_version_from_version: version_info=$version_info"
return 0 echo "$version_info" | get_version_from_version_info
;; return 0
*) ;;
echo "$version" *)
return 0 echo "$version"
;; return 0
esac ;;
esac
else
local version_info
version_info="$(parse_jsonfile_for_version "$json_file")" || return 1
echo "$version_info"
return 0
fi
} }
# args: # args:
@ -558,24 +607,6 @@ resolve_installation_path() {
return 0 return 0
} }
# args:
# install_root - $1
get_installed_version_info() {
eval $invocation
local install_root="$1"
local version_file="$(combine_paths "$install_root" "$local_version_file_relative_path")"
say_verbose "Local version file: $version_file"
if [ ! -z "$version_file" ] | [ -r "$version_file" ]; then
local version_info="$(cat "$version_file")"
echo "$version_info"
return 0
fi
say_verbose "Local version file not found."
return 0
}
# args: # args:
# relative_or_absolute_path - $1 # relative_or_absolute_path - $1
get_absolute_path() { get_absolute_path() {
@ -612,6 +643,9 @@ copy_files_or_dirs_from_list() {
local target="$out_path/$path" local target="$out_path/$path"
if [ "$override" = true ] || (! ([ -d "$target" ] || [ -e "$target" ])); then if [ "$override" = true ] || (! ([ -d "$target" ] || [ -e "$target" ])); then
mkdir -p "$out_path/$(dirname "$path")" mkdir -p "$out_path/$(dirname "$path")"
if [ -d "$target" ]; then
rm -rf "$target"
fi
cp -R $override_switch "$root_path/$path" "$target" cp -R $override_switch "$root_path/$path" "$target"
fi fi
done done
@ -721,7 +755,7 @@ calculate_vars() {
normalized_architecture="$(get_normalized_architecture_from_architecture "$architecture")" normalized_architecture="$(get_normalized_architecture_from_architecture "$architecture")"
say_verbose "normalized_architecture=$normalized_architecture" say_verbose "normalized_architecture=$normalized_architecture"
specific_version="$(get_specific_version_from_version "$azure_feed" "$channel" "$normalized_architecture" "$version")" specific_version="$(get_specific_version_from_version "$azure_feed" "$channel" "$normalized_architecture" "$version" "$json_file")"
say_verbose "specific_version=$specific_version" say_verbose "specific_version=$specific_version"
if [ -z "$specific_version" ]; then if [ -z "$specific_version" ]; then
say_err "Could not resolve version information." say_err "Could not resolve version information."
@ -823,6 +857,7 @@ temporary_file_template="${TMPDIR:-/tmp}/dotnet.XXXXXXXXX"
channel="LTS" channel="LTS"
version="Latest" version="Latest"
json_file=""
install_dir="<auto>" install_dir="<auto>"
architecture="<auto>" architecture="<auto>"
dry_run=false dry_run=false
@ -868,6 +903,9 @@ do
runtime="$1" runtime="$1"
if [[ "$runtime" != "dotnet" ]] && [[ "$runtime" != "aspnetcore" ]]; then if [[ "$runtime" != "dotnet" ]] && [[ "$runtime" != "aspnetcore" ]]; then
say_err "Unsupported value for --runtime: '$1'. Valid values are 'dotnet' and 'aspnetcore'." say_err "Unsupported value for --runtime: '$1'. Valid values are 'dotnet' and 'aspnetcore'."
if [[ "$runtime" == "windowsdesktop" ]]; then
say_err "WindowsDesktop archives are manufactured for Windows platforms only."
fi
exit 1 exit 1
fi fi
;; ;;
@ -906,6 +944,10 @@ do
runtime_id="$1" runtime_id="$1"
non_dynamic_parameters+=" $name "\""$1"\""" non_dynamic_parameters+=" $name "\""$1"\"""
;; ;;
--jsonfile|-[Jj][Ss]on[Ff]ile)
shift
json_file="$1"
;;
--skip-non-versioned-files|-[Ss]kip[Nn]on[Vv]ersioned[Ff]iles) --skip-non-versioned-files|-[Ss]kip[Nn]on[Vv]ersioned[Ff]iles)
override_non_versioned_files=false override_non_versioned_files=false
non_dynamic_parameters+=" $name" non_dynamic_parameters+=" $name"
@ -947,22 +989,25 @@ do
echo " Possible values:" echo " Possible values:"
echo " - dotnet - the Microsoft.NETCore.App shared runtime" echo " - dotnet - the Microsoft.NETCore.App shared runtime"
echo " - aspnetcore - the Microsoft.AspNetCore.App shared runtime" echo " - aspnetcore - the Microsoft.AspNetCore.App shared runtime"
echo " --skip-non-versioned-files Skips non-versioned files if they already exist, such as the dotnet executable."
echo " -SkipNonVersionedFiles"
echo " --dry-run,-DryRun Do not perform installation. Display download link." echo " --dry-run,-DryRun Do not perform installation. Display download link."
echo " --no-path, -NoPath Do not set PATH for the current process." echo " --no-path, -NoPath Do not set PATH for the current process."
echo " --verbose,-Verbose Display diagnostics information." echo " --verbose,-Verbose Display diagnostics information."
echo " --azure-feed,-AzureFeed Azure feed location. Defaults to $azure_feed, This parameter typically is not changed by the user." echo " --azure-feed,-AzureFeed Azure feed location. Defaults to $azure_feed, This parameter typically is not changed by the user."
echo " --uncached-feed,-UncachedFeed Uncached feed location. This parameter typically is not changed by the user." echo " --uncached-feed,-UncachedFeed Uncached feed location. This parameter typically is not changed by the user."
echo " --no-cdn,-NoCdn Disable downloading from the Azure CDN, and use the uncached feed directly."
echo " --feed-credential,-FeedCredential Azure feed shared access token. This parameter typically is not specified." echo " --feed-credential,-FeedCredential Azure feed shared access token. This parameter typically is not specified."
echo " --skip-non-versioned-files Skips non-versioned files if they already exist, such as the dotnet executable."
echo " -SkipNonVersionedFiles"
echo " --no-cdn,-NoCdn Disable downloading from the Azure CDN, and use the uncached feed directly."
echo " --jsonfile <JSONFILE> Determines the SDK version from a user specified global.json file."
echo " Note: global.json must have a value for 'SDK:Version'"
echo " --runtime-id Installs the .NET Tools for the given platform (use linux-x64 for portable linux)." echo " --runtime-id Installs the .NET Tools for the given platform (use linux-x64 for portable linux)."
echo " -RuntimeId" echo " -RuntimeId"
echo " -?,--?,-h,--help,-Help Shows this help message" echo " -?,--?,-h,--help,-Help Shows this help message"
echo "" echo ""
echo "Obsolete parameters:" echo "Obsolete parameters:"
echo " --shared-runtime The recommended alternative is '--runtime dotnet'." echo " --shared-runtime The recommended alternative is '--runtime dotnet'."
echo " -SharedRuntime Installs just the shared runtime bits, not the entire SDK." echo " This parameter is obsolete and may be removed in a future version of this script."
echo " Installs just the shared runtime bits, not the entire SDK."
echo "" echo ""
echo "Install Location:" echo "Install Location:"
echo " Location is chosen in following order:" echo " Location is chosen in following order:"

View File

@ -26,7 +26,6 @@ const fs_1 = require("fs");
const os = __importStar(require("os")); const os = __importStar(require("os"));
const path = __importStar(require("path")); const path = __importStar(require("path"));
const semver = __importStar(require("semver")); const semver = __importStar(require("semver"));
const util = __importStar(require("util"));
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
if (!tempDirectory) { if (!tempDirectory) {
let baseLocation; let baseLocation;
@ -73,7 +72,7 @@ class DotnetCoreInstaller {
console.log('Using cached tool'); console.log('Using cached tool');
} }
// Need to set this so that .NET Core global tools find the right locations. // Need to set this so that .NET Core global tools find the right locations.
core.exportVariable('DOTNET_ROOT', path.join(toolPath, '../..')); core.exportVariable('DOTNET_ROOT', toolPath);
// Prepend the tools path. instructs the agent to prepend for future tasks // Prepend the tools path. instructs the agent to prepend for future tasks
core.addPath(toolPath); core.addPath(toolPath);
}); });
@ -175,39 +174,29 @@ class DotnetCoreInstaller {
getDownloadUrls(osSuffixes, version) { getDownloadUrls(osSuffixes, version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let downloadUrls = []; let downloadUrls = [];
let releasesJSON = yield this.getReleasesJson(); const httpCallbackClient = new httpClient.HttpClient('actions/setup-dotnet', [], {});
core.debug('Releases: ' + releasesJSON); const releasesJsonUrl = yield this.getReleasesJsonUrl(httpCallbackClient, version.split('.'));
let releasesInfo = JSON.parse(yield releasesJSON.readBody()); let releasesJSON = yield httpCallbackClient.get(releasesJsonUrl);
let releasesInfo = JSON.parse(yield releasesJSON.readBody())['releases'];
releasesInfo = releasesInfo.filter((releaseInfo) => { releasesInfo = releasesInfo.filter((releaseInfo) => {
return (releaseInfo['version-sdk'] === version || return (releaseInfo['sdk']['version'] === version ||
releaseInfo['version-sdk-display'] === version); releaseInfo['sdk']['version-display'] === version);
}); });
if (releasesInfo.length != 0) { if (releasesInfo.length != 0) {
let release = releasesInfo[0]; let release = releasesInfo[0];
let blobUrl = release['blob-sdk']; let files = release['sdk']['files'];
let dlcUrl = release['dlc--sdk']; files = files.filter((file) => {
let fileName = release['sdk-' + osSuffixes[0]] if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) {
? release['sdk-' + osSuffixes[0]] return (file['url'].endsWith('.zip') || file['url'].endsWith('.tar.gz'));
: release['sdk-' + osSuffixes[1]];
if (!!fileName) {
fileName = fileName.trim();
// For some latest version, the filename itself can be full download url.
// Do a very basic check for url(instead of regex) as the url is only for downloading and
// is coming from .net core releases json and not some ransom user input
if (fileName.toLowerCase().startsWith('https://')) {
downloadUrls.push(fileName);
}
else {
if (!!blobUrl) {
downloadUrls.push(util.format('%s%s', blobUrl.trim(), fileName));
}
if (!!dlcUrl) {
downloadUrls.push(util.format('%s%s', dlcUrl.trim(), fileName));
}
} }
});
if (files.length > 0) {
files.forEach((file) => {
downloadUrls.push(file['url']);
});
} }
else { else {
throw `The specified version's download links are not correctly formed in the supported versions document => ${DotNetCoreReleasesUrl}`; throw `The specified version's download links are not correctly formed in the supported versions document => ${releasesJsonUrl}`;
} }
} }
else { else {
@ -221,9 +210,23 @@ class DotnetCoreInstaller {
return downloadUrls; return downloadUrls;
}); });
} }
getReleasesJson() { getReleasesJsonUrl(httpCallbackClient, versionParts) {
var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {}); return __awaiter(this, void 0, void 0, function* () {
return httpCallbackClient.get(DotNetCoreReleasesUrl); const releasesIndex = yield httpCallbackClient.get(DotNetCoreIndexUrl);
let releasesInfo = JSON.parse(yield releasesIndex.readBody())['releases-index'];
releasesInfo = releasesInfo.filter((info) => {
// channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x.
const sdkParts = info['channel-version'].split('.');
if (versionParts.length >= 2 && versionParts[1] != 'x') {
return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1];
}
return versionParts[0] == sdkParts[0];
});
if (releasesInfo.length === 0) {
throw `Could not find info for version ${versionParts.join('.')} at ${DotNetCoreIndexUrl}`;
}
return releasesInfo[0]['releases.json'];
});
} }
getFallbackDownloadUrls(version) { getFallbackDownloadUrls(version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -306,4 +309,4 @@ class DotnetCoreInstaller {
} }
} }
exports.DotnetCoreInstaller = DotnetCoreInstaller; exports.DotnetCoreInstaller = DotnetCoreInstaller;
const DotNetCoreReleasesUrl = 'https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases.json'; const DotNetCoreIndexUrl = 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json';

View File

@ -26,6 +26,7 @@ function run() {
// Version is optional. If supplied, install / use from the tool cache // Version is optional. If supplied, install / use from the tool cache
// If not supplied then task is still used to setup proxy, auth, etc... // If not supplied then task is still used to setup proxy, auth, etc...
// //
console.log(`::warning::Use the v1 tag to get the last version, master may contain breaking changes and will not contain any required packages in the future. i.e. actions/setup-dotnet@v1`);
let version = core.getInput('version'); let version = core.getInput('version');
if (!version) { if (!version) {
version = core.getInput('dotnet-version'); version = core.getInput('dotnet-version');

View File

@ -59,7 +59,7 @@ export class DotnetCoreInstaller {
} }
// Need to set this so that .NET Core global tools find the right locations. // Need to set this so that .NET Core global tools find the right locations.
core.exportVariable('DOTNET_ROOT', path.join(toolPath, '../..')); core.exportVariable('DOTNET_ROOT', toolPath);
// Prepend the tools path. instructs the agent to prepend for future tasks // Prepend the tools path. instructs the agent to prepend for future tasks
core.addPath(toolPath); core.addPath(toolPath);
@ -187,43 +187,46 @@ export class DotnetCoreInstaller {
version: string version: string
): Promise<string[]> { ): Promise<string[]> {
let downloadUrls: string[] = []; let downloadUrls: string[] = [];
let releasesJSON = await this.getReleasesJson();
core.debug('Releases: ' + releasesJSON);
let releasesInfo = JSON.parse(await releasesJSON.readBody()); const httpCallbackClient = new httpClient.HttpClient(
'actions/setup-dotnet',
[],
{}
);
const releasesJsonUrl: string = await this.getReleasesJsonUrl(
httpCallbackClient,
version.split('.')
);
let releasesJSON = await httpCallbackClient.get(releasesJsonUrl);
let releasesInfo: any[] = JSON.parse(await releasesJSON.readBody())[
'releases'
];
releasesInfo = releasesInfo.filter((releaseInfo: any) => { releasesInfo = releasesInfo.filter((releaseInfo: any) => {
return ( return (
releaseInfo['version-sdk'] === version || releaseInfo['sdk']['version'] === version ||
releaseInfo['version-sdk-display'] === version releaseInfo['sdk']['version-display'] === version
); );
}); });
if (releasesInfo.length != 0) { if (releasesInfo.length != 0) {
let release = releasesInfo[0]; let release = releasesInfo[0];
let blobUrl: string = release['blob-sdk']; let files: any[] = release['sdk']['files'];
let dlcUrl: string = release['dlc--sdk']; files = files.filter((file: any) => {
let fileName: string = release['sdk-' + osSuffixes[0]] if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) {
? release['sdk-' + osSuffixes[0]] return (
: release['sdk-' + osSuffixes[1]]; file['url'].endsWith('.zip') || file['url'].endsWith('.tar.gz')
);
if (!!fileName) {
fileName = fileName.trim();
// For some latest version, the filename itself can be full download url.
// Do a very basic check for url(instead of regex) as the url is only for downloading and
// is coming from .net core releases json and not some ransom user input
if (fileName.toLowerCase().startsWith('https://')) {
downloadUrls.push(fileName);
} else {
if (!!blobUrl) {
downloadUrls.push(util.format('%s%s', blobUrl.trim(), fileName));
}
if (!!dlcUrl) {
downloadUrls.push(util.format('%s%s', dlcUrl.trim(), fileName));
}
} }
});
if (files.length > 0) {
files.forEach((file: any) => {
downloadUrls.push(file['url']);
});
} else { } else {
throw `The specified version's download links are not correctly formed in the supported versions document => ${DotNetCoreReleasesUrl}`; throw `The specified version's download links are not correctly formed in the supported versions document => ${releasesJsonUrl}`;
} }
} else { } else {
console.log( console.log(
@ -241,9 +244,30 @@ export class DotnetCoreInstaller {
return downloadUrls; return downloadUrls;
} }
private getReleasesJson(): Promise<HttpClientResponse> { private async getReleasesJsonUrl(
var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {}); httpCallbackClient: httpClient.HttpClient,
return httpCallbackClient.get(DotNetCoreReleasesUrl); versionParts: string[]
): Promise<string> {
const releasesIndex: HttpClientResponse = await httpCallbackClient.get(
DotNetCoreIndexUrl
);
let releasesInfo: any[] = JSON.parse(await releasesIndex.readBody())[
'releases-index'
];
releasesInfo = releasesInfo.filter((info: any) => {
// channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x.
const sdkParts: string[] = info['channel-version'].split('.');
if (versionParts.length >= 2 && versionParts[1] != 'x') {
return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1];
}
return versionParts[0] == sdkParts[0];
});
if (releasesInfo.length === 0) {
throw `Could not find info for version ${versionParts.join(
'.'
)} at ${DotNetCoreIndexUrl}`;
}
return releasesInfo[0]['releases.json'];
} }
private async getFallbackDownloadUrls(version: string): Promise<string[]> { private async getFallbackDownloadUrls(version: string): Promise<string[]> {
@ -350,5 +374,5 @@ export class DotnetCoreInstaller {
private arch: string; private arch: string;
} }
const DotNetCoreReleasesUrl: string = const DotNetCoreIndexUrl: string =
'https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases.json'; 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json';

View File

@ -9,6 +9,10 @@ async function run() {
// Version is optional. If supplied, install / use from the tool cache // Version is optional. If supplied, install / use from the tool cache
// If not supplied then task is still used to setup proxy, auth, etc... // If not supplied then task is still used to setup proxy, auth, etc...
// //
console.log(
`::warning::Use the v1 tag to get the last version, master may contain breaking changes and will not contain any required packages in the future. i.e. actions/setup-dotnet@v1`
);
let version = core.getInput('version'); let version = core.getInput('version');
if (!version) { if (!version) {
version = core.getInput('dotnet-version'); version = core.getInput('dotnet-version');