diff --git a/dist/index.js b/dist/index.js index d897c56..ed26365 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5,142 +5,138 @@ /***/ (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) { - console.log(`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 || 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'); - var 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())) { - let 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())) { - let 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 == 0) { - 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' - var 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) { + var _a, _b; + console.log(`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 || 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 ((_b = (_a = json.configuration) === null || _a === void 0 ? void 0 : _a.packageSources) === null || _b === void 0 ? void 0 : _b.add) { + const packageSources = json.configuration.packageSources.add; + if (Array.isArray(packageSources)) { + packageSources.forEach(source => { + 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}`); + } + }); + } + else { + if (packageSources['@_value'] + .toLowerCase() + .includes(feedUrl.toLowerCase())) { + const key = packageSources['@_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 == 0) { + 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' + var output = xml.end({ pretty: true }); + fs.writeFileSync(tempFileLocation, output); +} /***/ }), @@ -149,261 +145,261 @@ 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()); - }); -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.DotnetCoreInstaller = exports.DotNetVersionInfo = 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 = __nccwpck_require__(9925); -const fs_1 = __nccwpck_require__(7147); -const path = __importStar(__nccwpck_require__(1017)); -const semver = __importStar(__nccwpck_require__(5911)); -const IS_WINDOWS = process.platform === 'win32'; -/** - * Represents the inputted version information - */ -class DotNetVersionInfo { - constructor(version) { - this.isExactVersionSet = false; - this.inputVersion = version; - // Check for exact match - if (semver.valid(semver.clean(version) || '') != null) { - this.fullversion = semver.clean(version); - this.isExactVersionSet = true; - return; - } - const parts = version.split('.'); - if (parts.length < 2 || parts.length > 3) - this.throwInvalidVersionFormat(); - if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') { - this.throwInvalidVersionFormat(); - } - const major = this.getVersionNumberOrThrow(parts[0]); - const minor = ['x', '*'].includes(parts[1]) - ? parts[1] - : this.getVersionNumberOrThrow(parts[1]); - this.fullversion = major + '.' + minor; - } - getVersionNumberOrThrow(input) { - try { - if (!input || input.trim() === '') - this.throwInvalidVersionFormat(); - let number = Number(input); - if (Number.isNaN(number) || number < 0) - this.throwInvalidVersionFormat(); - return number; - } - catch (_a) { - this.throwInvalidVersionFormat(); - return -1; - } - } - throwInvalidVersionFormat() { - throw new Error('Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*'); - } - /** - * If true exacatly one version should be resolved - */ - isExactVersion() { - return this.isExactVersionSet; - } - version() { - return this.fullversion; - } -} -exports.DotNetVersionInfo = DotNetVersionInfo; -class DotnetCoreInstaller { - constructor(version, includePrerelease = false) { - this.version = version; - this.includePrerelease = includePrerelease; - } - installDotnet() { - return __awaiter(this, void 0, void 0, function* () { - let output = ''; - let resultCode = 0; - let calculatedVersion = yield this.resolveVersion(new DotNetVersionInfo(this.version)); - var envVariables = {}; - for (let key in process.env) { - if (process.env[key]) { - let value = process.env[key]; - envVariables[key] = value; - } - } - if (IS_WINDOWS) { - let escapedScript = path - .join(__dirname, '..', 'externals', 'install-dotnet.ps1') - .replace(/'/g, "''"); - let command = `& '${escapedScript}'`; - if (calculatedVersion) { - command += ` -Version ${calculatedVersion}`; - } - if (process.env['https_proxy'] != null) { - command += ` -ProxyAddress ${process.env['https_proxy']}`; - } - // This is not currently an option - if (process.env['no_proxy'] != null) { - command += ` -ProxyBypassList ${process.env['no_proxy']}`; - } - // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used - const powershellPath = yield io.which('powershell', true); - var options = { - listeners: { - stdout: (data) => { - output += data.toString(); - } - }, - env: envVariables - }; - resultCode = yield exec.exec(`"${powershellPath}"`, [ - '-NoLogo', - '-Sta', - '-NoProfile', - '-NonInteractive', - '-ExecutionPolicy', - 'Unrestricted', - '-Command', - command - ], options); - } - else { - let escapedScript = path - .join(__dirname, '..', 'externals', 'install-dotnet.sh') - .replace(/'/g, "''"); - fs_1.chmodSync(escapedScript, '777'); - const scriptPath = yield io.which(escapedScript, true); - let scriptArguments = []; - if (calculatedVersion) { - scriptArguments.push('--version', calculatedVersion); - } - // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used - resultCode = yield exec.exec(`"${scriptPath}"`, scriptArguments, { - listeners: { - stdout: (data) => { - output += data.toString(); - } - }, - env: envVariables - }); - } - if (resultCode != 0) { - throw new Error(`Failed to install dotnet ${resultCode}. ${output}`); - } - }); - } - 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 (IS_WINDOWS) { - // This is the default set in install-dotnet.ps1 - core.addPath(path.join(process.env['LocalAppData'] + '', 'Microsoft', 'dotnet')); - core.exportVariable('DOTNET_ROOT', path.join(process.env['LocalAppData'] + '', 'Microsoft', 'dotnet')); - } - else { - // This is the default set in install-dotnet.sh - core.addPath(path.join(process.env['HOME'] + '', '.dotnet')); - core.exportVariable('DOTNET_ROOT', path.join(process.env['HOME'] + '', '.dotnet')); - } - } - console.log(process.env['PATH']); - } - // versionInfo - versionInfo of the SDK/Runtime - resolveVersion(versionInfo) { - return __awaiter(this, void 0, void 0, function* () { - if (versionInfo.isExactVersion()) { - return versionInfo.version(); - } - const httpClient = new hc.HttpClient('actions/setup-dotnet', [], { - allowRetries: true, - maxRetries: 3 - }); - const releasesJsonUrl = yield this.getReleasesJsonUrl(httpClient, versionInfo.version().split('.')); - const releasesResponse = yield httpClient.getJson(releasesJsonUrl); - const releasesResult = releasesResponse.result || {}; - let releasesInfo = releasesResult['releases']; - releasesInfo = releasesInfo.filter((releaseInfo) => { - return (semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version(), { - includePrerelease: this.includePrerelease - }) || - semver.satisfies(releaseInfo['sdk']['version-display'], versionInfo.version(), { - includePrerelease: this.includePrerelease - })); - }); - // Exclude versions that are newer than the latest if using not exact - let latestSdk = releasesResult['latest-sdk']; - releasesInfo = releasesInfo.filter((releaseInfo) => semver.lte(releaseInfo['sdk']['version'], latestSdk, { - includePrerelease: this.includePrerelease - })); - // Sort for latest version - releasesInfo = releasesInfo.sort((a, b) => semver.rcompare(a['sdk']['version'], b['sdk']['version'], { - includePrerelease: this.includePrerelease - })); - if (releasesInfo.length == 0) { - throw new Error(`Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`); - } - let release = releasesInfo[0]; - return release['sdk']['version']; - }); - } - getReleasesJsonUrl(httpClient, versionParts) { - return __awaiter(this, void 0, void 0, function* () { - const response = yield httpClient.getJson(DotNetCoreIndexUrl); - const result = response.result || {}; - let releasesInfo = result['releases-index']; - releasesInfo = releasesInfo.filter((info) => { - // channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x. - const sdkParts = info['channel-version'].split('.'); - if (versionParts.length >= 2 && - !(versionParts[1] == 'x' || versionParts[1] == '*')) { - return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1]; - } - return versionParts[0] == sdkParts[0]; - }); - if (releasesInfo.length === 0) { - throw new Error(`Could not find info for version ${versionParts.join('.')} at ${DotNetCoreIndexUrl}`); - } - const releaseInfo = releasesInfo[0]; - if (releaseInfo['support-phase'] === 'eol') { - core.warning(`${releaseInfo['product']} ${releaseInfo['channel-version']} is no longer supported and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the .NET support policy.`); - } - return releaseInfo['releases.json']; - }); - } -} -exports.DotnetCoreInstaller = DotnetCoreInstaller; -const DotNetCoreIndexUrl = 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json'; + +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()); + }); +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.DotnetCoreInstaller = exports.DotNetVersionInfo = 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 = __nccwpck_require__(9925); +const fs_1 = __nccwpck_require__(7147); +const path = __importStar(__nccwpck_require__(1017)); +const semver = __importStar(__nccwpck_require__(5911)); +const IS_WINDOWS = process.platform === 'win32'; +/** + * Represents the inputted version information + */ +class DotNetVersionInfo { + constructor(version) { + this.isExactVersionSet = false; + this.inputVersion = version; + // Check for exact match + if (semver.valid(semver.clean(version) || '') != null) { + this.fullversion = semver.clean(version); + this.isExactVersionSet = true; + return; + } + const parts = version.split('.'); + if (parts.length < 2 || parts.length > 3) + this.throwInvalidVersionFormat(); + if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') { + this.throwInvalidVersionFormat(); + } + const major = this.getVersionNumberOrThrow(parts[0]); + const minor = ['x', '*'].includes(parts[1]) + ? parts[1] + : this.getVersionNumberOrThrow(parts[1]); + this.fullversion = major + '.' + minor; + } + getVersionNumberOrThrow(input) { + try { + if (!input || input.trim() === '') + this.throwInvalidVersionFormat(); + let number = Number(input); + if (Number.isNaN(number) || number < 0) + this.throwInvalidVersionFormat(); + return number; + } + catch (_a) { + this.throwInvalidVersionFormat(); + return -1; + } + } + throwInvalidVersionFormat() { + throw new Error('Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*'); + } + /** + * If true exacatly one version should be resolved + */ + isExactVersion() { + return this.isExactVersionSet; + } + version() { + return this.fullversion; + } +} +exports.DotNetVersionInfo = DotNetVersionInfo; +class DotnetCoreInstaller { + constructor(version, includePrerelease = false) { + this.version = version; + this.includePrerelease = includePrerelease; + } + installDotnet() { + return __awaiter(this, void 0, void 0, function* () { + let output = ''; + let resultCode = 0; + let calculatedVersion = yield this.resolveVersion(new DotNetVersionInfo(this.version)); + var envVariables = {}; + for (let key in process.env) { + if (process.env[key]) { + let value = process.env[key]; + envVariables[key] = value; + } + } + if (IS_WINDOWS) { + let escapedScript = path + .join(__dirname, '..', 'externals', 'install-dotnet.ps1') + .replace(/'/g, "''"); + let command = `& '${escapedScript}'`; + if (calculatedVersion) { + command += ` -Version ${calculatedVersion}`; + } + if (process.env['https_proxy'] != null) { + command += ` -ProxyAddress ${process.env['https_proxy']}`; + } + // This is not currently an option + if (process.env['no_proxy'] != null) { + command += ` -ProxyBypassList ${process.env['no_proxy']}`; + } + // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used + const powershellPath = yield io.which('powershell', true); + var options = { + listeners: { + stdout: (data) => { + output += data.toString(); + } + }, + env: envVariables + }; + resultCode = yield exec.exec(`"${powershellPath}"`, [ + '-NoLogo', + '-Sta', + '-NoProfile', + '-NonInteractive', + '-ExecutionPolicy', + 'Unrestricted', + '-Command', + command + ], options); + } + else { + let escapedScript = path + .join(__dirname, '..', 'externals', 'install-dotnet.sh') + .replace(/'/g, "''"); + fs_1.chmodSync(escapedScript, '777'); + const scriptPath = yield io.which(escapedScript, true); + let scriptArguments = []; + if (calculatedVersion) { + scriptArguments.push('--version', calculatedVersion); + } + // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used + resultCode = yield exec.exec(`"${scriptPath}"`, scriptArguments, { + listeners: { + stdout: (data) => { + output += data.toString(); + } + }, + env: envVariables + }); + } + if (resultCode != 0) { + throw new Error(`Failed to install dotnet ${resultCode}. ${output}`); + } + }); + } + 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 (IS_WINDOWS) { + // This is the default set in install-dotnet.ps1 + core.addPath(path.join(process.env['LocalAppData'] + '', 'Microsoft', 'dotnet')); + core.exportVariable('DOTNET_ROOT', path.join(process.env['LocalAppData'] + '', 'Microsoft', 'dotnet')); + } + else { + // This is the default set in install-dotnet.sh + core.addPath(path.join(process.env['HOME'] + '', '.dotnet')); + core.exportVariable('DOTNET_ROOT', path.join(process.env['HOME'] + '', '.dotnet')); + } + } + console.log(process.env['PATH']); + } + // versionInfo - versionInfo of the SDK/Runtime + resolveVersion(versionInfo) { + return __awaiter(this, void 0, void 0, function* () { + if (versionInfo.isExactVersion()) { + return versionInfo.version(); + } + const httpClient = new hc.HttpClient('actions/setup-dotnet', [], { + allowRetries: true, + maxRetries: 3 + }); + const releasesJsonUrl = yield this.getReleasesJsonUrl(httpClient, versionInfo.version().split('.')); + const releasesResponse = yield httpClient.getJson(releasesJsonUrl); + const releasesResult = releasesResponse.result || {}; + let releasesInfo = releasesResult['releases']; + releasesInfo = releasesInfo.filter((releaseInfo) => { + return (semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version(), { + includePrerelease: this.includePrerelease + }) || + semver.satisfies(releaseInfo['sdk']['version-display'], versionInfo.version(), { + includePrerelease: this.includePrerelease + })); + }); + // Exclude versions that are newer than the latest if using not exact + let latestSdk = releasesResult['latest-sdk']; + releasesInfo = releasesInfo.filter((releaseInfo) => semver.lte(releaseInfo['sdk']['version'], latestSdk, { + includePrerelease: this.includePrerelease + })); + // Sort for latest version + releasesInfo = releasesInfo.sort((a, b) => semver.rcompare(a['sdk']['version'], b['sdk']['version'], { + includePrerelease: this.includePrerelease + })); + if (releasesInfo.length == 0) { + throw new Error(`Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`); + } + let release = releasesInfo[0]; + return release['sdk']['version']; + }); + } + getReleasesJsonUrl(httpClient, versionParts) { + return __awaiter(this, void 0, void 0, function* () { + const response = yield httpClient.getJson(DotNetCoreIndexUrl); + const result = response.result || {}; + let releasesInfo = result['releases-index']; + releasesInfo = releasesInfo.filter((info) => { + // channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x. + const sdkParts = info['channel-version'].split('.'); + if (versionParts.length >= 2 && + !(versionParts[1] == 'x' || versionParts[1] == '*')) { + return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1]; + } + return versionParts[0] == sdkParts[0]; + }); + if (releasesInfo.length === 0) { + throw new Error(`Could not find info for version ${versionParts.join('.')} at ${DotNetCoreIndexUrl}`); + } + const releaseInfo = releasesInfo[0]; + if (releaseInfo['support-phase'] === 'eol') { + core.warning(`${releaseInfo['product']} ${releaseInfo['channel-version']} is no longer supported and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the .NET support policy.`); + } + return releaseInfo['releases.json']; + }); + } +} +exports.DotnetCoreInstaller = DotnetCoreInstaller; +const DotNetCoreIndexUrl = 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json'; /***/ }), @@ -412,110 +408,110 @@ const DotNetCoreIndexUrl = 'https://dotnetcli.blob.core.windows.net/dotnet/relea /***/ (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()); - }); -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.run = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const installer = __importStar(__nccwpck_require__(1480)); -const fs = __importStar(__nccwpck_require__(7147)); -const path = __importStar(__nccwpck_require__(1017)); -const auth = __importStar(__nccwpck_require__(8527)); -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 - // - let versions = core.getMultilineInput('dotnet-version'); - const globalJsonFileInput = core.getInput('global-json-file'); - if (globalJsonFileInput) { - const globalJsonPath = path.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.join(process.cwd(), 'global.json'); - if (fs.existsSync(globalJsonPath)) { - versions.push(getVersionFromGlobalJson(globalJsonPath)); - } - } - if (versions.length) { - const includePrerelease = core.getBooleanInput('include-prerelease'); - let dotnetInstaller; - for (const version of new Set(versions)) { - dotnetInstaller = new installer.DotnetCoreInstaller(version, includePrerelease); - yield dotnetInstaller.installDotnet(); - } - installer.DotnetCoreInstaller.addToPath(); - } - const sourceUrl = core.getInput('source-url'); - const configFile = core.getInput('config-file'); - if (sourceUrl) { - auth.configAuthentication(sourceUrl, configFile); - } - const matchersPath = path.join(__dirname, '..', '.github'); - console.log(`##[add-matcher]${path.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()); + }); +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.run = void 0; +const core = __importStar(__nccwpck_require__(2186)); +const installer = __importStar(__nccwpck_require__(1480)); +const fs = __importStar(__nccwpck_require__(7147)); +const path = __importStar(__nccwpck_require__(1017)); +const auth = __importStar(__nccwpck_require__(8527)); +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 + // + let versions = core.getMultilineInput('dotnet-version'); + const globalJsonFileInput = core.getInput('global-json-file'); + if (globalJsonFileInput) { + const globalJsonPath = path.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.join(process.cwd(), 'global.json'); + if (fs.existsSync(globalJsonPath)) { + versions.push(getVersionFromGlobalJson(globalJsonPath)); + } + } + if (versions.length) { + const includePrerelease = core.getBooleanInput('include-prerelease'); + let dotnetInstaller; + for (const version of new Set(versions)) { + dotnetInstaller = new installer.DotnetCoreInstaller(version, includePrerelease); + yield dotnetInstaller.installDotnet(); + } + installer.DotnetCoreInstaller.addToPath(); + } + const sourceUrl = core.getInput('source-url'); + const configFile = core.getInput('config-file'); + if (sourceUrl) { + auth.configAuthentication(sourceUrl, configFile); + } + const matchersPath = path.join(__dirname, '..', '.github'); + console.log(`##[add-matcher]${path.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(); /***/ }),