From 8bcd8d8b4963209ddc611fb6ae3cd6f236aaa45c Mon Sep 17 00:00:00 2001 From: Zachary Taylor Date: Thu, 2 Jan 2025 00:13:37 +0000 Subject: [PATCH] linter fixes --- __tests__/authutil.test.ts | 676 ++++++++++++++++++------------------- src/authutil.ts | 310 ++++++++--------- src/installer.ts | 610 ++++++++++++++++----------------- src/setup-dotnet.ts | 5 +- 4 files changed, 798 insertions(+), 803 deletions(-) diff --git a/__tests__/authutil.test.ts b/__tests__/authutil.test.ts index f2e82d8..2302c8d 100644 --- a/__tests__/authutil.test.ts +++ b/__tests__/authutil.test.ts @@ -1,340 +1,336 @@ -import io = require('@actions/io'); -import fs = require('fs'); -import path = require('path'); - -const fakeSourcesDirForTesting = path.join( - __dirname, - 'runner', - path.join( - Math.random() - .toString(36) - .substring(7) - ), - 's' -); - -const invalidNuGetConfig: string = ``; - -const emptyNuGetConfig: string = ` - -`; - -const nugetorgNuGetConfig: string = ` - - - - -`; - -const gprnugetorgNuGetConfig: string = ` - - - - - -`; - -const gprNuGetConfig: string = ` - - - - -`; - -const twogprNuGetConfig: string = ` - - - - - -`; - -const spaceNuGetConfig: string = ` - - - - -`; - -const azureartifactsNuGetConfig: string = ` - - - - -`; - -const azureartifactsnugetorgNuGetConfig: string = ` - - - - - -`; - -// We want a NuGet.config one level above the sources directory, so it doesn't trample a user's NuGet.config but is still picked up by NuGet/dotnet. -const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config'); - -process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo'; -import * as auth from '../src/authutil'; - -describe('authutil tests', () => { - beforeEach(async () => { - await io.rmRF(fakeSourcesDirForTesting); - await io.mkdirP(fakeSourcesDirForTesting); - }, 30000); - - afterAll(async () => { - await io.rmRF(fakeSourcesDirForTesting); - }, 30000); - - beforeEach(() => { - if (fs.existsSync(nugetConfigFile)) { - fs.unlinkSync(nugetConfigFile); - } - process.env['INPUT_OWNER'] = ''; - process.env['NUGET_AUTH_TOKEN'] = ''; - }); - - it('No existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => { - process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; - await auth.configAuthentication( - 'https://nuget.pkg.github.com/OwnerName/index.json', - '', - fakeSourcesDirForTesting - ); - expect(fs.existsSync(nugetConfigFile)).toBe(true); - expect( - fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) - ).toMatchSnapshot(); - }); - - it('No existing config, auth token environment variable not provided, throws', async () => { - let thrown = false; - try { - await auth.configAuthentication( - 'https://nuget.pkg.github.com/OwnerName/index.json', - '', - fakeSourcesDirForTesting - ); - } catch { - thrown = true; - } - expect(thrown).toBe(true); - }); - - it('No existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR', async () => { - process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; - process.env['INPUT_OWNER'] = 'otherorg'; - await auth.configAuthentication( - 'https://nuget.pkg.github.com/otherorg/index.json', - '', - fakeSourcesDirForTesting - ); - expect(fs.existsSync(nugetConfigFile)).toBe(true); - expect( - fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) - ).toMatchSnapshot(); - }); - - it('Existing config (invalid), tries to parse an invalid NuGet.config and throws', async () => { - process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; - const inputNuGetConfigPath: string = path.join( - fakeSourcesDirForTesting, - 'nuget.config' - ); - fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig); - let thrown = false; - try { - await auth.configAuthentication( - 'https://nuget.pkg.github.com/OwnerName/index.json', - '', - fakeSourcesDirForTesting - ); - } catch { - thrown = true; - } - expect(thrown).toBe(true); - }); - - it('Existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => { - process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; - const inputNuGetConfigPath: string = path.join( - fakeSourcesDirForTesting, - 'nuget.config' - ); - fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig); - await auth.configAuthentication( - 'https://nuget.pkg.github.com/OwnerName/index.json', - '', - fakeSourcesDirForTesting - ); - expect(fs.existsSync(nugetConfigFile)).toBe(true); - expect( - fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) - ).toMatchSnapshot(); - }); - - it('Existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => { - process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; - const inputNuGetConfigPath: string = path.join( - fakeSourcesDirForTesting, - 'nuget.config' - ); - fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig); - await auth.configAuthentication( - 'https://nuget.pkg.github.com/OwnerName/index.json', - '', - fakeSourcesDirForTesting - ); - expect(fs.existsSync(nugetConfigFile)).toBe(true); - expect( - fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) - ).toMatchSnapshot(); - }); - - it('Existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR', async () => { - process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; - const inputNuGetConfigPath: string = path.join( - fakeSourcesDirForTesting, - 'nuget.config' - ); - fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig); - await auth.configAuthentication( - 'https://nuget.pkg.github.com/OwnerName/index.json', - '', - fakeSourcesDirForTesting - ); - expect(fs.existsSync(nugetConfigFile)).toBe(true); - expect( - fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) - ).toMatchSnapshot(); - }); - - it('Existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => { - process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; - const inputNuGetConfigPath: string = path.join( - fakeSourcesDirForTesting, - 'nuget.config' - ); - fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig); - await auth.configAuthentication( - 'https://nuget.pkg.github.com/OwnerName/index.json', - '', - fakeSourcesDirForTesting - ); - expect(fs.existsSync(nugetConfigFile)).toBe(true); - expect( - fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) - ).toMatchSnapshot(); - }); - - it('Existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR', async () => { - process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; - const inputNuGetConfigPath: string = path.join( - fakeSourcesDirForTesting, - 'nuget.config' - ); - fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig); - await auth.configAuthentication( - 'https://nuget.pkg.github.com', - '', - fakeSourcesDirForTesting - ); - expect(fs.existsSync(nugetConfigFile)).toBe(true); - expect( - fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) - ).toMatchSnapshot(); - }); - - it('Existing config w/ spaces in key, throws for now', async () => { - process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; - const inputNuGetConfigPath: string = path.join( - fakeSourcesDirForTesting, - 'nuget.config' - ); - fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig); - let thrown = false; - try { - await auth.configAuthentication( - 'https://nuget.pkg.github.com/OwnerName/index.json', - '', - fakeSourcesDirForTesting - ); - } catch { - thrown = true; - } - expect(thrown).toBe(true); - }); - - it('Existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR', async () => { - process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; - const inputNuGetConfigDirectory: string = path.join( - fakeSourcesDirForTesting, - 'subfolder' - ); - const inputNuGetConfigPath: string = path.join( - inputNuGetConfigDirectory, - 'nuget.config' - ); - fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true}); - fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig); - await auth.configAuthentication( - 'https://nuget.pkg.github.com/OwnerName/index.json', - 'subfolder/nuget.config', - fakeSourcesDirForTesting - ); - expect(fs.existsSync(nugetConfigFile)).toBe(true); - expect( - fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) - ).toMatchSnapshot(); - }); - - it('Existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR', async () => { - process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; - const inputNuGetConfigPath: string = path.join( - fakeSourcesDirForTesting, - 'nuget.config' - ); - fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig); - await auth.configAuthentication( - 'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json', - '', - fakeSourcesDirForTesting - ); - expect(fs.existsSync(nugetConfigFile)).toBe(true); - expect( - fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) - ).toMatchSnapshot(); - }); - - it('Existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => { - process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; - const inputNuGetConfigPath: string = path.join( - fakeSourcesDirForTesting, - 'nuget.config' - ); - fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig); - await auth.configAuthentication( - 'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json', - '', - fakeSourcesDirForTesting - ); - expect(fs.existsSync(nugetConfigFile)).toBe(true); - expect( - fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) - ).toMatchSnapshot(); - }); - - it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => { - process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; - await auth.configAuthentication( - 'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json', - '', - fakeSourcesDirForTesting - ); - expect(fs.existsSync(nugetConfigFile)).toBe(true); - expect( - fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) - ).toMatchSnapshot(); - }); -}); +import io = require('@actions/io'); +import fs = require('fs'); +import path = require('path'); + +const fakeSourcesDirForTesting = path.join( + __dirname, + 'runner', + path.join(Math.random().toString(36).substring(7)), + 's' +); + +const invalidNuGetConfig: string = ``; + +const emptyNuGetConfig: string = ` + +`; + +const nugetorgNuGetConfig: string = ` + + + + +`; + +const gprnugetorgNuGetConfig: string = ` + + + + + +`; + +const gprNuGetConfig: string = ` + + + + +`; + +const twogprNuGetConfig: string = ` + + + + + +`; + +const spaceNuGetConfig: string = ` + + + + +`; + +const azureartifactsNuGetConfig: string = ` + + + + +`; + +const azureartifactsnugetorgNuGetConfig: string = ` + + + + + +`; + +// We want a NuGet.config one level above the sources directory, so it doesn't trample a user's NuGet.config but is still picked up by NuGet/dotnet. +const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config'); + +process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo'; +import * as auth from '../src/authutil'; + +describe('authutil tests', () => { + beforeEach(async () => { + await io.rmRF(fakeSourcesDirForTesting); + await io.mkdirP(fakeSourcesDirForTesting); + }, 30000); + + afterAll(async () => { + await io.rmRF(fakeSourcesDirForTesting); + }, 30000); + + beforeEach(() => { + if (fs.existsSync(nugetConfigFile)) { + fs.unlinkSync(nugetConfigFile); + } + process.env['INPUT_OWNER'] = ''; + process.env['NUGET_AUTH_TOKEN'] = ''; + }); + + it('No existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => { + process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; + await auth.configAuthentication( + 'https://nuget.pkg.github.com/OwnerName/index.json', + '', + fakeSourcesDirForTesting + ); + expect(fs.existsSync(nugetConfigFile)).toBe(true); + expect( + fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) + ).toMatchSnapshot(); + }); + + it('No existing config, auth token environment variable not provided, throws', async () => { + let thrown = false; + try { + await auth.configAuthentication( + 'https://nuget.pkg.github.com/OwnerName/index.json', + '', + fakeSourcesDirForTesting + ); + } catch { + thrown = true; + } + expect(thrown).toBe(true); + }); + + it('No existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR', async () => { + process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; + process.env['INPUT_OWNER'] = 'otherorg'; + await auth.configAuthentication( + 'https://nuget.pkg.github.com/otherorg/index.json', + '', + fakeSourcesDirForTesting + ); + expect(fs.existsSync(nugetConfigFile)).toBe(true); + expect( + fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) + ).toMatchSnapshot(); + }); + + it('Existing config (invalid), tries to parse an invalid NuGet.config and throws', async () => { + process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; + const inputNuGetConfigPath: string = path.join( + fakeSourcesDirForTesting, + 'nuget.config' + ); + fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig); + let thrown = false; + try { + await auth.configAuthentication( + 'https://nuget.pkg.github.com/OwnerName/index.json', + '', + fakeSourcesDirForTesting + ); + } catch { + thrown = true; + } + expect(thrown).toBe(true); + }); + + it('Existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => { + process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; + const inputNuGetConfigPath: string = path.join( + fakeSourcesDirForTesting, + 'nuget.config' + ); + fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig); + await auth.configAuthentication( + 'https://nuget.pkg.github.com/OwnerName/index.json', + '', + fakeSourcesDirForTesting + ); + expect(fs.existsSync(nugetConfigFile)).toBe(true); + expect( + fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) + ).toMatchSnapshot(); + }); + + it('Existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => { + process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; + const inputNuGetConfigPath: string = path.join( + fakeSourcesDirForTesting, + 'nuget.config' + ); + fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig); + await auth.configAuthentication( + 'https://nuget.pkg.github.com/OwnerName/index.json', + '', + fakeSourcesDirForTesting + ); + expect(fs.existsSync(nugetConfigFile)).toBe(true); + expect( + fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) + ).toMatchSnapshot(); + }); + + it('Existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR', async () => { + process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; + const inputNuGetConfigPath: string = path.join( + fakeSourcesDirForTesting, + 'nuget.config' + ); + fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig); + await auth.configAuthentication( + 'https://nuget.pkg.github.com/OwnerName/index.json', + '', + fakeSourcesDirForTesting + ); + expect(fs.existsSync(nugetConfigFile)).toBe(true); + expect( + fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) + ).toMatchSnapshot(); + }); + + it('Existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => { + process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; + const inputNuGetConfigPath: string = path.join( + fakeSourcesDirForTesting, + 'nuget.config' + ); + fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig); + await auth.configAuthentication( + 'https://nuget.pkg.github.com/OwnerName/index.json', + '', + fakeSourcesDirForTesting + ); + expect(fs.existsSync(nugetConfigFile)).toBe(true); + expect( + fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) + ).toMatchSnapshot(); + }); + + it('Existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR', async () => { + process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; + const inputNuGetConfigPath: string = path.join( + fakeSourcesDirForTesting, + 'nuget.config' + ); + fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig); + await auth.configAuthentication( + 'https://nuget.pkg.github.com', + '', + fakeSourcesDirForTesting + ); + expect(fs.existsSync(nugetConfigFile)).toBe(true); + expect( + fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) + ).toMatchSnapshot(); + }); + + it('Existing config w/ spaces in key, throws for now', async () => { + process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; + const inputNuGetConfigPath: string = path.join( + fakeSourcesDirForTesting, + 'nuget.config' + ); + fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig); + let thrown = false; + try { + await auth.configAuthentication( + 'https://nuget.pkg.github.com/OwnerName/index.json', + '', + fakeSourcesDirForTesting + ); + } catch { + thrown = true; + } + expect(thrown).toBe(true); + }); + + it('Existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR', async () => { + process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; + const inputNuGetConfigDirectory: string = path.join( + fakeSourcesDirForTesting, + 'subfolder' + ); + const inputNuGetConfigPath: string = path.join( + inputNuGetConfigDirectory, + 'nuget.config' + ); + fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true}); + fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig); + await auth.configAuthentication( + 'https://nuget.pkg.github.com/OwnerName/index.json', + 'subfolder/nuget.config', + fakeSourcesDirForTesting + ); + expect(fs.existsSync(nugetConfigFile)).toBe(true); + expect( + fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) + ).toMatchSnapshot(); + }); + + it('Existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR', async () => { + process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; + const inputNuGetConfigPath: string = path.join( + fakeSourcesDirForTesting, + 'nuget.config' + ); + fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig); + await auth.configAuthentication( + 'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json', + '', + fakeSourcesDirForTesting + ); + expect(fs.existsSync(nugetConfigFile)).toBe(true); + expect( + fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) + ).toMatchSnapshot(); + }); + + it('Existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => { + process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; + const inputNuGetConfigPath: string = path.join( + fakeSourcesDirForTesting, + 'nuget.config' + ); + fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig); + await auth.configAuthentication( + 'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json', + '', + fakeSourcesDirForTesting + ); + expect(fs.existsSync(nugetConfigFile)).toBe(true); + expect( + fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) + ).toMatchSnapshot(); + }); + + it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => { + process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; + await auth.configAuthentication( + 'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json', + '', + fakeSourcesDirForTesting + ); + expect(fs.existsSync(nugetConfigFile)).toBe(true); + expect( + fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) + ).toMatchSnapshot(); + }); +}); diff --git a/src/authutil.ts b/src/authutil.ts index 9599979..f635e1b 100644 --- a/src/authutil.ts +++ b/src/authutil.ts @@ -1,155 +1,155 @@ -import * as fs from 'fs'; -import * as path from 'path'; -import * as core from '@actions/core'; -import * as github from '@actions/github'; -import * as xmlbuilder from 'xmlbuilder'; -import * as xmlParser from 'fast-xml-parser'; -import {ProcessEnvOptions} from 'child_process'; - -export function configAuthentication( - feedUrl: string, - existingFileLocation: string = '', - processRoot: string = process.cwd() -) { - const existingNuGetConfig: string = path.resolve( - processRoot, - existingFileLocation === '' - ? getExistingNugetConfig(processRoot) - : existingFileLocation - ); - - const tempNuGetConfig: string = path.resolve( - processRoot, - '../', - 'nuget.config' - ); - - writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig); -} - -function isValidKey(key: string): boolean { - return /^[\w\-\.]+$/i.test(key); -} - -function getExistingNugetConfig(processRoot: string) { - 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: string, - existingFileLocation: string, - tempFileLocation: string -) { - console.log( - `dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}` - ); - let xml: xmlbuilder.XMLElement; - let sourceKeys: string[] = []; - let owner: string = core.getInput('owner'); - let sourceUrl: string = 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: string = 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); -} +import * as fs from 'fs'; +import * as path from 'path'; +import * as core from '@actions/core'; +import * as github from '@actions/github'; +import * as xmlbuilder from 'xmlbuilder'; +import * as xmlParser from 'fast-xml-parser'; +import {ProcessEnvOptions} from 'child_process'; + +export function configAuthentication( + feedUrl: string, + existingFileLocation: string = '', + processRoot: string = process.cwd() +) { + const existingNuGetConfig: string = path.resolve( + processRoot, + existingFileLocation === '' + ? getExistingNugetConfig(processRoot) + : existingFileLocation + ); + + const tempNuGetConfig: string = path.resolve( + processRoot, + '../', + 'nuget.config' + ); + + writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig); +} + +function isValidKey(key: string): boolean { + return /^[\w\-\.]+$/i.test(key); +} + +function getExistingNugetConfig(processRoot: string) { + 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: string, + existingFileLocation: string, + tempFileLocation: string +) { + console.log( + `dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}` + ); + let xml: xmlbuilder.XMLElement; + let sourceKeys: string[] = []; + let owner: string = core.getInput('owner'); + let sourceUrl: string = 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: string = 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); +} diff --git a/src/installer.ts b/src/installer.ts index 471cfe9..21f9889 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -1,305 +1,305 @@ -// Load tempDirectory before it gets wiped by tool-cache -import * as core from '@actions/core'; -import * as exec from '@actions/exec'; -import * as io from '@actions/io'; -import hc = require('@actions/http-client'); -import {chmodSync} from 'fs'; -import * as path from 'path'; -import {ExecOptions} from '@actions/exec/lib/interfaces'; -import * as semver from 'semver'; - -const IS_WINDOWS = process.platform === 'win32'; - -/** - * Represents the inputted version information - */ -export class DotNetVersionInfo { - public inputVersion: string; - private fullversion: string; - private isExactVersionSet: boolean = false; - - constructor(version: string) { - this.inputVersion = version; - - // Check for exact match - if (semver.valid(semver.clean(version) || '') != null) { - this.fullversion = semver.clean(version) as string; - this.isExactVersionSet = true; - - return; - } - - const parts: string[] = 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; - } - - private getVersionNumberOrThrow(input: string): number { - try { - if (!input || input.trim() === '') this.throwInvalidVersionFormat(); - - let number = Number(input); - - if (Number.isNaN(number) || number < 0) this.throwInvalidVersionFormat(); - - return number; - } catch { - this.throwInvalidVersionFormat(); - return -1; - } - } - - private 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 - */ - public isExactVersion(): boolean { - return this.isExactVersionSet; - } - - public version(): string { - return this.fullversion; - } -} - -export class DotnetCoreInstaller { - constructor(version: string, includePrerelease: boolean = false) { - this.version = version; - this.includePrerelease = includePrerelease; - } - - public async installDotnet() { - let output = ''; - let resultCode = 0; - - let calculatedVersion = await this.resolveVersion( - new DotNetVersionInfo(this.version) - ); - - var envVariables: {[key: string]: string} = {}; - for (let key in process.env) { - if (process.env[key]) { - let value: any = 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 = - (await io.which('pwsh', false)) || (await io.which('powershell', true)); - - var options: ExecOptions = { - listeners: { - stdout: (data: Buffer) => { - output += data.toString(); - } - }, - env: envVariables - }; - - resultCode = await exec.exec( - `"${powershellPath}"`, - [ - '-NoLogo', - '-Sta', - '-NoProfile', - '-NonInteractive', - '-ExecutionPolicy', - 'Unrestricted', - '-Command', - command - ], - options - ); - } else { - let escapedScript = path - .join(__dirname, '..', 'externals', 'install-dotnet.sh') - .replace(/'/g, "''"); - chmodSync(escapedScript, '777'); - - const scriptPath = await io.which(escapedScript, true); - - let scriptArguments: string[] = []; - if (calculatedVersion) { - scriptArguments.push('--version', calculatedVersion); - } - - // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used - resultCode = await exec.exec(`"${scriptPath}"`, scriptArguments, { - listeners: { - stdout: (data: Buffer) => { - 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 - async resolveVersion(versionInfo: DotNetVersionInfo): Promise { - if (versionInfo.isExactVersion()) { - return versionInfo.version(); - } - - const httpClient = new hc.HttpClient('actions/setup-dotnet', [], { - allowRetries: true, - maxRetries: 3 - }); - - const releasesJsonUrl: string = await this.getReleasesJsonUrl( - httpClient, - versionInfo.version().split('.') - ); - - const releasesResponse = await httpClient.getJson(releasesJsonUrl); - const releasesResult = releasesResponse.result || {}; - let releasesInfo: any[] = releasesResult['releases']; - releasesInfo = releasesInfo.filter((releaseInfo: any) => { - 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: string = releasesResult['latest-sdk']; - - releasesInfo = releasesInfo.filter((releaseInfo: any) => - 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']; - } - - private async getReleasesJsonUrl( - httpClient: hc.HttpClient, - versionParts: string[] - ): Promise { - const response = await httpClient.getJson(DotNetCoreIndexUrl); - - const result = response.result || {}; - let releasesInfo: any[] = result['releases-index']; - - releasesInfo = releasesInfo.filter((info: any) => { - // channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x. - const sdkParts: string[] = info['channel-version'].split('.'); - if ( - versionParts.length >= 2 && - !(versionParts[1] == 'x' || 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']; - } - - private version: string; - private includePrerelease: boolean; -} - -const DotNetCoreIndexUrl: string = - 'https://builds.dotnet.microsoft.com/dotnet/release-metadata/releases-index.json'; +// Load tempDirectory before it gets wiped by tool-cache +import * as core from '@actions/core'; +import * as exec from '@actions/exec'; +import * as io from '@actions/io'; +import hc = require('@actions/http-client'); +import {chmodSync} from 'fs'; +import * as path from 'path'; +import {ExecOptions} from '@actions/exec/lib/interfaces'; +import * as semver from 'semver'; + +const IS_WINDOWS = process.platform === 'win32'; + +/** + * Represents the inputted version information + */ +export class DotNetVersionInfo { + public inputVersion: string; + private fullversion: string; + private isExactVersionSet: boolean = false; + + constructor(version: string) { + this.inputVersion = version; + + // Check for exact match + if (semver.valid(semver.clean(version) || '') != null) { + this.fullversion = semver.clean(version) as string; + this.isExactVersionSet = true; + + return; + } + + const parts: string[] = 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; + } + + private getVersionNumberOrThrow(input: string): number { + try { + if (!input || input.trim() === '') this.throwInvalidVersionFormat(); + + let number = Number(input); + + if (Number.isNaN(number) || number < 0) this.throwInvalidVersionFormat(); + + return number; + } catch { + this.throwInvalidVersionFormat(); + return -1; + } + } + + private 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 + */ + public isExactVersion(): boolean { + return this.isExactVersionSet; + } + + public version(): string { + return this.fullversion; + } +} + +export class DotnetCoreInstaller { + constructor(version: string, includePrerelease: boolean = false) { + this.version = version; + this.includePrerelease = includePrerelease; + } + + public async installDotnet() { + let output = ''; + let resultCode = 0; + + let calculatedVersion = await this.resolveVersion( + new DotNetVersionInfo(this.version) + ); + + var envVariables: {[key: string]: string} = {}; + for (let key in process.env) { + if (process.env[key]) { + let value: any = 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 = + (await io.which('pwsh', false)) || (await io.which('powershell', true)); + + var options: ExecOptions = { + listeners: { + stdout: (data: Buffer) => { + output += data.toString(); + } + }, + env: envVariables + }; + + resultCode = await exec.exec( + `"${powershellPath}"`, + [ + '-NoLogo', + '-Sta', + '-NoProfile', + '-NonInteractive', + '-ExecutionPolicy', + 'Unrestricted', + '-Command', + command + ], + options + ); + } else { + let escapedScript = path + .join(__dirname, '..', 'externals', 'install-dotnet.sh') + .replace(/'/g, "''"); + chmodSync(escapedScript, '777'); + + const scriptPath = await io.which(escapedScript, true); + + let scriptArguments: string[] = []; + if (calculatedVersion) { + scriptArguments.push('--version', calculatedVersion); + } + + // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used + resultCode = await exec.exec(`"${scriptPath}"`, scriptArguments, { + listeners: { + stdout: (data: Buffer) => { + 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 + async resolveVersion(versionInfo: DotNetVersionInfo): Promise { + if (versionInfo.isExactVersion()) { + return versionInfo.version(); + } + + const httpClient = new hc.HttpClient('actions/setup-dotnet', [], { + allowRetries: true, + maxRetries: 3 + }); + + const releasesJsonUrl: string = await this.getReleasesJsonUrl( + httpClient, + versionInfo.version().split('.') + ); + + const releasesResponse = await httpClient.getJson(releasesJsonUrl); + const releasesResult = releasesResponse.result || {}; + let releasesInfo: any[] = releasesResult['releases']; + releasesInfo = releasesInfo.filter((releaseInfo: any) => { + 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: string = releasesResult['latest-sdk']; + + releasesInfo = releasesInfo.filter((releaseInfo: any) => + 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']; + } + + private async getReleasesJsonUrl( + httpClient: hc.HttpClient, + versionParts: string[] + ): Promise { + const response = await httpClient.getJson(DotNetCoreIndexUrl); + + const result = response.result || {}; + let releasesInfo: any[] = result['releases-index']; + + releasesInfo = releasesInfo.filter((info: any) => { + // channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x. + const sdkParts: string[] = info['channel-version'].split('.'); + if ( + versionParts.length >= 2 && + !(versionParts[1] == 'x' || 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']; + } + + private version: string; + private includePrerelease: boolean; +} + +const DotNetCoreIndexUrl: string = + 'https://builds.dotnet.microsoft.com/dotnet/release-metadata/releases-index.json'; diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 2ae0459..82c6529 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -38,9 +38,8 @@ export async function run() { } if (versions.length) { - const includePrerelease: boolean = core.getBooleanInput( - 'include-prerelease' - ); + const includePrerelease: boolean = + core.getBooleanInput('include-prerelease'); let dotnetInstaller!: installer.DotnetCoreInstaller; for (const version of new Set(versions)) { dotnetInstaller = new installer.DotnetCoreInstaller(