From 45c9f236cf9a0c09d11298348f6ed06bd81914c0 Mon Sep 17 00:00:00 2001 From: Ivan <98037481+IvanZosimov@users.noreply.github.com> Date: Tue, 4 Oct 2022 10:22:05 +0200 Subject: [PATCH 1/3] Enable ability to change .NET SDK installation directory by `DOTNET_INSTALL_DIR` environment variable (#329) --- README.md | 3 ++- dist/index.js | 27 ++++++++++++++++----------- package-lock.json | 4 ++-- package.json | 2 +- src/installer.ts | 37 +++++++++++++++++-------------------- src/utils.ts | 1 - 6 files changed, 38 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index c802711..382465b 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,7 @@ Some environment variables may be necessary for your particular case or to impro | **Env.variable** | **Description** | **Default value** | | ----------- | ----------- | ----------- | +| DOTNET_INSTALL_DIR |Specifies a directory where .NET SDKs should be installed by the action|*isn't set*| | DOTNET_NOLOGO |Removes logo and telemetry message from first run of dotnet cli|*false*| | DOTNET_CLI_TELEMETRY_OPTOUT |Opt-out of telemetry being sent to Microsoft|*false*| | DOTNET_MULTILEVEL_LOOKUP |Configures whether the global install location is used as a fall-back|*true*| @@ -204,7 +205,7 @@ Some environment variables may be necessary for your particular case or to impro build: runs-on: ubuntu-latest env: - DOTNET_NOLOGO: true + DOTNET_INSTALL_DIR: "path/to/directory" steps: - uses: actions/checkout@main - uses: actions/setup-dotnet@v3 diff --git a/dist/index.js b/dist/index.js index 2176821..59deee9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -333,8 +333,10 @@ class DotnetCoreInstaller { if (process.env['no_proxy'] != null) { scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); } - scriptArguments.push('-InstallDir', `'${DotnetCoreInstaller.installationDirectoryWindows}'`); - // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used + if (!process.env['DOTNET_INSTALL_DIR']) { + process.env['DOTNET_INSTALL_DIR'] = + DotnetCoreInstaller.installationDirectoryWindows; + } scriptPath = (yield io.which('pwsh', false)) || (yield io.which('powershell', true)); scriptArguments = windowsDefaultOptions.concat(scriptArguments); @@ -349,18 +351,22 @@ class DotnetCoreInstaller { if (this.quality) { this.setQuality(dotnetVersion, scriptArguments); } - if (utils_1.IS_LINUX) { - scriptArguments.push('--install-dir', DotnetCoreInstaller.installationDirectoryLinux); - } - if (utils_1.IS_MAC) { - scriptArguments.push('--install-dir', DotnetCoreInstaller.installationDirectoryMac); + if (!process.env['DOTNET_INSTALL_DIR']) { + process.env['DOTNET_INSTALL_DIR'] = utils_1.IS_LINUX + ? DotnetCoreInstaller.installationDirectoryLinux + : DotnetCoreInstaller.installationDirectoryMac; } } - const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, { ignoreReturnCode: true }); + // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used + const getExecOutputOptions = { + ignoreReturnCode: true, + env: process.env + }; + const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, getExecOutputOptions); if (exitCode) { throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); } - return this.outputDotnetVersion(dotnetVersion.value, scriptArguments[scriptArguments.length - 1]); + return this.outputDotnetVersion(dotnetVersion.value, process.env['DOTNET_INSTALL_DIR']); }); } outputDotnetVersion(version, installationPath) { @@ -523,10 +529,9 @@ run(); "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.IS_MAC = exports.IS_LINUX = exports.IS_WINDOWS = void 0; +exports.IS_LINUX = exports.IS_WINDOWS = void 0; exports.IS_WINDOWS = process.platform === 'win32'; exports.IS_LINUX = process.platform === 'linux'; -exports.IS_MAC = process.platform === 'darwin'; /***/ }), diff --git a/package-lock.json b/package-lock.json index 98bc5c5..5459e0f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "setup-dotnet", - "version": "3.0.0", + "version": "3.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "setup-dotnet", - "version": "3.0.0", + "version": "3.0.1", "license": "MIT", "dependencies": { "@actions/core": "^1.9.1", diff --git a/package.json b/package.json index 5838e4d..b58554c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "setup-dotnet", - "version": "3.0.0", + "version": "3.0.1", "private": true, "description": "setup dotnet action", "main": "lib/setup-dotnet.js", diff --git a/src/installer.ts b/src/installer.ts index 041b655..f7730a6 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -7,7 +7,7 @@ import {chmodSync} from 'fs'; import {readdir} from 'fs/promises'; import path from 'path'; import semver from 'semver'; -import {IS_LINUX, IS_WINDOWS, IS_MAC} from './utils'; +import {IS_LINUX, IS_WINDOWS} from './utils'; import {QualityOptions} from './setup-dotnet'; export interface DotnetVersion { @@ -208,11 +208,11 @@ export class DotnetCoreInstaller { scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); } - scriptArguments.push( - '-InstallDir', - `'${DotnetCoreInstaller.installationDirectoryWindows}'` - ); - // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used + if (!process.env['DOTNET_INSTALL_DIR']) { + process.env['DOTNET_INSTALL_DIR'] = + DotnetCoreInstaller.installationDirectoryWindows; + } + scriptPath = (await io.which('pwsh', false)) || (await io.which('powershell', true)); scriptArguments = windowsDefaultOptions.concat(scriptArguments); @@ -229,24 +229,21 @@ export class DotnetCoreInstaller { this.setQuality(dotnetVersion, scriptArguments); } - if (IS_LINUX) { - scriptArguments.push( - '--install-dir', - DotnetCoreInstaller.installationDirectoryLinux - ); - } - - if (IS_MAC) { - scriptArguments.push( - '--install-dir', - DotnetCoreInstaller.installationDirectoryMac - ); + if (!process.env['DOTNET_INSTALL_DIR']) { + process.env['DOTNET_INSTALL_DIR'] = IS_LINUX + ? DotnetCoreInstaller.installationDirectoryLinux + : DotnetCoreInstaller.installationDirectoryMac; } } + // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used + const getExecOutputOptions = { + ignoreReturnCode: true, + env: process.env as {string: string} + }; const {exitCode, stdout} = await exec.getExecOutput( `"${scriptPath}"`, scriptArguments, - {ignoreReturnCode: true} + getExecOutputOptions ); if (exitCode) { throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); @@ -254,7 +251,7 @@ export class DotnetCoreInstaller { return this.outputDotnetVersion( dotnetVersion.value, - scriptArguments[scriptArguments.length - 1] + process.env['DOTNET_INSTALL_DIR'] ); } diff --git a/src/utils.ts b/src/utils.ts index ff20ee3..77886ce 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,2 @@ export const IS_WINDOWS = process.platform === 'win32'; export const IS_LINUX = process.platform === 'linux'; -export const IS_MAC = process.platform === 'darwin'; From 92606438168a6a25f2939b37f03d67816d27b1c5 Mon Sep 17 00:00:00 2001 From: Francesco Renzi Date: Thu, 6 Oct 2022 12:05:06 +0100 Subject: [PATCH 2/3] Update @actions/core to 1.10.0 --- .licenses/npm/@actions/core.dep.yml | Bin 1303 -> 1304 bytes dist/index.js | 1063 ++++++++++++++------------- package-lock.json | 14 +- package.json | 2 +- 4 files changed, 547 insertions(+), 532 deletions(-) diff --git a/.licenses/npm/@actions/core.dep.yml b/.licenses/npm/@actions/core.dep.yml index 2e0762e41b02be6564d88601b850e7b653993aa7..a2682b834ca92e59bdad37339d721e67eb0cb076 100644 GIT binary patch delta 15 WcmbQvHG^w{DvP0kp20?q_bdP-WCVx+ delta 14 VcmbQiHJxjMDzl}Y;YQ8(EC3)N1YrOG diff --git a/dist/index.js b/dist/index.js index 59deee9..fb2365b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5,142 +5,142 @@ /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.configAuthentication = void 0; -const fs = __importStar(__nccwpck_require__(7147)); -const path = __importStar(__nccwpck_require__(1017)); -const core = __importStar(__nccwpck_require__(2186)); -const github = __importStar(__nccwpck_require__(5438)); -const xmlbuilder = __importStar(__nccwpck_require__(2958)); -const xmlParser = __importStar(__nccwpck_require__(7448)); -function configAuthentication(feedUrl, existingFileLocation = '', processRoot = process.cwd()) { - const existingNuGetConfig = path.resolve(processRoot, existingFileLocation === '' - ? getExistingNugetConfig(processRoot) - : existingFileLocation); - const tempNuGetConfig = path.resolve(processRoot, '../', 'nuget.config'); - writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig); -} -exports.configAuthentication = configAuthentication; -function isValidKey(key) { - return /^[\w\-\.]+$/i.test(key); -} -function getExistingNugetConfig(processRoot) { - const defaultConfigName = 'nuget.config'; - const configFileNames = fs - .readdirSync(processRoot) - .filter(filename => filename.toLowerCase() === defaultConfigName); - if (configFileNames.length) { - return configFileNames[0]; - } - return defaultConfigName; -} -function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) { - core.info(`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`); - let xml; - let sourceKeys = []; - let owner = core.getInput('owner'); - let sourceUrl = feedUrl; - if (!owner) { - owner = github.context.repo.owner; - } - if (!process.env.NUGET_AUTH_TOKEN) { - throw new Error('The NUGET_AUTH_TOKEN environment variable was not provided. In this step, add the following: \r\nenv:\r\n NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}'); - } - if (fs.existsSync(existingFileLocation)) { - // get key from existing NuGet.config so NuGet/dotnet can match credentials - const curContents = fs.readFileSync(existingFileLocation, 'utf8'); - const json = xmlParser.parse(curContents, { ignoreAttributes: false }); - if (typeof json.configuration === 'undefined') { - throw new Error(`The provided NuGet.config seems invalid.`); - } - if (typeof json.configuration.packageSources != 'undefined') { - if (typeof json.configuration.packageSources.add != 'undefined') { - // file has at least one - if (typeof json.configuration.packageSources.add[0] === 'undefined') { - // file has only one - if (json.configuration.packageSources.add['@_value'] - .toLowerCase() - .includes(feedUrl.toLowerCase())) { - const key = json.configuration.packageSources.add['@_key']; - sourceKeys.push(key); - core.debug(`Found a URL with key ${key}`); - } - } - else { - // file has 2+ - for (let i = 0; i < json.configuration.packageSources.add.length; i++) { - const source = json.configuration.packageSources.add[i]; - const value = source['@_value']; - core.debug(`source '${value}'`); - if (value.toLowerCase().includes(feedUrl.toLowerCase())) { - const key = source['@_key']; - sourceKeys.push(key); - core.debug(`Found a URL with key ${key}`); - } - } - } - } - } - } - xml = xmlbuilder - .create('configuration') - .ele('config') - .ele('add', { key: 'defaultPushSource', value: sourceUrl }) - .up() - .up(); - if (!sourceKeys.length) { - let keystring = 'Source'; - xml = xml - .ele('packageSources') - .ele('add', { key: keystring, value: sourceUrl }) - .up() - .up(); - sourceKeys.push(keystring); - } - xml = xml.ele('packageSourceCredentials'); - sourceKeys.forEach(key => { - if (!isValidKey(key)) { - throw new Error("Source name can contain letters, numbers, and '-', '_', '.' symbols only. Please, fix source name in NuGet.config and try again."); - } - xml = xml - .ele(key) - .ele('add', { key: 'Username', value: owner }) - .up() - .ele('add', { - key: 'ClearTextPassword', - value: process.env.NUGET_AUTH_TOKEN - }) - .up() - .up(); - }); - // If NuGet fixes itself such that on Linux it can look for environment variables in the config file (it doesn't seem to work today), - // use this for the value above - // process.platform == 'win32' - // ? '%NUGET_AUTH_TOKEN%' - // : '$NUGET_AUTH_TOKEN' - const output = xml.end({ pretty: true }); - fs.writeFileSync(tempFileLocation, output); -} + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.configAuthentication = void 0; +const fs = __importStar(__nccwpck_require__(7147)); +const path = __importStar(__nccwpck_require__(1017)); +const core = __importStar(__nccwpck_require__(2186)); +const github = __importStar(__nccwpck_require__(5438)); +const xmlbuilder = __importStar(__nccwpck_require__(2958)); +const xmlParser = __importStar(__nccwpck_require__(7448)); +function configAuthentication(feedUrl, existingFileLocation = '', processRoot = process.cwd()) { + const existingNuGetConfig = path.resolve(processRoot, existingFileLocation === '' + ? getExistingNugetConfig(processRoot) + : existingFileLocation); + const tempNuGetConfig = path.resolve(processRoot, '../', 'nuget.config'); + writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig); +} +exports.configAuthentication = configAuthentication; +function isValidKey(key) { + return /^[\w\-\.]+$/i.test(key); +} +function getExistingNugetConfig(processRoot) { + const defaultConfigName = 'nuget.config'; + const configFileNames = fs + .readdirSync(processRoot) + .filter(filename => filename.toLowerCase() === defaultConfigName); + if (configFileNames.length) { + return configFileNames[0]; + } + return defaultConfigName; +} +function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) { + core.info(`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`); + let xml; + let sourceKeys = []; + let owner = core.getInput('owner'); + let sourceUrl = feedUrl; + if (!owner) { + owner = github.context.repo.owner; + } + if (!process.env.NUGET_AUTH_TOKEN) { + throw new Error('The NUGET_AUTH_TOKEN environment variable was not provided. In this step, add the following: \r\nenv:\r\n NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}'); + } + if (fs.existsSync(existingFileLocation)) { + // get key from existing NuGet.config so NuGet/dotnet can match credentials + const curContents = fs.readFileSync(existingFileLocation, 'utf8'); + const json = xmlParser.parse(curContents, { ignoreAttributes: false }); + if (typeof json.configuration === 'undefined') { + throw new Error(`The provided NuGet.config seems invalid.`); + } + if (typeof json.configuration.packageSources != 'undefined') { + if (typeof json.configuration.packageSources.add != 'undefined') { + // file has at least one + if (typeof json.configuration.packageSources.add[0] === 'undefined') { + // file has only one + if (json.configuration.packageSources.add['@_value'] + .toLowerCase() + .includes(feedUrl.toLowerCase())) { + const key = json.configuration.packageSources.add['@_key']; + sourceKeys.push(key); + core.debug(`Found a URL with key ${key}`); + } + } + else { + // file has 2+ + for (let i = 0; i < json.configuration.packageSources.add.length; i++) { + const source = json.configuration.packageSources.add[i]; + const value = source['@_value']; + core.debug(`source '${value}'`); + if (value.toLowerCase().includes(feedUrl.toLowerCase())) { + const key = source['@_key']; + sourceKeys.push(key); + core.debug(`Found a URL with key ${key}`); + } + } + } + } + } + } + xml = xmlbuilder + .create('configuration') + .ele('config') + .ele('add', { key: 'defaultPushSource', value: sourceUrl }) + .up() + .up(); + if (!sourceKeys.length) { + let keystring = 'Source'; + xml = xml + .ele('packageSources') + .ele('add', { key: keystring, value: sourceUrl }) + .up() + .up(); + sourceKeys.push(keystring); + } + xml = xml.ele('packageSourceCredentials'); + sourceKeys.forEach(key => { + if (!isValidKey(key)) { + throw new Error("Source name can contain letters, numbers, and '-', '_', '.' symbols only. Please, fix source name in NuGet.config and try again."); + } + xml = xml + .ele(key) + .ele('add', { key: 'Username', value: owner }) + .up() + .ele('add', { + key: 'ClearTextPassword', + value: process.env.NUGET_AUTH_TOKEN + }) + .up() + .up(); + }); + // If NuGet fixes itself such that on Linux it can look for environment variables in the config file (it doesn't seem to work today), + // use this for the value above + // process.platform == 'win32' + // ? '%NUGET_AUTH_TOKEN%' + // : '$NUGET_AUTH_TOKEN' + const output = xml.end({ pretty: true }); + fs.writeFileSync(tempFileLocation, output); +} /***/ }), @@ -149,240 +149,240 @@ function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) { /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -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); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.DotnetCoreInstaller = exports.DotnetVersionResolver = void 0; -// Load tempDirectory before it gets wiped by tool-cache -const core = __importStar(__nccwpck_require__(2186)); -const exec = __importStar(__nccwpck_require__(1514)); -const io = __importStar(__nccwpck_require__(7436)); -const hc = __importStar(__nccwpck_require__(6255)); -const fs_1 = __nccwpck_require__(7147); -const promises_1 = __nccwpck_require__(3292); -const path_1 = __importDefault(__nccwpck_require__(1017)); -const semver_1 = __importDefault(__nccwpck_require__(5911)); -const utils_1 = __nccwpck_require__(918); -class DotnetVersionResolver { - constructor(version) { - this.inputVersion = version.trim(); - this.resolvedArgument = { type: '', value: '', qualityFlag: false }; - } - resolveVersionInput() { - return __awaiter(this, void 0, void 0, function* () { - if (!semver_1.default.validRange(this.inputVersion)) { - throw new Error(`'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B, A.B.x, A, A.x`); - } - if (semver_1.default.valid(this.inputVersion)) { - this.resolvedArgument.type = 'version'; - this.resolvedArgument.value = this.inputVersion; - } - else { - const [major, minor] = this.inputVersion.split('.'); - if (this.isNumericTag(major)) { - this.resolvedArgument.type = 'channel'; - if (this.isNumericTag(minor)) { - this.resolvedArgument.value = `${major}.${minor}`; - } - else { - const httpClient = new hc.HttpClient('actions/setup-dotnet', [], { - allowRetries: true, - maxRetries: 3 - }); - this.resolvedArgument.value = yield this.getLatestVersion(httpClient, [major, minor]); - } - } - this.resolvedArgument.qualityFlag = +major >= 6 ? true : false; - } - }); - } - isNumericTag(versionTag) { - return /^\d+$/.test(versionTag); - } - createDotNetVersion() { - return __awaiter(this, void 0, void 0, function* () { - yield this.resolveVersionInput(); - if (!this.resolvedArgument.type) { - return this.resolvedArgument; - } - if (utils_1.IS_WINDOWS) { - this.resolvedArgument.type = - this.resolvedArgument.type === 'channel' ? '-Channel' : '-Version'; - } - else { - this.resolvedArgument.type = - this.resolvedArgument.type === 'channel' ? '--channel' : '--version'; - } - return this.resolvedArgument; - }); - } - getLatestVersion(httpClient, versionParts) { - return __awaiter(this, void 0, void 0, function* () { - const response = yield httpClient.getJson(DotnetVersionResolver.DotNetCoreIndexUrl); - const result = response.result || {}; - let releasesInfo = result['releases-index']; - let releaseInfo = releasesInfo.find(info => { - let sdkParts = info['channel-version'].split('.'); - return sdkParts[0] === versionParts[0]; - }); - if (!releaseInfo) { - throw new Error(`Could not find info for version ${versionParts.join('.')} at ${DotnetVersionResolver.DotNetCoreIndexUrl}`); - } - return releaseInfo['channel-version']; - }); - } -} -exports.DotnetVersionResolver = DotnetVersionResolver; -DotnetVersionResolver.DotNetCoreIndexUrl = 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json'; -class DotnetCoreInstaller { - constructor(version, quality) { - this.version = version; - this.quality = quality; - } - static addToPath() { - if (process.env['DOTNET_INSTALL_DIR']) { - core.addPath(process.env['DOTNET_INSTALL_DIR']); - core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']); - } - else { - if (utils_1.IS_WINDOWS) { - core.addPath(DotnetCoreInstaller.installationDirectoryWindows); - core.exportVariable('DOTNET_ROOT', DotnetCoreInstaller.installationDirectoryWindows); - } - else if (utils_1.IS_LINUX) { - core.addPath(DotnetCoreInstaller.installationDirectoryLinux); - core.exportVariable('DOTNET_ROOT', DotnetCoreInstaller.installationDirectoryLinux); - } - else { - // This is the default set in install-dotnet.sh - core.addPath(DotnetCoreInstaller.installationDirectoryMac); - core.exportVariable('DOTNET_ROOT', DotnetCoreInstaller.installationDirectoryMac); - } - } - } - setQuality(dotnetVersion, scriptArguments) { - const option = utils_1.IS_WINDOWS ? '-Quality' : '--quality'; - if (dotnetVersion.qualityFlag) { - scriptArguments.push(option, this.quality); - } - else { - core.warning(`'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A and A.x formats where the major tag is higher than 5. You specified: ${this.version}. 'dotnet-quality' input is ignored.`); - } - } - installDotnet() { - return __awaiter(this, void 0, void 0, function* () { - const windowsDefaultOptions = [ - '-NoLogo', - '-Sta', - '-NoProfile', - '-NonInteractive', - '-ExecutionPolicy', - 'Unrestricted', - '-Command' - ]; - const scriptName = utils_1.IS_WINDOWS ? 'install-dotnet.ps1' : 'install-dotnet.sh'; - const escapedScript = path_1.default - .join(__dirname, '..', 'externals', scriptName) - .replace(/'/g, "''"); - let scriptArguments; - let scriptPath = ''; - const versionResolver = new DotnetVersionResolver(this.version); - const dotnetVersion = yield versionResolver.createDotNetVersion(); - if (utils_1.IS_WINDOWS) { - scriptArguments = ['&', `'${escapedScript}'`]; - if (dotnetVersion.type) { - scriptArguments.push(dotnetVersion.type, dotnetVersion.value); - } - if (this.quality) { - this.setQuality(dotnetVersion, scriptArguments); - } - if (process.env['https_proxy'] != null) { - scriptArguments.push(`-ProxyAddress ${process.env['https_proxy']}`); - } - // This is not currently an option - if (process.env['no_proxy'] != null) { - scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); - } - if (!process.env['DOTNET_INSTALL_DIR']) { - process.env['DOTNET_INSTALL_DIR'] = - DotnetCoreInstaller.installationDirectoryWindows; - } - scriptPath = - (yield io.which('pwsh', false)) || (yield io.which('powershell', true)); - scriptArguments = windowsDefaultOptions.concat(scriptArguments); - } - else { - fs_1.chmodSync(escapedScript, '777'); - scriptPath = yield io.which(escapedScript, true); - scriptArguments = []; - if (dotnetVersion.type) { - scriptArguments.push(dotnetVersion.type, dotnetVersion.value); - } - if (this.quality) { - this.setQuality(dotnetVersion, scriptArguments); - } - if (!process.env['DOTNET_INSTALL_DIR']) { - process.env['DOTNET_INSTALL_DIR'] = utils_1.IS_LINUX - ? DotnetCoreInstaller.installationDirectoryLinux - : DotnetCoreInstaller.installationDirectoryMac; - } - } - // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used - const getExecOutputOptions = { - ignoreReturnCode: true, - env: process.env - }; - const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, getExecOutputOptions); - if (exitCode) { - throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); - } - return this.outputDotnetVersion(dotnetVersion.value, process.env['DOTNET_INSTALL_DIR']); - }); - } - outputDotnetVersion(version, installationPath) { - return __awaiter(this, void 0, void 0, function* () { - let versionsOnRunner = yield promises_1.readdir(path_1.default.join(installationPath.replace(/'/g, ''), 'sdk')); - let installedVersion = semver_1.default.maxSatisfying(versionsOnRunner, version, { - includePrerelease: true - }); - return installedVersion; - }); - } -} -exports.DotnetCoreInstaller = DotnetCoreInstaller; -DotnetCoreInstaller.installationDirectoryWindows = path_1.default.join(process.env['PROGRAMFILES'] + '', 'dotnet'); -DotnetCoreInstaller.installationDirectoryLinux = '/usr/share/dotnet'; -DotnetCoreInstaller.installationDirectoryMac = path_1.default.join(process.env['HOME'] + '', '.dotnet'); + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +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); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.DotnetCoreInstaller = exports.DotnetVersionResolver = void 0; +// Load tempDirectory before it gets wiped by tool-cache +const core = __importStar(__nccwpck_require__(2186)); +const exec = __importStar(__nccwpck_require__(1514)); +const io = __importStar(__nccwpck_require__(7436)); +const hc = __importStar(__nccwpck_require__(6255)); +const fs_1 = __nccwpck_require__(7147); +const promises_1 = __nccwpck_require__(3292); +const path_1 = __importDefault(__nccwpck_require__(1017)); +const semver_1 = __importDefault(__nccwpck_require__(5911)); +const utils_1 = __nccwpck_require__(918); +class DotnetVersionResolver { + constructor(version) { + this.inputVersion = version.trim(); + this.resolvedArgument = { type: '', value: '', qualityFlag: false }; + } + resolveVersionInput() { + return __awaiter(this, void 0, void 0, function* () { + if (!semver_1.default.validRange(this.inputVersion)) { + throw new Error(`'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B, A.B.x, A, A.x`); + } + if (semver_1.default.valid(this.inputVersion)) { + this.resolvedArgument.type = 'version'; + this.resolvedArgument.value = this.inputVersion; + } + else { + const [major, minor] = this.inputVersion.split('.'); + if (this.isNumericTag(major)) { + this.resolvedArgument.type = 'channel'; + if (this.isNumericTag(minor)) { + this.resolvedArgument.value = `${major}.${minor}`; + } + else { + const httpClient = new hc.HttpClient('actions/setup-dotnet', [], { + allowRetries: true, + maxRetries: 3 + }); + this.resolvedArgument.value = yield this.getLatestVersion(httpClient, [major, minor]); + } + } + this.resolvedArgument.qualityFlag = +major >= 6 ? true : false; + } + }); + } + isNumericTag(versionTag) { + return /^\d+$/.test(versionTag); + } + createDotNetVersion() { + return __awaiter(this, void 0, void 0, function* () { + yield this.resolveVersionInput(); + if (!this.resolvedArgument.type) { + return this.resolvedArgument; + } + if (utils_1.IS_WINDOWS) { + this.resolvedArgument.type = + this.resolvedArgument.type === 'channel' ? '-Channel' : '-Version'; + } + else { + this.resolvedArgument.type = + this.resolvedArgument.type === 'channel' ? '--channel' : '--version'; + } + return this.resolvedArgument; + }); + } + getLatestVersion(httpClient, versionParts) { + return __awaiter(this, void 0, void 0, function* () { + const response = yield httpClient.getJson(DotnetVersionResolver.DotNetCoreIndexUrl); + const result = response.result || {}; + let releasesInfo = result['releases-index']; + let releaseInfo = releasesInfo.find(info => { + let sdkParts = info['channel-version'].split('.'); + return sdkParts[0] === versionParts[0]; + }); + if (!releaseInfo) { + throw new Error(`Could not find info for version ${versionParts.join('.')} at ${DotnetVersionResolver.DotNetCoreIndexUrl}`); + } + return releaseInfo['channel-version']; + }); + } +} +exports.DotnetVersionResolver = DotnetVersionResolver; +DotnetVersionResolver.DotNetCoreIndexUrl = 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json'; +class DotnetCoreInstaller { + constructor(version, quality) { + this.version = version; + this.quality = quality; + } + static addToPath() { + if (process.env['DOTNET_INSTALL_DIR']) { + core.addPath(process.env['DOTNET_INSTALL_DIR']); + core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']); + } + else { + if (utils_1.IS_WINDOWS) { + core.addPath(DotnetCoreInstaller.installationDirectoryWindows); + core.exportVariable('DOTNET_ROOT', DotnetCoreInstaller.installationDirectoryWindows); + } + else if (utils_1.IS_LINUX) { + core.addPath(DotnetCoreInstaller.installationDirectoryLinux); + core.exportVariable('DOTNET_ROOT', DotnetCoreInstaller.installationDirectoryLinux); + } + else { + // This is the default set in install-dotnet.sh + core.addPath(DotnetCoreInstaller.installationDirectoryMac); + core.exportVariable('DOTNET_ROOT', DotnetCoreInstaller.installationDirectoryMac); + } + } + } + setQuality(dotnetVersion, scriptArguments) { + const option = utils_1.IS_WINDOWS ? '-Quality' : '--quality'; + if (dotnetVersion.qualityFlag) { + scriptArguments.push(option, this.quality); + } + else { + core.warning(`'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A and A.x formats where the major tag is higher than 5. You specified: ${this.version}. 'dotnet-quality' input is ignored.`); + } + } + installDotnet() { + return __awaiter(this, void 0, void 0, function* () { + const windowsDefaultOptions = [ + '-NoLogo', + '-Sta', + '-NoProfile', + '-NonInteractive', + '-ExecutionPolicy', + 'Unrestricted', + '-Command' + ]; + const scriptName = utils_1.IS_WINDOWS ? 'install-dotnet.ps1' : 'install-dotnet.sh'; + const escapedScript = path_1.default + .join(__dirname, '..', 'externals', scriptName) + .replace(/'/g, "''"); + let scriptArguments; + let scriptPath = ''; + const versionResolver = new DotnetVersionResolver(this.version); + const dotnetVersion = yield versionResolver.createDotNetVersion(); + if (utils_1.IS_WINDOWS) { + scriptArguments = ['&', `'${escapedScript}'`]; + if (dotnetVersion.type) { + scriptArguments.push(dotnetVersion.type, dotnetVersion.value); + } + if (this.quality) { + this.setQuality(dotnetVersion, scriptArguments); + } + if (process.env['https_proxy'] != null) { + scriptArguments.push(`-ProxyAddress ${process.env['https_proxy']}`); + } + // This is not currently an option + if (process.env['no_proxy'] != null) { + scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); + } + if (!process.env['DOTNET_INSTALL_DIR']) { + process.env['DOTNET_INSTALL_DIR'] = + DotnetCoreInstaller.installationDirectoryWindows; + } + scriptPath = + (yield io.which('pwsh', false)) || (yield io.which('powershell', true)); + scriptArguments = windowsDefaultOptions.concat(scriptArguments); + } + else { + fs_1.chmodSync(escapedScript, '777'); + scriptPath = yield io.which(escapedScript, true); + scriptArguments = []; + if (dotnetVersion.type) { + scriptArguments.push(dotnetVersion.type, dotnetVersion.value); + } + if (this.quality) { + this.setQuality(dotnetVersion, scriptArguments); + } + if (!process.env['DOTNET_INSTALL_DIR']) { + process.env['DOTNET_INSTALL_DIR'] = utils_1.IS_LINUX + ? DotnetCoreInstaller.installationDirectoryLinux + : DotnetCoreInstaller.installationDirectoryMac; + } + } + // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used + const getExecOutputOptions = { + ignoreReturnCode: true, + env: process.env + }; + const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, getExecOutputOptions); + if (exitCode) { + throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); + } + return this.outputDotnetVersion(dotnetVersion.value, process.env['DOTNET_INSTALL_DIR']); + }); + } + outputDotnetVersion(version, installationPath) { + return __awaiter(this, void 0, void 0, function* () { + let versionsOnRunner = yield promises_1.readdir(path_1.default.join(installationPath.replace(/'/g, ''), 'sdk')); + let installedVersion = semver_1.default.maxSatisfying(versionsOnRunner, version, { + includePrerelease: true + }); + return installedVersion; + }); + } +} +exports.DotnetCoreInstaller = DotnetCoreInstaller; +DotnetCoreInstaller.installationDirectoryWindows = path_1.default.join(process.env['PROGRAMFILES'] + '', 'dotnet'); +DotnetCoreInstaller.installationDirectoryLinux = '/usr/share/dotnet'; +DotnetCoreInstaller.installationDirectoryMac = path_1.default.join(process.env['HOME'] + '', '.dotnet'); /***/ }), @@ -391,134 +391,134 @@ DotnetCoreInstaller.installationDirectoryMac = path_1.default.join(process.env[' /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -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); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.run = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const installer_1 = __nccwpck_require__(1480); -const fs = __importStar(__nccwpck_require__(7147)); -const path_1 = __importDefault(__nccwpck_require__(1017)); -const semver_1 = __importDefault(__nccwpck_require__(5911)); -const auth = __importStar(__nccwpck_require__(8527)); -const qualityOptions = [ - 'daily', - 'signed', - 'validated', - 'preview', - 'ga' -]; -function run() { - return __awaiter(this, void 0, void 0, function* () { - try { - // - // dotnet-version is optional, but needs to be provided for most use cases. - // If supplied, install / use from the tool cache. - // global-version-file may be specified to point to a specific global.json - // and will be used to install an additional version. - // If not supplied, look for version in ./global.json. - // If a valid version still can't be identified, nothing will be installed. - // Proxy, auth, (etc) are still set up, even if no version is identified - // - const versions = core.getMultilineInput('dotnet-version'); - const installedDotnetVersions = []; - const globalJsonFileInput = core.getInput('global-json-file'); - if (globalJsonFileInput) { - const globalJsonPath = path_1.default.join(process.cwd(), globalJsonFileInput); - if (!fs.existsSync(globalJsonPath)) { - throw new Error(`The specified global.json file '${globalJsonFileInput}' does not exist`); - } - versions.push(getVersionFromGlobalJson(globalJsonPath)); - } - if (!versions.length) { - // Try to fall back to global.json - core.debug('No version found, trying to find version from global.json'); - const globalJsonPath = path_1.default.join(process.cwd(), 'global.json'); - if (fs.existsSync(globalJsonPath)) { - versions.push(getVersionFromGlobalJson(globalJsonPath)); - } - } - if (versions.length) { - const quality = core.getInput('dotnet-quality'); - if (quality && !qualityOptions.includes(quality)) { - throw new Error(`${quality} is not a supported value for 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`); - } - let dotnetInstaller; - const uniqueVersions = new Set(versions); - for (const version of uniqueVersions) { - dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality); - const installedVersion = yield dotnetInstaller.installDotnet(); - installedDotnetVersions.push(installedVersion); - } - installer_1.DotnetCoreInstaller.addToPath(); - } - const sourceUrl = core.getInput('source-url'); - const configFile = core.getInput('config-file'); - if (sourceUrl) { - auth.configAuthentication(sourceUrl, configFile); - } - const comparisonRange = globalJsonFileInput - ? versions[versions.length - 1] - : '*'; - const versionToOutput = semver_1.default.maxSatisfying(installedDotnetVersions, comparisonRange, { - includePrerelease: true - }); - core.setOutput('dotnet-version', versionToOutput); - const matchersPath = path_1.default.join(__dirname, '..', '.github'); - core.info(`##[add-matcher]${path_1.default.join(matchersPath, 'csc.json')}`); - } - catch (error) { - core.setFailed(error.message); - } - }); -} -exports.run = run; -function getVersionFromGlobalJson(globalJsonPath) { - let version = ''; - const globalJson = JSON.parse( - // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 - fs.readFileSync(globalJsonPath, { encoding: 'utf8' }).trim()); - if (globalJson.sdk && globalJson.sdk.version) { - version = globalJson.sdk.version; - const rollForward = globalJson.sdk.rollForward; - if (rollForward && rollForward === 'latestFeature') { - const [major, minor] = version.split('.'); - version = `${major}.${minor}`; - } - } - return version; -} -run(); + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +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); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.run = void 0; +const core = __importStar(__nccwpck_require__(2186)); +const installer_1 = __nccwpck_require__(1480); +const fs = __importStar(__nccwpck_require__(7147)); +const path_1 = __importDefault(__nccwpck_require__(1017)); +const semver_1 = __importDefault(__nccwpck_require__(5911)); +const auth = __importStar(__nccwpck_require__(8527)); +const qualityOptions = [ + 'daily', + 'signed', + 'validated', + 'preview', + 'ga' +]; +function run() { + return __awaiter(this, void 0, void 0, function* () { + try { + // + // dotnet-version is optional, but needs to be provided for most use cases. + // If supplied, install / use from the tool cache. + // global-version-file may be specified to point to a specific global.json + // and will be used to install an additional version. + // If not supplied, look for version in ./global.json. + // If a valid version still can't be identified, nothing will be installed. + // Proxy, auth, (etc) are still set up, even if no version is identified + // + const versions = core.getMultilineInput('dotnet-version'); + const installedDotnetVersions = []; + const globalJsonFileInput = core.getInput('global-json-file'); + if (globalJsonFileInput) { + const globalJsonPath = path_1.default.join(process.cwd(), globalJsonFileInput); + if (!fs.existsSync(globalJsonPath)) { + throw new Error(`The specified global.json file '${globalJsonFileInput}' does not exist`); + } + versions.push(getVersionFromGlobalJson(globalJsonPath)); + } + if (!versions.length) { + // Try to fall back to global.json + core.debug('No version found, trying to find version from global.json'); + const globalJsonPath = path_1.default.join(process.cwd(), 'global.json'); + if (fs.existsSync(globalJsonPath)) { + versions.push(getVersionFromGlobalJson(globalJsonPath)); + } + } + if (versions.length) { + const quality = core.getInput('dotnet-quality'); + if (quality && !qualityOptions.includes(quality)) { + throw new Error(`${quality} is not a supported value for 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`); + } + let dotnetInstaller; + const uniqueVersions = new Set(versions); + for (const version of uniqueVersions) { + dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality); + const installedVersion = yield dotnetInstaller.installDotnet(); + installedDotnetVersions.push(installedVersion); + } + installer_1.DotnetCoreInstaller.addToPath(); + } + const sourceUrl = core.getInput('source-url'); + const configFile = core.getInput('config-file'); + if (sourceUrl) { + auth.configAuthentication(sourceUrl, configFile); + } + const comparisonRange = globalJsonFileInput + ? versions[versions.length - 1] + : '*'; + const versionToOutput = semver_1.default.maxSatisfying(installedDotnetVersions, comparisonRange, { + includePrerelease: true + }); + core.setOutput('dotnet-version', versionToOutput); + const matchersPath = path_1.default.join(__dirname, '..', '.github'); + core.info(`##[add-matcher]${path_1.default.join(matchersPath, 'csc.json')}`); + } + catch (error) { + core.setFailed(error.message); + } + }); +} +exports.run = run; +function getVersionFromGlobalJson(globalJsonPath) { + let version = ''; + const globalJson = JSON.parse( + // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 + fs.readFileSync(globalJsonPath, { encoding: 'utf8' }).trim()); + if (globalJson.sdk && globalJson.sdk.version) { + version = globalJson.sdk.version; + const rollForward = globalJson.sdk.rollForward; + if (rollForward && rollForward === 'latestFeature') { + const [major, minor] = version.split('.'); + version = `${major}.${minor}`; + } + } + return version; +} +run(); /***/ }), @@ -527,11 +527,11 @@ run(); /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.IS_LINUX = exports.IS_WINDOWS = void 0; -exports.IS_WINDOWS = process.platform === 'win32'; -exports.IS_LINUX = process.platform === 'linux'; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.IS_LINUX = exports.IS_WINDOWS = void 0; +exports.IS_WINDOWS = process.platform === 'win32'; +exports.IS_LINUX = process.platform === 'linux'; /***/ }), @@ -675,7 +675,6 @@ const file_command_1 = __nccwpck_require__(717); const utils_1 = __nccwpck_require__(5278); const os = __importStar(__nccwpck_require__(2037)); const path = __importStar(__nccwpck_require__(1017)); -const uuid_1 = __nccwpck_require__(5840); const oidc_utils_1 = __nccwpck_require__(8041); /** * The code to exit an action @@ -705,20 +704,9 @@ function exportVariable(name, val) { process.env[name] = convertedVal; const filePath = process.env['GITHUB_ENV'] || ''; if (filePath) { - const delimiter = `ghadelimiter_${uuid_1.v4()}`; - // These should realistically never happen, but just in case someone finds a way to exploit uuid generation let's not allow keys or values that contain the delimiter. - if (name.includes(delimiter)) { - throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`); - } - if (convertedVal.includes(delimiter)) { - throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`); - } - const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`; - file_command_1.issueCommand('ENV', commandValue); - } - else { - command_1.issueCommand('set-env', { name }, convertedVal); + return file_command_1.issueFileCommand('ENV', file_command_1.prepareKeyValueMessage(name, val)); } + command_1.issueCommand('set-env', { name }, convertedVal); } exports.exportVariable = exportVariable; /** @@ -736,7 +724,7 @@ exports.setSecret = setSecret; function addPath(inputPath) { const filePath = process.env['GITHUB_PATH'] || ''; if (filePath) { - file_command_1.issueCommand('PATH', inputPath); + file_command_1.issueFileCommand('PATH', inputPath); } else { command_1.issueCommand('add-path', {}, inputPath); @@ -776,7 +764,10 @@ function getMultilineInput(name, options) { const inputs = getInput(name, options) .split('\n') .filter(x => x !== ''); - return inputs; + if (options && options.trimWhitespace === false) { + return inputs; + } + return inputs.map(input => input.trim()); } exports.getMultilineInput = getMultilineInput; /** @@ -809,8 +800,12 @@ exports.getBooleanInput = getBooleanInput; */ // eslint-disable-next-line @typescript-eslint/no-explicit-any function setOutput(name, value) { + const filePath = process.env['GITHUB_OUTPUT'] || ''; + if (filePath) { + return file_command_1.issueFileCommand('OUTPUT', file_command_1.prepareKeyValueMessage(name, value)); + } process.stdout.write(os.EOL); - command_1.issueCommand('set-output', { name }, value); + command_1.issueCommand('set-output', { name }, utils_1.toCommandValue(value)); } exports.setOutput = setOutput; /** @@ -939,7 +934,11 @@ exports.group = group; */ // eslint-disable-next-line @typescript-eslint/no-explicit-any function saveState(name, value) { - command_1.issueCommand('save-state', { name }, value); + const filePath = process.env['GITHUB_STATE'] || ''; + if (filePath) { + return file_command_1.issueFileCommand('STATE', file_command_1.prepareKeyValueMessage(name, value)); + } + command_1.issueCommand('save-state', { name }, utils_1.toCommandValue(value)); } exports.saveState = saveState; /** @@ -1005,13 +1004,14 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.issueCommand = void 0; +exports.prepareKeyValueMessage = exports.issueFileCommand = void 0; // We use any as a valid input type /* eslint-disable @typescript-eslint/no-explicit-any */ const fs = __importStar(__nccwpck_require__(7147)); const os = __importStar(__nccwpck_require__(2037)); +const uuid_1 = __nccwpck_require__(5840); const utils_1 = __nccwpck_require__(5278); -function issueCommand(command, message) { +function issueFileCommand(command, message) { const filePath = process.env[`GITHUB_${command}`]; if (!filePath) { throw new Error(`Unable to find environment variable for file command ${command}`); @@ -1023,7 +1023,22 @@ function issueCommand(command, message) { encoding: 'utf8' }); } -exports.issueCommand = issueCommand; +exports.issueFileCommand = issueFileCommand; +function prepareKeyValueMessage(key, value) { + const delimiter = `ghadelimiter_${uuid_1.v4()}`; + const convertedValue = utils_1.toCommandValue(value); + // These should realistically never happen, but just in case someone finds a + // way to exploit uuid generation let's not allow keys or values that contain + // the delimiter. + if (key.includes(delimiter)) { + throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`); + } + if (convertedValue.includes(delimiter)) { + throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`); + } + return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`; +} +exports.prepareKeyValueMessage = prepareKeyValueMessage; //# sourceMappingURL=file-command.js.map /***/ }), diff --git a/package-lock.json b/package-lock.json index 5459e0f..ecb8ff4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.0.1", "license": "MIT", "dependencies": { - "@actions/core": "^1.9.1", + "@actions/core": "^1.10.0", "@actions/exec": "^1.0.4", "@actions/github": "^1.1.0", "@actions/http-client": "^2.0.1", @@ -33,9 +33,9 @@ } }, "node_modules/@actions/core": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.1.tgz", - "integrity": "sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==", + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz", + "integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==", "dependencies": { "@actions/http-client": "^2.0.1", "uuid": "^8.3.2" @@ -4725,9 +4725,9 @@ }, "dependencies": { "@actions/core": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.1.tgz", - "integrity": "sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==", + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz", + "integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==", "requires": { "@actions/http-client": "^2.0.1", "uuid": "^8.3.2" diff --git a/package.json b/package.json index b58554c..2fdd345 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "author": "GitHub", "license": "MIT", "dependencies": { - "@actions/core": "^1.9.1", + "@actions/core": "^1.10.0", "@actions/exec": "^1.0.4", "@actions/github": "^1.1.0", "@actions/http-client": "^2.0.1", From 4d4a70f4a5b2a5a5329f13be4ac933f2c9206ac0 Mon Sep 17 00:00:00 2001 From: Ivan <98037481+IvanZosimov@users.noreply.github.com> Date: Mon, 10 Oct 2022 14:27:29 +0200 Subject: [PATCH 3/3] Add logic for processing DOTNET_INSTALL_DIR environment variable (#332) --- .gitattributes | 2 +- .prettierrc.json | 3 +- README.md | 9 +- __tests__/authutil.test.ts | 6 +- dist/index.js | 1025 ++++++++++++++++++------------------ package-lock.json | 37 +- package.json | 6 +- src/installer.ts | 89 ++-- tsconfig.json | 1 + 9 files changed, 598 insertions(+), 580 deletions(-) diff --git a/.gitattributes b/.gitattributes index 541fd55..f6ac05f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -.licenses/** -diff linguist-generated=true \ No newline at end of file +.licenses/** -diff linguist-generated=true diff --git a/.prettierrc.json b/.prettierrc.json index f6736bc..ca09262 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -7,5 +7,6 @@ "trailingComma": "none", "bracketSpacing": false, "arrowParens": "avoid", - "parser": "typescript" + "parser": "typescript", + "endOfLine": "auto" } \ No newline at end of file diff --git a/README.md b/README.md index 382465b..cec68e9 100644 --- a/README.md +++ b/README.md @@ -195,11 +195,18 @@ Some environment variables may be necessary for your particular case or to impro | **Env.variable** | **Description** | **Default value** | | ----------- | ----------- | ----------- | -| DOTNET_INSTALL_DIR |Specifies a directory where .NET SDKs should be installed by the action|*isn't set*| +| DOTNET_INSTALL_DIR |Specifies a directory where .NET SDKs should be installed by the action.|*default value for each OS* | | DOTNET_NOLOGO |Removes logo and telemetry message from first run of dotnet cli|*false*| | DOTNET_CLI_TELEMETRY_OPTOUT |Opt-out of telemetry being sent to Microsoft|*false*| | DOTNET_MULTILEVEL_LOOKUP |Configures whether the global install location is used as a fall-back|*true*| +The default value of the `DOTNET_INSTALL_DIR` environment variable depends on the operation system which is used on a runner: +| **Operation system** | **Default value** | +| ----------- | ----------- | +| **Windows** | `C:\Program Files\dotnet` | +| **Ubuntu** | `/usr/share/dotnet` | +| **macOS** | `/Users/runner/.dotnet` | + **Example usage**: ```yml build: diff --git a/__tests__/authutil.test.ts b/__tests__/authutil.test.ts index ce02533..595682e 100644 --- a/__tests__/authutil.test.ts +++ b/__tests__/authutil.test.ts @@ -5,11 +5,7 @@ import path from 'path'; const fakeSourcesDirForTesting = path.join( __dirname, 'runner', - path.join( - Math.random() - .toString(36) - .substring(7) - ), + path.join(Math.random().toString(36).substring(7)), 's' ); diff --git a/dist/index.js b/dist/index.js index fb2365b..82fb725 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5,142 +5,146 @@ /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.configAuthentication = void 0; -const fs = __importStar(__nccwpck_require__(7147)); -const path = __importStar(__nccwpck_require__(1017)); -const core = __importStar(__nccwpck_require__(2186)); -const github = __importStar(__nccwpck_require__(5438)); -const xmlbuilder = __importStar(__nccwpck_require__(2958)); -const xmlParser = __importStar(__nccwpck_require__(7448)); -function configAuthentication(feedUrl, existingFileLocation = '', processRoot = process.cwd()) { - const existingNuGetConfig = path.resolve(processRoot, existingFileLocation === '' - ? getExistingNugetConfig(processRoot) - : existingFileLocation); - const tempNuGetConfig = path.resolve(processRoot, '../', 'nuget.config'); - writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig); -} -exports.configAuthentication = configAuthentication; -function isValidKey(key) { - return /^[\w\-\.]+$/i.test(key); -} -function getExistingNugetConfig(processRoot) { - const defaultConfigName = 'nuget.config'; - const configFileNames = fs - .readdirSync(processRoot) - .filter(filename => filename.toLowerCase() === defaultConfigName); - if (configFileNames.length) { - return configFileNames[0]; - } - return defaultConfigName; -} -function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) { - core.info(`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`); - let xml; - let sourceKeys = []; - let owner = core.getInput('owner'); - let sourceUrl = feedUrl; - if (!owner) { - owner = github.context.repo.owner; - } - if (!process.env.NUGET_AUTH_TOKEN) { - throw new Error('The NUGET_AUTH_TOKEN environment variable was not provided. In this step, add the following: \r\nenv:\r\n NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}'); - } - if (fs.existsSync(existingFileLocation)) { - // get key from existing NuGet.config so NuGet/dotnet can match credentials - const curContents = fs.readFileSync(existingFileLocation, 'utf8'); - const json = xmlParser.parse(curContents, { ignoreAttributes: false }); - if (typeof json.configuration === 'undefined') { - throw new Error(`The provided NuGet.config seems invalid.`); - } - if (typeof json.configuration.packageSources != 'undefined') { - if (typeof json.configuration.packageSources.add != 'undefined') { - // file has at least one - if (typeof json.configuration.packageSources.add[0] === 'undefined') { - // file has only one - if (json.configuration.packageSources.add['@_value'] - .toLowerCase() - .includes(feedUrl.toLowerCase())) { - const key = json.configuration.packageSources.add['@_key']; - sourceKeys.push(key); - core.debug(`Found a URL with key ${key}`); - } - } - else { - // file has 2+ - for (let i = 0; i < json.configuration.packageSources.add.length; i++) { - const source = json.configuration.packageSources.add[i]; - const value = source['@_value']; - core.debug(`source '${value}'`); - if (value.toLowerCase().includes(feedUrl.toLowerCase())) { - const key = source['@_key']; - sourceKeys.push(key); - core.debug(`Found a URL with key ${key}`); - } - } - } - } - } - } - xml = xmlbuilder - .create('configuration') - .ele('config') - .ele('add', { key: 'defaultPushSource', value: sourceUrl }) - .up() - .up(); - if (!sourceKeys.length) { - let keystring = 'Source'; - xml = xml - .ele('packageSources') - .ele('add', { key: keystring, value: sourceUrl }) - .up() - .up(); - sourceKeys.push(keystring); - } - xml = xml.ele('packageSourceCredentials'); - sourceKeys.forEach(key => { - if (!isValidKey(key)) { - throw new Error("Source name can contain letters, numbers, and '-', '_', '.' symbols only. Please, fix source name in NuGet.config and try again."); - } - xml = xml - .ele(key) - .ele('add', { key: 'Username', value: owner }) - .up() - .ele('add', { - key: 'ClearTextPassword', - value: process.env.NUGET_AUTH_TOKEN - }) - .up() - .up(); - }); - // If NuGet fixes itself such that on Linux it can look for environment variables in the config file (it doesn't seem to work today), - // use this for the value above - // process.platform == 'win32' - // ? '%NUGET_AUTH_TOKEN%' - // : '$NUGET_AUTH_TOKEN' - const output = xml.end({ pretty: true }); - fs.writeFileSync(tempFileLocation, output); -} + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.configAuthentication = void 0; +const fs = __importStar(__nccwpck_require__(7147)); +const path = __importStar(__nccwpck_require__(1017)); +const core = __importStar(__nccwpck_require__(2186)); +const github = __importStar(__nccwpck_require__(5438)); +const xmlbuilder = __importStar(__nccwpck_require__(2958)); +const xmlParser = __importStar(__nccwpck_require__(7448)); +function configAuthentication(feedUrl, existingFileLocation = '', processRoot = process.cwd()) { + const existingNuGetConfig = path.resolve(processRoot, existingFileLocation === '' + ? getExistingNugetConfig(processRoot) + : existingFileLocation); + const tempNuGetConfig = path.resolve(processRoot, '../', 'nuget.config'); + writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig); +} +exports.configAuthentication = configAuthentication; +function isValidKey(key) { + return /^[\w\-\.]+$/i.test(key); +} +function getExistingNugetConfig(processRoot) { + const defaultConfigName = 'nuget.config'; + const configFileNames = fs + .readdirSync(processRoot) + .filter(filename => filename.toLowerCase() === defaultConfigName); + if (configFileNames.length) { + return configFileNames[0]; + } + return defaultConfigName; +} +function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) { + core.info(`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`); + let xml; + let sourceKeys = []; + let owner = core.getInput('owner'); + let sourceUrl = feedUrl; + if (!owner) { + owner = github.context.repo.owner; + } + if (!process.env.NUGET_AUTH_TOKEN) { + throw new Error('The NUGET_AUTH_TOKEN environment variable was not provided. In this step, add the following: \r\nenv:\r\n NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}'); + } + if (fs.existsSync(existingFileLocation)) { + // get key from existing NuGet.config so NuGet/dotnet can match credentials + const curContents = fs.readFileSync(existingFileLocation, 'utf8'); + const json = xmlParser.parse(curContents, { ignoreAttributes: false }); + if (typeof json.configuration === 'undefined') { + throw new Error(`The provided NuGet.config seems invalid.`); + } + if (typeof json.configuration.packageSources != 'undefined') { + if (typeof json.configuration.packageSources.add != 'undefined') { + // file has at least one + if (typeof json.configuration.packageSources.add[0] === 'undefined') { + // file has only one + if (json.configuration.packageSources.add['@_value'] + .toLowerCase() + .includes(feedUrl.toLowerCase())) { + const key = json.configuration.packageSources.add['@_key']; + sourceKeys.push(key); + core.debug(`Found a URL with key ${key}`); + } + } + else { + // file has 2+ + for (let i = 0; i < json.configuration.packageSources.add.length; i++) { + const source = json.configuration.packageSources.add[i]; + const value = source['@_value']; + core.debug(`source '${value}'`); + if (value.toLowerCase().includes(feedUrl.toLowerCase())) { + const key = source['@_key']; + sourceKeys.push(key); + core.debug(`Found a URL with key ${key}`); + } + } + } + } + } + } + xml = xmlbuilder + .create('configuration') + .ele('config') + .ele('add', { key: 'defaultPushSource', value: sourceUrl }) + .up() + .up(); + if (!sourceKeys.length) { + let keystring = 'Source'; + xml = xml + .ele('packageSources') + .ele('add', { key: keystring, value: sourceUrl }) + .up() + .up(); + sourceKeys.push(keystring); + } + xml = xml.ele('packageSourceCredentials'); + sourceKeys.forEach(key => { + if (!isValidKey(key)) { + throw new Error("Source name can contain letters, numbers, and '-', '_', '.' symbols only. Please, fix source name in NuGet.config and try again."); + } + xml = xml + .ele(key) + .ele('add', { key: 'Username', value: owner }) + .up() + .ele('add', { + key: 'ClearTextPassword', + value: process.env.NUGET_AUTH_TOKEN + }) + .up() + .up(); + }); + // If NuGet fixes itself such that on Linux it can look for environment variables in the config file (it doesn't seem to work today), + // use this for the value above + // process.platform == 'win32' + // ? '%NUGET_AUTH_TOKEN%' + // : '$NUGET_AUTH_TOKEN' + const output = xml.end({ pretty: true }); + fs.writeFileSync(tempFileLocation, output); +} /***/ }), @@ -149,240 +153,251 @@ function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) { /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -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); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.DotnetCoreInstaller = exports.DotnetVersionResolver = void 0; -// Load tempDirectory before it gets wiped by tool-cache -const core = __importStar(__nccwpck_require__(2186)); -const exec = __importStar(__nccwpck_require__(1514)); -const io = __importStar(__nccwpck_require__(7436)); -const hc = __importStar(__nccwpck_require__(6255)); -const fs_1 = __nccwpck_require__(7147); -const promises_1 = __nccwpck_require__(3292); -const path_1 = __importDefault(__nccwpck_require__(1017)); -const semver_1 = __importDefault(__nccwpck_require__(5911)); -const utils_1 = __nccwpck_require__(918); -class DotnetVersionResolver { - constructor(version) { - this.inputVersion = version.trim(); - this.resolvedArgument = { type: '', value: '', qualityFlag: false }; - } - resolveVersionInput() { - return __awaiter(this, void 0, void 0, function* () { - if (!semver_1.default.validRange(this.inputVersion)) { - throw new Error(`'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B, A.B.x, A, A.x`); - } - if (semver_1.default.valid(this.inputVersion)) { - this.resolvedArgument.type = 'version'; - this.resolvedArgument.value = this.inputVersion; - } - else { - const [major, minor] = this.inputVersion.split('.'); - if (this.isNumericTag(major)) { - this.resolvedArgument.type = 'channel'; - if (this.isNumericTag(minor)) { - this.resolvedArgument.value = `${major}.${minor}`; - } - else { - const httpClient = new hc.HttpClient('actions/setup-dotnet', [], { - allowRetries: true, - maxRetries: 3 - }); - this.resolvedArgument.value = yield this.getLatestVersion(httpClient, [major, minor]); - } - } - this.resolvedArgument.qualityFlag = +major >= 6 ? true : false; - } - }); - } - isNumericTag(versionTag) { - return /^\d+$/.test(versionTag); - } - createDotNetVersion() { - return __awaiter(this, void 0, void 0, function* () { - yield this.resolveVersionInput(); - if (!this.resolvedArgument.type) { - return this.resolvedArgument; - } - if (utils_1.IS_WINDOWS) { - this.resolvedArgument.type = - this.resolvedArgument.type === 'channel' ? '-Channel' : '-Version'; - } - else { - this.resolvedArgument.type = - this.resolvedArgument.type === 'channel' ? '--channel' : '--version'; - } - return this.resolvedArgument; - }); - } - getLatestVersion(httpClient, versionParts) { - return __awaiter(this, void 0, void 0, function* () { - const response = yield httpClient.getJson(DotnetVersionResolver.DotNetCoreIndexUrl); - const result = response.result || {}; - let releasesInfo = result['releases-index']; - let releaseInfo = releasesInfo.find(info => { - let sdkParts = info['channel-version'].split('.'); - return sdkParts[0] === versionParts[0]; - }); - if (!releaseInfo) { - throw new Error(`Could not find info for version ${versionParts.join('.')} at ${DotnetVersionResolver.DotNetCoreIndexUrl}`); - } - return releaseInfo['channel-version']; - }); - } -} -exports.DotnetVersionResolver = DotnetVersionResolver; -DotnetVersionResolver.DotNetCoreIndexUrl = 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json'; -class DotnetCoreInstaller { - constructor(version, quality) { - this.version = version; - this.quality = quality; - } - static addToPath() { - if (process.env['DOTNET_INSTALL_DIR']) { - core.addPath(process.env['DOTNET_INSTALL_DIR']); - core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']); - } - else { - if (utils_1.IS_WINDOWS) { - core.addPath(DotnetCoreInstaller.installationDirectoryWindows); - core.exportVariable('DOTNET_ROOT', DotnetCoreInstaller.installationDirectoryWindows); - } - else if (utils_1.IS_LINUX) { - core.addPath(DotnetCoreInstaller.installationDirectoryLinux); - core.exportVariable('DOTNET_ROOT', DotnetCoreInstaller.installationDirectoryLinux); - } - else { - // This is the default set in install-dotnet.sh - core.addPath(DotnetCoreInstaller.installationDirectoryMac); - core.exportVariable('DOTNET_ROOT', DotnetCoreInstaller.installationDirectoryMac); - } - } - } - setQuality(dotnetVersion, scriptArguments) { - const option = utils_1.IS_WINDOWS ? '-Quality' : '--quality'; - if (dotnetVersion.qualityFlag) { - scriptArguments.push(option, this.quality); - } - else { - core.warning(`'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A and A.x formats where the major tag is higher than 5. You specified: ${this.version}. 'dotnet-quality' input is ignored.`); - } - } - installDotnet() { - return __awaiter(this, void 0, void 0, function* () { - const windowsDefaultOptions = [ - '-NoLogo', - '-Sta', - '-NoProfile', - '-NonInteractive', - '-ExecutionPolicy', - 'Unrestricted', - '-Command' - ]; - const scriptName = utils_1.IS_WINDOWS ? 'install-dotnet.ps1' : 'install-dotnet.sh'; - const escapedScript = path_1.default - .join(__dirname, '..', 'externals', scriptName) - .replace(/'/g, "''"); - let scriptArguments; - let scriptPath = ''; - const versionResolver = new DotnetVersionResolver(this.version); - const dotnetVersion = yield versionResolver.createDotNetVersion(); - if (utils_1.IS_WINDOWS) { - scriptArguments = ['&', `'${escapedScript}'`]; - if (dotnetVersion.type) { - scriptArguments.push(dotnetVersion.type, dotnetVersion.value); - } - if (this.quality) { - this.setQuality(dotnetVersion, scriptArguments); - } - if (process.env['https_proxy'] != null) { - scriptArguments.push(`-ProxyAddress ${process.env['https_proxy']}`); - } - // This is not currently an option - if (process.env['no_proxy'] != null) { - scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); - } - if (!process.env['DOTNET_INSTALL_DIR']) { - process.env['DOTNET_INSTALL_DIR'] = - DotnetCoreInstaller.installationDirectoryWindows; - } - scriptPath = - (yield io.which('pwsh', false)) || (yield io.which('powershell', true)); - scriptArguments = windowsDefaultOptions.concat(scriptArguments); - } - else { - fs_1.chmodSync(escapedScript, '777'); - scriptPath = yield io.which(escapedScript, true); - scriptArguments = []; - if (dotnetVersion.type) { - scriptArguments.push(dotnetVersion.type, dotnetVersion.value); - } - if (this.quality) { - this.setQuality(dotnetVersion, scriptArguments); - } - if (!process.env['DOTNET_INSTALL_DIR']) { - process.env['DOTNET_INSTALL_DIR'] = utils_1.IS_LINUX - ? DotnetCoreInstaller.installationDirectoryLinux - : DotnetCoreInstaller.installationDirectoryMac; - } - } - // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used - const getExecOutputOptions = { - ignoreReturnCode: true, - env: process.env - }; - const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, getExecOutputOptions); - if (exitCode) { - throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); - } - return this.outputDotnetVersion(dotnetVersion.value, process.env['DOTNET_INSTALL_DIR']); - }); - } - outputDotnetVersion(version, installationPath) { - return __awaiter(this, void 0, void 0, function* () { - let versionsOnRunner = yield promises_1.readdir(path_1.default.join(installationPath.replace(/'/g, ''), 'sdk')); - let installedVersion = semver_1.default.maxSatisfying(versionsOnRunner, version, { - includePrerelease: true - }); - return installedVersion; - }); - } -} -exports.DotnetCoreInstaller = DotnetCoreInstaller; -DotnetCoreInstaller.installationDirectoryWindows = path_1.default.join(process.env['PROGRAMFILES'] + '', 'dotnet'); -DotnetCoreInstaller.installationDirectoryLinux = '/usr/share/dotnet'; -DotnetCoreInstaller.installationDirectoryMac = path_1.default.join(process.env['HOME'] + '', '.dotnet'); + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +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); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +var _a; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.DotnetCoreInstaller = exports.DotnetVersionResolver = void 0; +// Load tempDirectory before it gets wiped by tool-cache +const core = __importStar(__nccwpck_require__(2186)); +const exec = __importStar(__nccwpck_require__(1514)); +const io = __importStar(__nccwpck_require__(7436)); +const hc = __importStar(__nccwpck_require__(6255)); +const fs_1 = __nccwpck_require__(7147); +const promises_1 = __nccwpck_require__(3292); +const path_1 = __importDefault(__nccwpck_require__(1017)); +const os_1 = __importDefault(__nccwpck_require__(2037)); +const semver_1 = __importDefault(__nccwpck_require__(5911)); +const utils_1 = __nccwpck_require__(918); +class DotnetVersionResolver { + constructor(version) { + this.inputVersion = version.trim(); + this.resolvedArgument = { type: '', value: '', qualityFlag: false }; + } + resolveVersionInput() { + return __awaiter(this, void 0, void 0, function* () { + if (!semver_1.default.validRange(this.inputVersion)) { + throw new Error(`'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B, A.B.x, A, A.x`); + } + if (semver_1.default.valid(this.inputVersion)) { + this.resolvedArgument.type = 'version'; + this.resolvedArgument.value = this.inputVersion; + } + else { + const [major, minor] = this.inputVersion.split('.'); + if (this.isNumericTag(major)) { + this.resolvedArgument.type = 'channel'; + if (this.isNumericTag(minor)) { + this.resolvedArgument.value = `${major}.${minor}`; + } + else { + const httpClient = new hc.HttpClient('actions/setup-dotnet', [], { + allowRetries: true, + maxRetries: 3 + }); + this.resolvedArgument.value = yield this.getLatestVersion(httpClient, [major, minor]); + } + } + this.resolvedArgument.qualityFlag = +major >= 6 ? true : false; + } + }); + } + isNumericTag(versionTag) { + return /^\d+$/.test(versionTag); + } + createDotNetVersion() { + return __awaiter(this, void 0, void 0, function* () { + yield this.resolveVersionInput(); + if (!this.resolvedArgument.type) { + return this.resolvedArgument; + } + if (utils_1.IS_WINDOWS) { + this.resolvedArgument.type = + this.resolvedArgument.type === 'channel' ? '-Channel' : '-Version'; + } + else { + this.resolvedArgument.type = + this.resolvedArgument.type === 'channel' ? '--channel' : '--version'; + } + return this.resolvedArgument; + }); + } + getLatestVersion(httpClient, versionParts) { + return __awaiter(this, void 0, void 0, function* () { + const response = yield httpClient.getJson(DotnetVersionResolver.DotNetCoreIndexUrl); + const result = response.result || {}; + let releasesInfo = result['releases-index']; + let releaseInfo = releasesInfo.find(info => { + let sdkParts = info['channel-version'].split('.'); + return sdkParts[0] === versionParts[0]; + }); + if (!releaseInfo) { + throw new Error(`Could not find info for version ${versionParts.join('.')} at ${DotnetVersionResolver.DotNetCoreIndexUrl}`); + } + return releaseInfo['channel-version']; + }); + } +} +exports.DotnetVersionResolver = DotnetVersionResolver; +DotnetVersionResolver.DotNetCoreIndexUrl = 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json'; +class DotnetCoreInstaller { + constructor(version, quality) { + this.version = version; + this.quality = quality; + } + static convertInstallPathToAbsolute(installDir) { + let transformedPath; + if (path_1.default.isAbsolute(installDir)) { + transformedPath = installDir; + } + else { + transformedPath = installDir.startsWith('~') + ? path_1.default.join(os_1.default.homedir(), installDir.slice(1)) + : (transformedPath = path_1.default.join(process.cwd(), installDir)); + } + return path_1.default.normalize(transformedPath); + } + static addToPath() { + core.addPath(process.env['DOTNET_INSTALL_DIR']); + core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']); + } + setQuality(dotnetVersion, scriptArguments) { + const option = utils_1.IS_WINDOWS ? '-Quality' : '--quality'; + if (dotnetVersion.qualityFlag) { + scriptArguments.push(option, this.quality); + } + else { + core.warning(`'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A and A.x formats where the major tag is higher than 5. You specified: ${this.version}. 'dotnet-quality' input is ignored.`); + } + } + installDotnet() { + return __awaiter(this, void 0, void 0, function* () { + const windowsDefaultOptions = [ + '-NoLogo', + '-Sta', + '-NoProfile', + '-NonInteractive', + '-ExecutionPolicy', + 'Unrestricted', + '-Command' + ]; + const scriptName = utils_1.IS_WINDOWS ? 'install-dotnet.ps1' : 'install-dotnet.sh'; + const escapedScript = path_1.default + .join(__dirname, '..', 'externals', scriptName) + .replace(/'/g, "''"); + let scriptArguments; + let scriptPath = ''; + const versionResolver = new DotnetVersionResolver(this.version); + const dotnetVersion = yield versionResolver.createDotNetVersion(); + if (utils_1.IS_WINDOWS) { + scriptArguments = ['&', `'${escapedScript}'`]; + if (dotnetVersion.type) { + scriptArguments.push(dotnetVersion.type, dotnetVersion.value); + } + if (this.quality) { + this.setQuality(dotnetVersion, scriptArguments); + } + if (process.env['https_proxy'] != null) { + scriptArguments.push(`-ProxyAddress ${process.env['https_proxy']}`); + } + // This is not currently an option + if (process.env['no_proxy'] != null) { + scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); + } + scriptPath = + (yield io.which('pwsh', false)) || (yield io.which('powershell', true)); + scriptArguments = windowsDefaultOptions.concat(scriptArguments); + } + else { + (0, fs_1.chmodSync)(escapedScript, '777'); + scriptPath = yield io.which(escapedScript, true); + scriptArguments = []; + if (dotnetVersion.type) { + scriptArguments.push(dotnetVersion.type, dotnetVersion.value); + } + if (this.quality) { + this.setQuality(dotnetVersion, scriptArguments); + } + } + // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used + const getExecOutputOptions = { + ignoreReturnCode: true, + env: process.env + }; + const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, getExecOutputOptions); + if (exitCode) { + throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); + } + return this.outputDotnetVersion(dotnetVersion.value); + }); + } + outputDotnetVersion(version) { + return __awaiter(this, void 0, void 0, function* () { + const installationPath = process.env['DOTNET_INSTALL_DIR']; + let versionsOnRunner = yield (0, promises_1.readdir)(path_1.default.join(installationPath.replace(/'/g, ''), 'sdk')); + let installedVersion = semver_1.default.maxSatisfying(versionsOnRunner, version, { + includePrerelease: true + }); + return installedVersion; + }); + } +} +exports.DotnetCoreInstaller = DotnetCoreInstaller; +_a = DotnetCoreInstaller; +(() => { + const installationDirectoryWindows = path_1.default.join(process.env['PROGRAMFILES'] + '', 'dotnet'); + const installationDirectoryLinux = '/usr/share/dotnet'; + const installationDirectoryMac = path_1.default.join(process.env['HOME'] + '', '.dotnet'); + const dotnetInstallDir = process.env['DOTNET_INSTALL_DIR']; + if (dotnetInstallDir) { + process.env['DOTNET_INSTALL_DIR'] = + _a.convertInstallPathToAbsolute(dotnetInstallDir); + } + else { + if (utils_1.IS_WINDOWS) { + process.env['DOTNET_INSTALL_DIR'] = installationDirectoryWindows; + } + else { + process.env['DOTNET_INSTALL_DIR'] = utils_1.IS_LINUX + ? installationDirectoryLinux + : installationDirectoryMac; + } + } +})(); /***/ }), @@ -391,134 +406,138 @@ DotnetCoreInstaller.installationDirectoryMac = path_1.default.join(process.env[' /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -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); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.run = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const installer_1 = __nccwpck_require__(1480); -const fs = __importStar(__nccwpck_require__(7147)); -const path_1 = __importDefault(__nccwpck_require__(1017)); -const semver_1 = __importDefault(__nccwpck_require__(5911)); -const auth = __importStar(__nccwpck_require__(8527)); -const qualityOptions = [ - 'daily', - 'signed', - 'validated', - 'preview', - 'ga' -]; -function run() { - return __awaiter(this, void 0, void 0, function* () { - try { - // - // dotnet-version is optional, but needs to be provided for most use cases. - // If supplied, install / use from the tool cache. - // global-version-file may be specified to point to a specific global.json - // and will be used to install an additional version. - // If not supplied, look for version in ./global.json. - // If a valid version still can't be identified, nothing will be installed. - // Proxy, auth, (etc) are still set up, even if no version is identified - // - const versions = core.getMultilineInput('dotnet-version'); - const installedDotnetVersions = []; - const globalJsonFileInput = core.getInput('global-json-file'); - if (globalJsonFileInput) { - const globalJsonPath = path_1.default.join(process.cwd(), globalJsonFileInput); - if (!fs.existsSync(globalJsonPath)) { - throw new Error(`The specified global.json file '${globalJsonFileInput}' does not exist`); - } - versions.push(getVersionFromGlobalJson(globalJsonPath)); - } - if (!versions.length) { - // Try to fall back to global.json - core.debug('No version found, trying to find version from global.json'); - const globalJsonPath = path_1.default.join(process.cwd(), 'global.json'); - if (fs.existsSync(globalJsonPath)) { - versions.push(getVersionFromGlobalJson(globalJsonPath)); - } - } - if (versions.length) { - const quality = core.getInput('dotnet-quality'); - if (quality && !qualityOptions.includes(quality)) { - throw new Error(`${quality} is not a supported value for 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`); - } - let dotnetInstaller; - const uniqueVersions = new Set(versions); - for (const version of uniqueVersions) { - dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality); - const installedVersion = yield dotnetInstaller.installDotnet(); - installedDotnetVersions.push(installedVersion); - } - installer_1.DotnetCoreInstaller.addToPath(); - } - const sourceUrl = core.getInput('source-url'); - const configFile = core.getInput('config-file'); - if (sourceUrl) { - auth.configAuthentication(sourceUrl, configFile); - } - const comparisonRange = globalJsonFileInput - ? versions[versions.length - 1] - : '*'; - const versionToOutput = semver_1.default.maxSatisfying(installedDotnetVersions, comparisonRange, { - includePrerelease: true - }); - core.setOutput('dotnet-version', versionToOutput); - const matchersPath = path_1.default.join(__dirname, '..', '.github'); - core.info(`##[add-matcher]${path_1.default.join(matchersPath, 'csc.json')}`); - } - catch (error) { - core.setFailed(error.message); - } - }); -} -exports.run = run; -function getVersionFromGlobalJson(globalJsonPath) { - let version = ''; - const globalJson = JSON.parse( - // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 - fs.readFileSync(globalJsonPath, { encoding: 'utf8' }).trim()); - if (globalJson.sdk && globalJson.sdk.version) { - version = globalJson.sdk.version; - const rollForward = globalJson.sdk.rollForward; - if (rollForward && rollForward === 'latestFeature') { - const [major, minor] = version.split('.'); - version = `${major}.${minor}`; - } - } - return version; -} -run(); + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +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); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.run = void 0; +const core = __importStar(__nccwpck_require__(2186)); +const installer_1 = __nccwpck_require__(1480); +const fs = __importStar(__nccwpck_require__(7147)); +const path_1 = __importDefault(__nccwpck_require__(1017)); +const semver_1 = __importDefault(__nccwpck_require__(5911)); +const auth = __importStar(__nccwpck_require__(8527)); +const qualityOptions = [ + 'daily', + 'signed', + 'validated', + 'preview', + 'ga' +]; +function run() { + return __awaiter(this, void 0, void 0, function* () { + try { + // + // dotnet-version is optional, but needs to be provided for most use cases. + // If supplied, install / use from the tool cache. + // global-version-file may be specified to point to a specific global.json + // and will be used to install an additional version. + // If not supplied, look for version in ./global.json. + // If a valid version still can't be identified, nothing will be installed. + // Proxy, auth, (etc) are still set up, even if no version is identified + // + const versions = core.getMultilineInput('dotnet-version'); + const installedDotnetVersions = []; + const globalJsonFileInput = core.getInput('global-json-file'); + if (globalJsonFileInput) { + const globalJsonPath = path_1.default.join(process.cwd(), globalJsonFileInput); + if (!fs.existsSync(globalJsonPath)) { + throw new Error(`The specified global.json file '${globalJsonFileInput}' does not exist`); + } + versions.push(getVersionFromGlobalJson(globalJsonPath)); + } + if (!versions.length) { + // Try to fall back to global.json + core.debug('No version found, trying to find version from global.json'); + const globalJsonPath = path_1.default.join(process.cwd(), 'global.json'); + if (fs.existsSync(globalJsonPath)) { + versions.push(getVersionFromGlobalJson(globalJsonPath)); + } + } + if (versions.length) { + const quality = core.getInput('dotnet-quality'); + if (quality && !qualityOptions.includes(quality)) { + throw new Error(`${quality} is not a supported value for 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`); + } + let dotnetInstaller; + const uniqueVersions = new Set(versions); + for (const version of uniqueVersions) { + dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality); + const installedVersion = yield dotnetInstaller.installDotnet(); + installedDotnetVersions.push(installedVersion); + } + installer_1.DotnetCoreInstaller.addToPath(); + } + const sourceUrl = core.getInput('source-url'); + const configFile = core.getInput('config-file'); + if (sourceUrl) { + auth.configAuthentication(sourceUrl, configFile); + } + const comparisonRange = globalJsonFileInput + ? versions[versions.length - 1] + : '*'; + const versionToOutput = semver_1.default.maxSatisfying(installedDotnetVersions, comparisonRange, { + includePrerelease: true + }); + core.setOutput('dotnet-version', versionToOutput); + const matchersPath = path_1.default.join(__dirname, '..', '.github'); + core.info(`##[add-matcher]${path_1.default.join(matchersPath, 'csc.json')}`); + } + catch (error) { + core.setFailed(error.message); + } + }); +} +exports.run = run; +function getVersionFromGlobalJson(globalJsonPath) { + let version = ''; + const globalJson = JSON.parse( + // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 + fs.readFileSync(globalJsonPath, { encoding: 'utf8' }).trim()); + if (globalJson.sdk && globalJson.sdk.version) { + version = globalJson.sdk.version; + const rollForward = globalJson.sdk.rollForward; + if (rollForward && rollForward === 'latestFeature') { + const [major, minor] = version.split('.'); + version = `${major}.${minor}`; + } + } + return version; +} +run(); /***/ }), @@ -527,11 +546,11 @@ run(); /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.IS_LINUX = exports.IS_WINDOWS = void 0; -exports.IS_WINDOWS = process.platform === 'win32'; -exports.IS_LINUX = process.platform === 'linux'; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.IS_LINUX = exports.IS_WINDOWS = void 0; +exports.IS_WINDOWS = process.platform === 'win32'; +exports.IS_LINUX = process.platform === 'linux'; /***/ }), diff --git a/package-lock.json b/package-lock.json index ecb8ff4..1687485 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "setup-dotnet", - "version": "3.0.1", + "version": "3.0.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "setup-dotnet", - "version": "3.0.1", + "version": "3.0.2", "license": "MIT", "dependencies": { "@actions/core": "^1.10.0", @@ -26,9 +26,9 @@ "husky": "^8.0.1", "jest": "^27.2.5", "jest-circus": "^27.2.5", - "prettier": "^1.19.1", + "prettier": "^2.7.1", "ts-jest": "^27.0.5", - "typescript": "^3.9.7", + "typescript": "^4.8.4", "wget-improved": "^3.2.1" } }, @@ -3883,15 +3883,18 @@ } }, "node_modules/prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", "dev": true, "bin": { "prettier": "bin-prettier.js" }, "engines": { - "node": ">=4" + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" } }, "node_modules/pretty-format": { @@ -4430,9 +4433,9 @@ } }, "node_modules/typescript": { - "version": "3.9.7", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", - "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==", + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", + "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -7723,9 +7726,9 @@ "dev": true }, "prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", "dev": true }, "pretty-format": { @@ -8123,9 +8126,9 @@ } }, "typescript": { - "version": "3.9.7", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", - "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==", + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", + "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", "dev": true }, "universal-user-agent": { diff --git a/package.json b/package.json index 2fdd345..efa743e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "setup-dotnet", - "version": "3.0.1", + "version": "3.0.2", "private": true, "description": "setup dotnet action", "main": "lib/setup-dotnet.js", @@ -41,9 +41,9 @@ "husky": "^8.0.1", "jest": "^27.2.5", "jest-circus": "^27.2.5", - "prettier": "^1.19.1", + "prettier": "^2.7.1", "ts-jest": "^27.0.5", - "typescript": "^3.9.7", + "typescript": "^4.8.4", "wget-improved": "^3.2.1" }, "jest": { diff --git a/src/installer.ts b/src/installer.ts index f7730a6..be0444f 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -6,6 +6,7 @@ import * as hc from '@actions/http-client'; import {chmodSync} from 'fs'; import {readdir} from 'fs/promises'; import path from 'path'; +import os from 'os'; import semver from 'semver'; import {IS_LINUX, IS_WINDOWS} from './utils'; import {QualityOptions} from './setup-dotnet'; @@ -112,40 +113,29 @@ export class DotnetVersionResolver { export class DotnetCoreInstaller { private version: string; private quality: QualityOptions; - private static readonly installationDirectoryWindows = path.join( - process.env['PROGRAMFILES'] + '', - 'dotnet' - ); - private static readonly installationDirectoryLinux = '/usr/share/dotnet'; - private static readonly installationDirectoryMac = path.join( - process.env['HOME'] + '', - '.dotnet' - ); - static addToPath() { - if (process.env['DOTNET_INSTALL_DIR']) { - core.addPath(process.env['DOTNET_INSTALL_DIR']); - core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']); + static { + const installationDirectoryWindows = path.join( + process.env['PROGRAMFILES'] + '', + 'dotnet' + ); + const installationDirectoryLinux = '/usr/share/dotnet'; + const installationDirectoryMac = path.join( + process.env['HOME'] + '', + '.dotnet' + ); + const dotnetInstallDir: string | undefined = + process.env['DOTNET_INSTALL_DIR']; + if (dotnetInstallDir) { + process.env['DOTNET_INSTALL_DIR'] = + this.convertInstallPathToAbsolute(dotnetInstallDir); } else { if (IS_WINDOWS) { - core.addPath(DotnetCoreInstaller.installationDirectoryWindows); - core.exportVariable( - 'DOTNET_ROOT', - DotnetCoreInstaller.installationDirectoryWindows - ); - } else if (IS_LINUX) { - core.addPath(DotnetCoreInstaller.installationDirectoryLinux); - core.exportVariable( - 'DOTNET_ROOT', - DotnetCoreInstaller.installationDirectoryLinux - ); + process.env['DOTNET_INSTALL_DIR'] = installationDirectoryWindows; } else { - // This is the default set in install-dotnet.sh - core.addPath(DotnetCoreInstaller.installationDirectoryMac); - core.exportVariable( - 'DOTNET_ROOT', - DotnetCoreInstaller.installationDirectoryMac - ); + process.env['DOTNET_INSTALL_DIR'] = IS_LINUX + ? installationDirectoryLinux + : installationDirectoryMac; } } } @@ -155,6 +145,23 @@ export class DotnetCoreInstaller { this.quality = quality; } + private static convertInstallPathToAbsolute(installDir: string): string { + let transformedPath; + if (path.isAbsolute(installDir)) { + transformedPath = installDir; + } else { + transformedPath = installDir.startsWith('~') + ? path.join(os.homedir(), installDir.slice(1)) + : (transformedPath = path.join(process.cwd(), installDir)); + } + return path.normalize(transformedPath); + } + + static addToPath() { + core.addPath(process.env['DOTNET_INSTALL_DIR']!); + core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']); + } + private setQuality( dotnetVersion: DotnetVersion, scriptArguments: string[] @@ -208,11 +215,6 @@ export class DotnetCoreInstaller { scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); } - if (!process.env['DOTNET_INSTALL_DIR']) { - process.env['DOTNET_INSTALL_DIR'] = - DotnetCoreInstaller.installationDirectoryWindows; - } - scriptPath = (await io.which('pwsh', false)) || (await io.which('powershell', true)); scriptArguments = windowsDefaultOptions.concat(scriptArguments); @@ -228,12 +230,6 @@ export class DotnetCoreInstaller { if (this.quality) { this.setQuality(dotnetVersion, scriptArguments); } - - if (!process.env['DOTNET_INSTALL_DIR']) { - process.env['DOTNET_INSTALL_DIR'] = IS_LINUX - ? DotnetCoreInstaller.installationDirectoryLinux - : DotnetCoreInstaller.installationDirectoryMac; - } } // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used const getExecOutputOptions = { @@ -249,16 +245,11 @@ export class DotnetCoreInstaller { throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); } - return this.outputDotnetVersion( - dotnetVersion.value, - process.env['DOTNET_INSTALL_DIR'] - ); + return this.outputDotnetVersion(dotnetVersion.value); } - private async outputDotnetVersion( - version, - installationPath - ): Promise { + private async outputDotnetVersion(version): Promise { + const installationPath = process.env['DOTNET_INSTALL_DIR']!; let versionsOnRunner: string[] = await readdir( path.join(installationPath.replace(/'/g, ''), 'sdk') ); diff --git a/tsconfig.json b/tsconfig.json index 5adbcc5..8bd57d4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -35,6 +35,7 @@ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ /* Additional Checks */ + "useUnknownInCatchVariables": false, /* Type catch clause variables as 'unknown' instead of 'any'. */ // "noUnusedLocals": true, /* Report errors on unused locals. */ // "noUnusedParameters": true, /* Report errors on unused parameters. */ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */