diff --git a/lib/manager/nuget/__snapshots__/artifacts.spec.ts.snap b/lib/manager/nuget/__snapshots__/artifacts.spec.ts.snap index 961ebbd4a6bfca86ab97d173ce1c8aab062b5937..8c3eec536f28ca8fafa4634f5af6d5424d01cb67 100644 --- a/lib/manager/nuget/__snapshots__/artifacts.spec.ts.snap +++ b/lib/manager/nuget/__snapshots__/artifacts.spec.ts.snap @@ -2,24 +2,6 @@ exports[`updateArtifacts aborts if lock file is unchanged 1`] = ` Array [ - Object { - "cmd": "dotnet new nugetconfig --output ./others/nuget/not-so-random", - "options": Object { - "cwd": "/tmp/github/some/repo", - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "maxBuffer": 10485760, - "timeout": 900000, - }, - }, Object { "cmd": "dotnet restore project.csproj --force-evaluate --configfile others/nuget/not-so-random/nuget.config", "options": Object { @@ -46,25 +28,7 @@ exports[`updateArtifacts aborts if no lock file found 1`] = `Array []`; exports[`updateArtifacts authenticates at registries 1`] = ` Array [ Object { - "cmd": "dotnet new nugetconfig --output ./others/nuget/not-so-random", - "options": Object { - "cwd": "/tmp/github/some/repo", - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "maxBuffer": 10485760, - "timeout": 900000, - }, - }, - Object { - "cmd": "dotnet nuget add source https://my-registry.example.org --name myRegistry --configfile others/nuget/not-so-random/nuget.config --username some-username --password some-password --store-password-in-clear-text", + "cmd": "dotnet nuget add source https://my-registry.example.org --configfile others/nuget/not-so-random/nuget.config --name myRegistry --username some-username --password some-password --store-password-in-clear-text", "options": Object { "cwd": "/tmp/github/some/repo", "encoding": "utf-8", @@ -119,24 +83,6 @@ exports[`updateArtifacts does not update lock file when non-proj file is changed exports[`updateArtifacts performs lock file maintenance 1`] = ` Array [ - Object { - "cmd": "dotnet new nugetconfig --output ./others/nuget/not-so-random", - "options": Object { - "cwd": "/tmp/github/some/repo", - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "maxBuffer": 10485760, - "timeout": 900000, - }, - }, Object { "cmd": "dotnet restore project.csproj --force-evaluate --configfile others/nuget/not-so-random/nuget.config", "options": Object { @@ -173,7 +119,7 @@ Array [ }, }, Object { - "cmd": "docker run --rm --name=renovate_dotnet --label=renovate_child --user=foobar -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -w \\"/tmp/github/some/repo\\" renovate/dotnet bash -l -c \\"dotnet new nugetconfig --output ./others/nuget/not-so-random && dotnet restore project.csproj --force-evaluate --configfile others/nuget/not-so-random/nuget.config\\"", + "cmd": "docker run --rm --name=renovate_dotnet --label=renovate_child --user=foobar -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -w \\"/tmp/github/some/repo\\" renovate/dotnet bash -l -c \\"dotnet restore project.csproj --force-evaluate --configfile others/nuget/not-so-random/nuget.config\\"", "options": Object { "cwd": "/tmp/github/some/repo", "encoding": "utf-8", @@ -195,24 +141,6 @@ Array [ exports[`updateArtifacts supports global mode 1`] = ` Array [ - Object { - "cmd": "dotnet new nugetconfig --output ./others/nuget/not-so-random", - "options": Object { - "cwd": "/tmp/github/some/repo", - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "maxBuffer": 10485760, - "timeout": 900000, - }, - }, Object { "cmd": "dotnet restore project.csproj --force-evaluate --configfile others/nuget/not-so-random/nuget.config", "options": Object { @@ -236,24 +164,6 @@ Array [ exports[`updateArtifacts updates lock file 1`] = ` Array [ - Object { - "cmd": "dotnet new nugetconfig --output ./others/nuget/not-so-random", - "options": Object { - "cwd": "/tmp/github/some/repo", - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "maxBuffer": 10485760, - "timeout": 900000, - }, - }, Object { "cmd": "dotnet restore project.csproj --force-evaluate --configfile others/nuget/not-so-random/nuget.config", "options": Object { diff --git a/lib/manager/nuget/artifacts.spec.ts b/lib/manager/nuget/artifacts.spec.ts index f88cb4a7d997d0ffb56b380aeb486bf8c2c9f4c5..efde7a1d800496c1c30d45e9975e45190940210e 100644 --- a/lib/manager/nuget/artifacts.spec.ts +++ b/lib/manager/nuget/artifacts.spec.ts @@ -9,7 +9,8 @@ import * as _env from '../../util/exec/env'; import * as _hostRules from '../../util/host-rules'; import * as nuget from './artifacts'; import { - determineRegistries as _determineRegistries, + getConfiguredRegistries as _getConfiguredRegistries, + getDefaultRegistries as _getDefaultRegistries, getRandomString as _getRandomString, } from './util'; @@ -21,7 +22,8 @@ jest.mock('./util'); const exec: jest.Mock<typeof _exec> = _exec as any; const env = mocked(_env); -const determineRegistries: jest.Mock<typeof _determineRegistries> = _determineRegistries as any; +const getConfiguredRegistries: jest.Mock<typeof _getConfiguredRegistries> = _getConfiguredRegistries as any; +const getDefaultRegistries: jest.Mock<typeof _getDefaultRegistries> = _getDefaultRegistries as any; const getRandomString: jest.Mock<typeof _getRandomString> = _getRandomString as any; const hostRules = mocked(_hostRules); @@ -36,6 +38,7 @@ describe('updateArtifacts', () => { beforeEach(async () => { jest.resetAllMocks(); jest.resetModules(); + getDefaultRegistries.mockReturnValue([] as any); env.getChildProcessEnv.mockReturnValue(envMock.basic); fs.ensureCacheDir.mockImplementation((dirName: string) => Promise.resolve(dirName) @@ -191,7 +194,7 @@ describe('updateArtifacts', () => { fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json' as any); - determineRegistries.mockResolvedValueOnce([ + getConfiguredRegistries.mockResolvedValueOnce([ { name: 'myRegistry', url: 'https://my-registry.example.org', diff --git a/lib/manager/nuget/artifacts.ts b/lib/manager/nuget/artifacts.ts index de5d9d80b8241e7542b96f47f4a9ebb23851448e..8c4c0b0ed1f93cf93ccba650890b98a4d2b742cd 100644 --- a/lib/manager/nuget/artifacts.ts +++ b/lib/manager/nuget/artifacts.ts @@ -5,6 +5,7 @@ import { ExecOptions, exec } from '../../util/exec'; import { ensureCacheDir, getSiblingFileName, + outputFile, readLocalFile, remove, writeLocalFile, @@ -15,25 +16,33 @@ import { UpdateArtifactsConfig, UpdateArtifactsResult, } from '../common'; -import { determineRegistries, getRandomString } from './util'; +import { + getConfiguredRegistries, + getDefaultRegistries, + getRandomString, +} from './util'; async function addSourceCmds( packageFileName: string, config: UpdateArtifactsConfig, nugetConfigFile: string ): Promise<string[]> { - const registries = ( - (await determineRegistries(packageFileName, config.localDir)) || [] - ).filter((registry) => registry.name != null); + const registries = + (await getConfiguredRegistries(packageFileName, config.localDir)) || + getDefaultRegistries(); const result = []; for (const registry of registries) { const { username, password } = hostRules.find({ hostType: id, url: registry.url, }); - let addSourceCmd = `dotnet nuget add source ${registry.url} --name ${registry.name} --configfile ${nugetConfigFile}`; + let addSourceCmd = `dotnet nuget add source ${registry.url} --configfile ${nugetConfigFile}`; + if (registry.name) { + // Add name for registry, if known. + addSourceCmd += ` --name ${registry.name}`; + } if (username && password) { - // Add registry credentials from host rules. + // Add registry credentials from host rules, if configured. addSourceCmd += ` --username ${username} --password ${password} --store-password-in-clear-text`; } result.push(addSourceCmd); @@ -55,8 +64,11 @@ async function runDotnetRestore( `./others/nuget/${getRandomString()}` ); const nugetConfigFile = join(nugetConfigDir, 'nuget.config'); + await outputFile( + nugetConfigFile, + `<?xml version="1.0" encoding="utf-8"?>\n<configuration>\n</configuration>\n` + ); const cmds = [ - `dotnet new nugetconfig --output ${nugetConfigDir}`, ...(await addSourceCmds(packageFileName, config, nugetConfigFile)), `dotnet restore ${packageFileName} --force-evaluate --configfile ${nugetConfigFile}`, ]; diff --git a/lib/manager/nuget/extract.ts b/lib/manager/nuget/extract.ts index ca2ea845fb4559a498d67a9a6e0ded13edf5581c..aa07afccff11f0bfba398cf090766da9b5753d9f 100644 --- a/lib/manager/nuget/extract.ts +++ b/lib/manager/nuget/extract.ts @@ -3,7 +3,7 @@ import * as datasourceNuget from '../../datasource/nuget'; import { logger } from '../../logger'; import { ExtractConfig, PackageDependency, PackageFile } from '../common'; import { DotnetToolsManifest } from './types'; -import { determineRegistries } from './util'; +import { getConfiguredRegistries } from './util'; /** * https://docs.microsoft.com/en-us/nuget/concepts/package-versioning @@ -59,7 +59,10 @@ export async function extractPackageFile( ): Promise<PackageFile | null> { logger.trace({ packageFile }, 'nuget.extractPackageFile()'); - const registries = await determineRegistries(packageFile, config.localDir); + const registries = await getConfiguredRegistries( + packageFile, + config.localDir + ); const registryUrls = registries ? registries.map((registry) => registry.url) : undefined; diff --git a/lib/manager/nuget/util.ts b/lib/manager/nuget/util.ts index 499a44a046d553b6e38ad34ccd3eb46e8a433757..3f8d19e2b8867a41f30b53e9ab42af23c1715995 100644 --- a/lib/manager/nuget/util.ts +++ b/lib/manager/nuget/util.ts @@ -25,7 +25,16 @@ export function getRandomString(): string { return cryptoRandomString({ length: 16 }); } -export async function determineRegistries( +export function getDefaultRegistries(): Registry[] { + return datasourceNuget.defaultRegistryUrls.map( + (registryUrl) => + ({ + url: registryUrl, + } as Registry) + ); +} + +export async function getConfiguredRegistries( packageFile: string, localDir: string ): Promise<Registry[] | undefined> { @@ -56,12 +65,7 @@ export async function determineRegistries( return undefined; } - const registries = datasourceNuget.defaultRegistryUrls.map( - (registryUrl) => - ({ - url: registryUrl, - } as Registry) - ); + const registries = getDefaultRegistries(); for (const child of packageSources.children) { if (child.type === 'element') { if (child.name === 'clear') {