mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-08-20 15:40:20 +00:00
Honor specified nuget file location
This commit is contained in:
parent
61ee7d7a72
commit
be33caae9f
@ -75,7 +75,6 @@ const azureartifactsnugetorgNuGetConfig: string = `<?xml version="1.0" encoding=
|
|||||||
const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config');
|
const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config');
|
||||||
|
|
||||||
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
||||||
process.env['RUNNER_TEMP'] = fakeSourcesDirForTesting;
|
|
||||||
import * as auth from '../src/authutil';
|
import * as auth from '../src/authutil';
|
||||||
|
|
||||||
describe('authutil tests', () => {
|
describe('authutil tests', () => {
|
||||||
@ -95,7 +94,9 @@ describe('authutil tests', () => {
|
|||||||
it('No existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
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';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
|
'',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
@ -107,7 +108,9 @@ describe('authutil tests', () => {
|
|||||||
let thrown = false;
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
|
'',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
);
|
);
|
||||||
} catch {
|
} catch {
|
||||||
thrown = true;
|
thrown = true;
|
||||||
@ -119,7 +122,9 @@ describe('authutil tests', () => {
|
|||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
process.env['INPUT_OWNER'] = 'otherorg';
|
process.env['INPUT_OWNER'] = 'otherorg';
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/otherorg/index.json'
|
'https://nuget.pkg.github.com/otherorg/index.json',
|
||||||
|
'',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
@ -137,7 +142,9 @@ describe('authutil tests', () => {
|
|||||||
let thrown = false;
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
|
'',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
);
|
);
|
||||||
} catch {
|
} catch {
|
||||||
thrown = true;
|
thrown = true;
|
||||||
@ -153,7 +160,9 @@ describe('authutil tests', () => {
|
|||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
|
'',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
@ -169,7 +178,9 @@ describe('authutil tests', () => {
|
|||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
|
'',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
@ -185,7 +196,9 @@ describe('authutil tests', () => {
|
|||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
|
'',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
@ -201,7 +214,9 @@ describe('authutil tests', () => {
|
|||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
|
'',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
@ -216,7 +231,11 @@ describe('authutil tests', () => {
|
|||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
|
||||||
await auth.configAuthentication('https://nuget.pkg.github.com');
|
await auth.configAuthentication(
|
||||||
|
'https://nuget.pkg.github.com',
|
||||||
|
'',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
@ -233,7 +252,9 @@ describe('authutil tests', () => {
|
|||||||
let thrown = false;
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
|
'',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
);
|
);
|
||||||
} catch {
|
} catch {
|
||||||
thrown = true;
|
thrown = true;
|
||||||
@ -255,7 +276,8 @@ describe('authutil tests', () => {
|
|||||||
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
'subfolder/nuget.config'
|
'subfolder/nuget.config',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
@ -271,7 +293,9 @@ describe('authutil tests', () => {
|
|||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||||
|
'',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
@ -287,7 +311,9 @@ describe('authutil tests', () => {
|
|||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||||
|
'',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
@ -298,7 +324,9 @@ describe('authutil tests', () => {
|
|||||||
it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => {
|
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';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||||
|
'',
|
||||||
|
fakeSourcesDirForTesting
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
|
@ -4,18 +4,20 @@ import * as core from '@actions/core';
|
|||||||
import * as github from '@actions/github';
|
import * as github from '@actions/github';
|
||||||
import * as xmlbuilder from 'xmlbuilder';
|
import * as xmlbuilder from 'xmlbuilder';
|
||||||
import * as xmlParser from 'fast-xml-parser';
|
import * as xmlParser from 'fast-xml-parser';
|
||||||
|
import { ProcessEnvOptions } from 'child_process';
|
||||||
|
|
||||||
export function configAuthentication(
|
export function configAuthentication(
|
||||||
feedUrl: string,
|
feedUrl: string,
|
||||||
existingFileLocation: string = ''
|
existingFileLocation: string = '',
|
||||||
|
processRoot: string = process.cwd()
|
||||||
) {
|
) {
|
||||||
const existingNuGetConfig: string = path.resolve(
|
const existingNuGetConfig: string = path.resolve(
|
||||||
process.env['RUNNER_TEMP'] || process.cwd(),
|
processRoot,
|
||||||
existingFileLocation == '' ? 'nuget.config' : existingFileLocation
|
existingFileLocation == '' ? 'nuget.config' : existingFileLocation
|
||||||
);
|
);
|
||||||
|
|
||||||
const tempNuGetConfig: string = path.resolve(
|
const tempNuGetConfig: string = path.resolve(
|
||||||
process.env['RUNNER_TEMP'] || process.cwd(),
|
processRoot,
|
||||||
'../',
|
'../',
|
||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user