From f7896b6c4cc14a38650502998c74e42a200b715a Mon Sep 17 00:00:00 2001 From: damccorm Date: Thu, 29 Aug 2019 15:10:05 -0400 Subject: [PATCH 01/10] Update from obsolete endpoint --- lib/installer.js | 65 +++++++++++++++++++------------------ src/installer.ts | 84 +++++++++++++++++++++++++++++------------------- 2 files changed, 85 insertions(+), 64 deletions(-) diff --git a/lib/installer.js b/lib/installer.js index 73bded0..fad1a68 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -26,7 +26,6 @@ const fs_1 = require("fs"); const os = __importStar(require("os")); const path = __importStar(require("path")); const semver = __importStar(require("semver")); -const util = __importStar(require("util")); const IS_WINDOWS = process.platform === 'win32'; if (!tempDirectory) { let baseLocation; @@ -175,39 +174,29 @@ class DotnetCoreInstaller { getDownloadUrls(osSuffixes, version) { return __awaiter(this, void 0, void 0, function* () { let downloadUrls = []; - let releasesJSON = yield this.getReleasesJson(); - core.debug('Releases: ' + releasesJSON); - let releasesInfo = JSON.parse(yield releasesJSON.readBody()); + var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {}); + const releasesJsonUrl = yield this.getReleasesJsonUrl(httpCallbackClient, version.split('.')); + let releasesJSON = yield httpCallbackClient.get(releasesJsonUrl); + let releasesInfo = JSON.parse(yield releasesJSON.readBody())['releases']; releasesInfo = releasesInfo.filter((releaseInfo) => { - return (releaseInfo['version-sdk'] === version || - releaseInfo['version-sdk-display'] === version); + return (releaseInfo['sdk']['version'] === version || + releaseInfo['sdk']['version-display'] === version); }); if (releasesInfo.length != 0) { let release = releasesInfo[0]; - let blobUrl = release['blob-sdk']; - let dlcUrl = release['dlc--sdk']; - let fileName = release['sdk-' + osSuffixes[0]] - ? release['sdk-' + osSuffixes[0]] - : 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)); - } + let files = release['sdk']['files']; + files = files.filter((file) => { + if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) { + return (file['url'].endsWith('.zip') || file['url'].endsWith('.tar.gz')); } + }); + if (files.length > 0) { + files.forEach((file) => { + downloadUrls.push(file['url']); + }); } 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 { @@ -221,9 +210,23 @@ class DotnetCoreInstaller { return downloadUrls; }); } - getReleasesJson() { - var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {}); - return httpCallbackClient.get(DotNetCoreReleasesUrl); + getReleasesJsonUrl(httpCallbackClient, versionParts) { + return __awaiter(this, void 0, void 0, function* () { + // First, get the location of the correct releases.json then get that. + const releasesIndex = yield httpCallbackClient.get(DotNetCoreIndexUrl); + let releasesInfo = JSON.parse(yield releasesIndex.readBody())['releases-index']; + releasesInfo = releasesInfo.filter((releaseInfo) => { + const sdkParts = releaseInfo['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 this version at ${DotNetCoreIndexUrl}`; + } + return releasesInfo[0]['releases.json']; + }); } getFallbackDownloadUrls(version) { return __awaiter(this, void 0, void 0, function* () { @@ -306,4 +309,4 @@ class 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'; diff --git a/src/installer.ts b/src/installer.ts index 4e620e1..dc0cbdb 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -186,44 +186,43 @@ export class DotnetCoreInstaller { osSuffixes: string[], version: string ): Promise { - let downloadUrls = []; - let releasesJSON = await this.getReleasesJson(); - core.debug('Releases: ' + releasesJSON); + let downloadUrls: string[] = []; - let releasesInfo = JSON.parse(await releasesJSON.readBody()); + var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {}); + const releasesJsonUrl = 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) => { return ( - releaseInfo['version-sdk'] === version || - releaseInfo['version-sdk-display'] === version + releaseInfo['sdk']['version'] === version || + releaseInfo['sdk']['version-display'] === version ); }); if (releasesInfo.length != 0) { let release = releasesInfo[0]; - let blobUrl: string = release['blob-sdk']; - let dlcUrl: string = release['dlc--sdk']; - let fileName: string = release['sdk-' + osSuffixes[0]] - ? release['sdk-' + osSuffixes[0]] - : 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)); - } + let files = release['sdk']['files']; + files = files.filter((file: any) => { + if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) { + return ( + file['url'].endsWith('.zip') || file['url'].endsWith('.tar.gz') + ); } + }); + + if (files.length > 0) { + files.forEach((file: any) => { + downloadUrls.push(file['url']); + }); } 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 { console.log( @@ -241,9 +240,28 @@ export class DotnetCoreInstaller { return downloadUrls; } - private getReleasesJson(): Promise { - var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {}); - return httpCallbackClient.get(DotNetCoreReleasesUrl); + private async getReleasesJsonUrl( + httpCallbackClient: httpClient.HttpClient, + versionParts: string[] + ): Promise { + // First, get the location of the correct releases.json then get that. + const releasesIndex: HttpClientResponse = await httpCallbackClient.get( + DotNetCoreIndexUrl + ); + let releasesInfo = JSON.parse(await releasesIndex.readBody())[ + 'releases-index' + ]; + releasesInfo = releasesInfo.filter((releaseInfo: any) => { + const sdkParts: string[] = releaseInfo['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 this version at ${DotNetCoreIndexUrl}`; + } + return releasesInfo[0]['releases.json']; } private async getFallbackDownloadUrls(version: string): Promise { @@ -350,5 +368,5 @@ export class DotnetCoreInstaller { private arch: string; } -const DotNetCoreReleasesUrl: string = - 'https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases.json'; +const DotNetCoreIndexUrl: string = + 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json'; From e28ad717b826ad4e949a5dd731c71fbfd43f5845 Mon Sep 17 00:00:00 2001 From: damccorm Date: Thu, 29 Aug 2019 16:15:06 -0400 Subject: [PATCH 02/10] Feedback --- lib/installer.js | 10 +++++----- src/installer.ts | 22 ++++++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/installer.js b/lib/installer.js index fad1a68..159c5b3 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -174,7 +174,7 @@ class DotnetCoreInstaller { getDownloadUrls(osSuffixes, version) { return __awaiter(this, void 0, void 0, function* () { let downloadUrls = []; - var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {}); + const httpCallbackClient = new httpClient.HttpClient('actions/setup-dotnet', [], {}); const releasesJsonUrl = yield this.getReleasesJsonUrl(httpCallbackClient, version.split('.')); let releasesJSON = yield httpCallbackClient.get(releasesJsonUrl); let releasesInfo = JSON.parse(yield releasesJSON.readBody())['releases']; @@ -212,18 +212,18 @@ class DotnetCoreInstaller { } getReleasesJsonUrl(httpCallbackClient, versionParts) { return __awaiter(this, void 0, void 0, function* () { - // First, get the location of the correct releases.json then get that. const releasesIndex = yield httpCallbackClient.get(DotNetCoreIndexUrl); let releasesInfo = JSON.parse(yield releasesIndex.readBody())['releases-index']; - releasesInfo = releasesInfo.filter((releaseInfo) => { - const sdkParts = releaseInfo['channel-version'].split('.'); + 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 this version at ${DotNetCoreIndexUrl}`; + throw `Could not find info for version ${versionParts.join('.')} at ${DotNetCoreIndexUrl}`; } return releasesInfo[0]['releases.json']; }); diff --git a/src/installer.ts b/src/installer.ts index dc0cbdb..265bc8e 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -188,8 +188,12 @@ export class DotnetCoreInstaller { ): Promise { let downloadUrls: string[] = []; - var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {}); - const releasesJsonUrl = await this.getReleasesJsonUrl( + const httpCallbackClient = new httpClient.HttpClient( + 'actions/setup-dotnet', + [], + {} + ); + const releasesJsonUrl: string = await this.getReleasesJsonUrl( httpCallbackClient, version.split('.') ); @@ -208,7 +212,7 @@ export class DotnetCoreInstaller { if (releasesInfo.length != 0) { let release = releasesInfo[0]; - let files = release['sdk']['files']; + let files: any[] = release['sdk']['files']; files = files.filter((file: any) => { if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) { return ( @@ -244,22 +248,24 @@ export class DotnetCoreInstaller { httpCallbackClient: httpClient.HttpClient, versionParts: string[] ): Promise { - // First, get the location of the correct releases.json then get that. const releasesIndex: HttpClientResponse = await httpCallbackClient.get( DotNetCoreIndexUrl ); - let releasesInfo = JSON.parse(await releasesIndex.readBody())[ + let releasesInfo: any[] = JSON.parse(await releasesIndex.readBody())[ 'releases-index' ]; - releasesInfo = releasesInfo.filter((releaseInfo: any) => { - const sdkParts: string[] = releaseInfo['channel-version'].split('.'); + 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 this version at ${DotNetCoreIndexUrl}`; + throw `Could not find info for version ${versionParts.join( + '.' + )} at ${DotNetCoreIndexUrl}`; } return releasesInfo[0]['releases.json']; } From a668ade667b3edbafe8068d6b408a5a8c9997361 Mon Sep 17 00:00:00 2001 From: Robert Jeppesen Date: Wed, 11 Sep 2019 20:22:37 +0200 Subject: [PATCH 03/10] Include version/architecture in DOTNET_ROOT Fixes #29 --- lib/installer.js | 2 +- src/installer.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/installer.js b/lib/installer.js index 73bded0..41c3b2c 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -73,7 +73,7 @@ class DotnetCoreInstaller { console.log('Using cached tool'); } // 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 core.addPath(toolPath); }); diff --git a/src/installer.ts b/src/installer.ts index 4e620e1..1979227 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -59,7 +59,7 @@ export class DotnetCoreInstaller { } // 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 core.addPath(toolPath); From c61e78b5854116c69762902be74bebdb79dd382b Mon Sep 17 00:00:00 2001 From: Chris Patterson Date: Thu, 10 Oct 2019 14:48:45 -0400 Subject: [PATCH 04/10] Fixed matcher regex --- .github/csc.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/csc.json b/.github/csc.json index 764ede5..c5c47ef 100644 --- a/.github/csc.json +++ b/.github/csc.json @@ -1,10 +1,10 @@ { "problemMatcher": [ { - "owner": "csc", + "owner": "msCompile", "pattern": [ { - "regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(CS\\d+)\\s*:\\s*(.*)$", + "regexp": "^(?:\\s+\\d+\\>)?([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\)\\s*:\\s+(error|warning|info)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$", "file": 1, "location": 2, "severity": 3, From d9c317d9d5f7adf485b8378b3a493539653b4cf5 Mon Sep 17 00:00:00 2001 From: Chris Patterson Date: Thu, 10 Oct 2019 14:51:48 -0400 Subject: [PATCH 05/10] Revert "Fixed matcher regex" This reverts commit c61e78b5854116c69762902be74bebdb79dd382b. --- .github/csc.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/csc.json b/.github/csc.json index c5c47ef..764ede5 100644 --- a/.github/csc.json +++ b/.github/csc.json @@ -1,10 +1,10 @@ { "problemMatcher": [ { - "owner": "msCompile", + "owner": "csc", "pattern": [ { - "regexp": "^(?:\\s+\\d+\\>)?([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\)\\s*:\\s+(error|warning|info)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$", + "regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(CS\\d+)\\s*:\\s*(.*)$", "file": 1, "location": 2, "severity": 3, From d6b77de15f7ba6689c6c0c8f5f013d11c0e8a0ce Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Thu, 10 Oct 2019 19:41:56 -0400 Subject: [PATCH 06/10] Update external install scripts --- externals/install-dotnet.ps1 | 14 +++++++++++++- externals/install-dotnet.sh | 8 +++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/externals/install-dotnet.ps1 b/externals/install-dotnet.ps1 index f17bd85..2ff62da 100644 --- a/externals/install-dotnet.ps1 +++ b/externals/install-dotnet.ps1 @@ -46,6 +46,7 @@ Possible values: - dotnet - the Microsoft.NETCore.App shared runtime - aspnetcore - the Microsoft.AspNetCore.App shared runtime + - windowsdesktop - the Microsoft.WindowsDesktop.App shared runtime .PARAMETER DryRun 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 @@ -83,7 +84,7 @@ param( [string]$Version="Latest", [string]$InstallDir="", [string]$Architecture="", - [ValidateSet("dotnet", "aspnetcore", IgnoreCase = $false)] + [ValidateSet("dotnet", "aspnetcore", "windowsdesktop", IgnoreCase = $false)] [string]$Runtime, [Obsolete("This parameter may be removed in a future version of this script. The recommended alternative is '-Runtime dotnet'.")] [switch]$SharedRuntime, @@ -268,6 +269,10 @@ function Get-Latest-Version-Info([string]$AzureFeed, [string]$Channel, [bool]$Co elseif ($Runtime -eq "aspnetcore") { $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) { if ($Coherent) { $VersionFileUrl = "$UncachedFeed/Sdk/$Channel/latest.coherent.version" @@ -325,6 +330,9 @@ function Get-Download-Link([string]$AzureFeed, [string]$SpecificVersion, [string elseif ($Runtime -eq "aspnetcore") { $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) { $PayloadURL = "$AzureFeed/Sdk/$SpecificVersion/dotnet-sdk-$SpecificVersion-win-$CLIArchitecture.zip" } @@ -564,6 +572,10 @@ elseif ($Runtime -eq "aspnetcore") { $assetName = "ASP.NET Core Runtime" $dotnetPackageRelativePath = "shared\Microsoft.AspNetCore.App" } +elseif ($Runtime -eq "windowsdesktop") { + $assetName = ".NET Core Windows Desktop Runtime" + $dotnetPackageRelativePath = "shared\Microsoft.WindowsDesktop.App" +} elseif (-not $Runtime) { $assetName = ".NET Core SDK" $dotnetPackageRelativePath = "sdk" diff --git a/externals/install-dotnet.sh b/externals/install-dotnet.sh index 2217d47..6133704 100644 --- a/externals/install-dotnet.sh +++ b/externals/install-dotnet.sh @@ -148,7 +148,7 @@ get_linux_platform_name() { return 0 elif [ -e /etc/redhat-release ]; then local redhatRelease=$( Date: Thu, 10 Oct 2019 19:52:12 -0400 Subject: [PATCH 07/10] Run tests on pull requests --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 22e0e06..0b95177 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,5 +1,5 @@ name: Main workflow -on: [push] +on: [push, pull_request] jobs: run: name: Run From bb17c31bebcce9c656a110e3a64c8e3b6210ef82 Mon Sep 17 00:00:00 2001 From: Zachary Eisinger Date: Mon, 21 Oct 2019 07:51:03 -0700 Subject: [PATCH 08/10] Update README to show real matrix examples Makes the README more clear about environment being set-up and gives valid examples of versions that can be installed. Fixes #43 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a31feb5..a690ee9 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ GitHub Actions status

-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 - registering problem matchers for error output @@ -30,7 +30,7 @@ jobs: runs-on: ubuntu-16.04 strategy: 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 steps: - uses: actions/checkout@master From e1b1954735348cd3b65a85ba6659d01f785b970f Mon Sep 17 00:00:00 2001 From: Zachary Eisinger Date: Thu, 24 Oct 2019 13:32:42 -0700 Subject: [PATCH 09/10] Warn on master (#45) Add warning message when running on master --- lib/installer.js | 3 ++- lib/setup-dotnet.js | 4 +++- src/setup-dotnet.ts | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/installer.js b/lib/installer.js index 527eafd..bef24da 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -1,9 +1,10 @@ "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; diff --git a/lib/setup-dotnet.js b/lib/setup-dotnet.js index 17d922c..1c4cdae 100644 --- a/lib/setup-dotnet.js +++ b/lib/setup-dotnet.js @@ -1,9 +1,10 @@ "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; @@ -25,6 +26,7 @@ function run() { // Version is optional. If supplied, install / use from the tool cache // 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'); if (!version) { version = core.getInput('dotnet-version'); diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 8e491e9..eee984d 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -8,6 +8,10 @@ async function run() { // Version is optional. If supplied, install / use from the tool cache // 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'); if (!version) { version = core.getInput('dotnet-version'); From 719c622d485b1115e319aff474d105a8b489a90b Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 8 Nov 2019 17:02:16 +0100 Subject: [PATCH 10/10] Updating Install Scripts (#48) * Updating install scripts * Ignore items in node_modules by default * Updating scripts updated by commit-hooks * Modifying the correct files --- .gitignore | 1 + externals/install-dotnet.ps1 | 91 ++++++++++++++++--------- externals/install-dotnet.sh | 125 +++++++++++++++++++++++------------ lib/installer.js | 3 +- lib/setup-dotnet.js | 3 +- 5 files changed, 144 insertions(+), 79 deletions(-) diff --git a/.gitignore b/.gitignore index 25b580b..57017a7 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,4 @@ typings/ # DynamoDB Local files .dynamodb/ +node_modules diff --git a/externals/install-dotnet.ps1 b/externals/install-dotnet.ps1 index 2ff62da..6dedd84 100644 --- a/externals/install-dotnet.ps1 +++ b/externals/install-dotnet.ps1 @@ -37,10 +37,7 @@ .PARAMETER SharedRuntime This parameter is obsolete and may be removed in a future version of this script. The recommended alternative is '-Runtime dotnet'. - - Default: false Installs just the shared runtime bits, not the entire SDK. - This is equivalent to specifying `-Runtime dotnet`. .PARAMETER Runtime Installs just a shared runtime, not the entire SDK. Possible values: @@ -77,11 +74,15 @@ Skips installing non-versioned files if they already exist, such as dotnet.exe. .PARAMETER NoCdn 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()] param( [string]$Channel="LTS", [string]$Version="Latest", + [string]$JSonFile, [string]$InstallDir="", [string]$Architecture="", [ValidateSet("dotnet", "aspnetcore", "windowsdesktop", IgnoreCase = $false)] @@ -258,7 +259,6 @@ function GetHTTPResponse([Uri] $Uri) }) } - function Get-Latest-Version-Info([string]$AzureFeed, [string]$Channel, [bool]$Coherent) { Say-Invocation $MyInvocation @@ -304,20 +304,64 @@ function Get-Latest-Version-Info([string]$AzureFeed, [string]$Channel, [bool]$Co return $VersionInfo } - -function Get-Specific-Version-From-Version([string]$AzureFeed, [string]$Channel, [string]$Version) { +function Parse-Jsonfile-For-Version([string]$JSonFile) { Say-Invocation $MyInvocation - switch ($Version.ToLower()) { - { $_ -eq "latest" } { - $LatestVersionInfo = Get-Latest-Version-Info -AzureFeed $AzureFeed -Channel $Channel -Coherent $False - return $LatestVersionInfo.Version + If (-Not (Test-Path $JSonFile)) { + throw "Unable to find '$JSonFile'" + exit 0 + } + 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" } { - $LatestVersionInfo = Get-Latest-Version-Info -AzureFeed $AzureFeed -Channel $Channel -Coherent $True - return $LatestVersionInfo.Version + catch { + throw "Unable to parse the SDK node in '$JSonFile'" + 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 } } @@ -382,23 +426,6 @@ function Resolve-Installation-Path([string]$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) { Say-Invocation $MyInvocation @@ -534,7 +561,7 @@ function Prepend-Sdk-InstallRoot-To-Path([string]$InstallRoot, [string]$BinFolde } $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 $LegacyDownloadLink = Get-LegacyDownload-Link -AzureFeed $AzureFeed -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture diff --git a/externals/install-dotnet.sh b/externals/install-dotnet.sh index 6133704..b46c343 100644 --- a/externals/install-dotnet.sh +++ b/externals/install-dotnet.sh @@ -435,11 +435,52 @@ get_latest_version_info() { 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: # azure_feed - $1 # channel - $2 # normalized_architecture - $3 # version - $4 +# json_file - $5 get_specific_version_from_version() { eval $invocation @@ -447,27 +488,35 @@ get_specific_version_from_version() { local channel="$2" local normalized_architecture="$3" local version="$(to_lowercase "$4")" + local json_file="$5" - case "$version" in - latest) - local version_info - version_info="$(get_latest_version_info "$azure_feed" "$channel" "$normalized_architecture" false)" || return 1 - say_verbose "get_specific_version_from_version: version_info=$version_info" - echo "$version_info" | get_version_from_version_info - return 0 - ;; - coherent) - local version_info - version_info="$(get_latest_version_info "$azure_feed" "$channel" "$normalized_architecture" true)" || return 1 - say_verbose "get_specific_version_from_version: version_info=$version_info" - echo "$version_info" | get_version_from_version_info - return 0 - ;; - *) - echo "$version" - return 0 - ;; - esac + if [ -z "$json_file" ]; then + case "$version" in + latest) + local version_info + version_info="$(get_latest_version_info "$azure_feed" "$channel" "$normalized_architecture" false)" || return 1 + say_verbose "get_specific_version_from_version: version_info=$version_info" + echo "$version_info" | get_version_from_version_info + return 0 + ;; + coherent) + local version_info + version_info="$(get_latest_version_info "$azure_feed" "$channel" "$normalized_architecture" true)" || return 1 + say_verbose "get_specific_version_from_version: version_info=$version_info" + echo "$version_info" | get_version_from_version_info + return 0 + ;; + *) + echo "$version" + return 0 + ;; + esac + else + local version_info + version_info="$(parse_jsonfile_for_version "$json_file")" || return 1 + echo "$version_info" + return 0 + fi } # args: @@ -558,24 +607,6 @@ resolve_installation_path() { 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: # relative_or_absolute_path - $1 get_absolute_path() { @@ -724,7 +755,7 @@ calculate_vars() { normalized_architecture="$(get_normalized_architecture_from_architecture "$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" if [ -z "$specific_version" ]; then say_err "Could not resolve version information." @@ -826,6 +857,7 @@ temporary_file_template="${TMPDIR:-/tmp}/dotnet.XXXXXXXXX" channel="LTS" version="Latest" +json_file="" install_dir="" architecture="" dry_run=false @@ -912,6 +944,10 @@ do runtime_id="$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) override_non_versioned_files=false non_dynamic_parameters+=" $name" @@ -953,22 +989,25 @@ do echo " Possible values:" echo " - dotnet - the Microsoft.NETCore.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 " --no-path, -NoPath Do not set PATH for the current process." 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 " --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 " --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 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 " -RuntimeId" echo " -?,--?,-h,--help,-Help Shows this help message" echo "" echo "Obsolete parameters:" 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 "Install Location:" echo " Location is chosen in following order:" diff --git a/lib/installer.js b/lib/installer.js index bef24da..527eafd 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -1,10 +1,9 @@ "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; diff --git a/lib/setup-dotnet.js b/lib/setup-dotnet.js index 1c4cdae..7815b6b 100644 --- a/lib/setup-dotnet.js +++ b/lib/setup-dotnet.js @@ -1,10 +1,9 @@ "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); };