mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
fix(manager:nuget): use git to read current lockfile (#15395)
This commit is contained in:
parent
74956b8f9c
commit
5afed40ba3
4 changed files with 36 additions and 30 deletions
|
@ -6,8 +6,8 @@ import type { RepoGlobalConfig } from '../../../config/types';
|
||||||
import * as docker from '../../../util/exec/docker';
|
import * as docker from '../../../util/exec/docker';
|
||||||
import * as _hostRules from '../../../util/host-rules';
|
import * as _hostRules from '../../../util/host-rules';
|
||||||
import type { UpdateArtifactsConfig } from '../types';
|
import type { UpdateArtifactsConfig } from '../types';
|
||||||
import * as nuget from './artifacts';
|
|
||||||
import * as util from './util';
|
import * as util from './util';
|
||||||
|
import * as nuget from '.';
|
||||||
|
|
||||||
jest.mock('child_process');
|
jest.mock('child_process');
|
||||||
jest.mock('../../../util/exec/env');
|
jest.mock('../../../util/exec/env');
|
||||||
|
@ -66,7 +66,7 @@ describe('modules/manager/nuget/artifacts', () => {
|
||||||
fs.getSiblingFileName.mockReturnValueOnce(
|
fs.getSiblingFileName.mockReturnValueOnce(
|
||||||
'path/with space/packages.lock.json'
|
'path/with space/packages.lock.json'
|
||||||
);
|
);
|
||||||
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
|
git.getFile.mockResolvedValueOnce('Current packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
|
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
|
||||||
expect(
|
expect(
|
||||||
await nuget.updateArtifacts({
|
await nuget.updateArtifacts({
|
||||||
|
@ -82,7 +82,7 @@ describe('modules/manager/nuget/artifacts', () => {
|
||||||
it('updates lock file', async () => {
|
it('updates lock file', async () => {
|
||||||
const execSnapshots = mockExecAll(exec);
|
const execSnapshots = mockExecAll(exec);
|
||||||
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
|
git.getFile.mockResolvedValueOnce('Current packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
||||||
expect(
|
expect(
|
||||||
await nuget.updateArtifacts({
|
await nuget.updateArtifacts({
|
||||||
|
@ -98,7 +98,7 @@ describe('modules/manager/nuget/artifacts', () => {
|
||||||
it('does not update lock file when non-proj file is changed', async () => {
|
it('does not update lock file when non-proj file is changed', async () => {
|
||||||
const execSnapshots = mockExecAll(exec);
|
const execSnapshots = mockExecAll(exec);
|
||||||
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
|
git.getFile.mockResolvedValueOnce('Current packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
||||||
expect(
|
expect(
|
||||||
await nuget.updateArtifacts({
|
await nuget.updateArtifacts({
|
||||||
|
@ -114,7 +114,7 @@ describe('modules/manager/nuget/artifacts', () => {
|
||||||
it('does not update lock file when no deps changed', async () => {
|
it('does not update lock file when no deps changed', async () => {
|
||||||
const execSnapshots = mockExecAll(exec);
|
const execSnapshots = mockExecAll(exec);
|
||||||
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
|
git.getFile.mockResolvedValueOnce('Current packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
||||||
expect(
|
expect(
|
||||||
await nuget.updateArtifacts({
|
await nuget.updateArtifacts({
|
||||||
|
@ -130,7 +130,7 @@ describe('modules/manager/nuget/artifacts', () => {
|
||||||
it('performs lock file maintenance', async () => {
|
it('performs lock file maintenance', async () => {
|
||||||
const execSnapshots = mockExecAll(exec);
|
const execSnapshots = mockExecAll(exec);
|
||||||
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
|
git.getFile.mockResolvedValueOnce('Current packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
||||||
expect(
|
expect(
|
||||||
await nuget.updateArtifacts({
|
await nuget.updateArtifacts({
|
||||||
|
@ -150,7 +150,7 @@ describe('modules/manager/nuget/artifacts', () => {
|
||||||
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
|
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
|
||||||
const execSnapshots = mockExecAll(exec);
|
const execSnapshots = mockExecAll(exec);
|
||||||
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
|
git.getFile.mockResolvedValueOnce('Current packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
||||||
expect(
|
expect(
|
||||||
await nuget.updateArtifacts({
|
await nuget.updateArtifacts({
|
||||||
|
@ -167,7 +167,7 @@ describe('modules/manager/nuget/artifacts', () => {
|
||||||
GlobalConfig.set({ ...adminConfig, binarySource: 'global' });
|
GlobalConfig.set({ ...adminConfig, binarySource: 'global' });
|
||||||
const execSnapshots = mockExecAll(exec);
|
const execSnapshots = mockExecAll(exec);
|
||||||
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
|
git.getFile.mockResolvedValueOnce('Current packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
||||||
expect(
|
expect(
|
||||||
await nuget.updateArtifacts({
|
await nuget.updateArtifacts({
|
||||||
|
@ -182,7 +182,7 @@ describe('modules/manager/nuget/artifacts', () => {
|
||||||
|
|
||||||
it('catches errors', async () => {
|
it('catches errors', async () => {
|
||||||
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
|
git.getFile.mockResolvedValueOnce('Current packages.lock.json');
|
||||||
fs.writeLocalFile.mockImplementationOnce(() => {
|
fs.writeLocalFile.mockImplementationOnce(() => {
|
||||||
throw new Error('not found');
|
throw new Error('not found');
|
||||||
});
|
});
|
||||||
|
@ -206,7 +206,7 @@ describe('modules/manager/nuget/artifacts', () => {
|
||||||
it('authenticates at registries', async () => {
|
it('authenticates at registries', async () => {
|
||||||
const execSnapshots = mockExecAll(exec);
|
const execSnapshots = mockExecAll(exec);
|
||||||
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
|
git.getFile.mockResolvedValueOnce('Current packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
||||||
getConfiguredRegistries.mockResolvedValueOnce([
|
getConfiguredRegistries.mockResolvedValueOnce([
|
||||||
{
|
{
|
||||||
|
@ -224,7 +224,7 @@ describe('modules/manager/nuget/artifacts', () => {
|
||||||
password: 'some-password',
|
password: 'some-password',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return undefined;
|
return {};
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
await nuget.updateArtifacts({
|
await nuget.updateArtifacts({
|
||||||
|
@ -240,7 +240,7 @@ describe('modules/manager/nuget/artifacts', () => {
|
||||||
it('strips protocol version from feed url', async () => {
|
it('strips protocol version from feed url', async () => {
|
||||||
const execSnapshots = mockExecAll(exec);
|
const execSnapshots = mockExecAll(exec);
|
||||||
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
|
git.getFile.mockResolvedValueOnce('Current packages.lock.json');
|
||||||
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
|
||||||
getConfiguredRegistries.mockResolvedValueOnce([
|
getConfiguredRegistries.mockResolvedValueOnce([
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
remove,
|
remove,
|
||||||
writeLocalFile,
|
writeLocalFile,
|
||||||
} from '../../../util/fs';
|
} from '../../../util/fs';
|
||||||
|
import { getFile } from '../../../util/git';
|
||||||
import * as hostRules from '../../../util/host-rules';
|
import * as hostRules from '../../../util/host-rules';
|
||||||
import { regEx } from '../../../util/regex';
|
import { regEx } from '../../../util/regex';
|
||||||
import { NugetDatasource } from '../../datasource/nuget';
|
import { NugetDatasource } from '../../datasource/nuget';
|
||||||
|
@ -30,7 +31,7 @@ import {
|
||||||
|
|
||||||
async function addSourceCmds(
|
async function addSourceCmds(
|
||||||
packageFileName: string,
|
packageFileName: string,
|
||||||
config: UpdateArtifactsConfig,
|
_config: UpdateArtifactsConfig,
|
||||||
nugetConfigFile: string
|
nugetConfigFile: string
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
const registries =
|
const registries =
|
||||||
|
@ -93,15 +94,15 @@ async function runDotnetRestore(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLockFileContentMap(
|
async function getLockFileContentMap(
|
||||||
lockFileNames: string[]
|
lockFileNames: string[],
|
||||||
): Promise<Record<string, string>> {
|
local = false
|
||||||
const lockFileContentMap: Record<string, string> = {};
|
): Promise<Record<string, string | null>> {
|
||||||
|
const lockFileContentMap: Record<string, string | null> = {};
|
||||||
|
|
||||||
for (const lockFileName of lockFileNames) {
|
for (const lockFileName of lockFileNames) {
|
||||||
lockFileContentMap[lockFileName] = await readLocalFile(
|
lockFileContentMap[lockFileName] = local
|
||||||
lockFileName,
|
? await readLocalFile(lockFileName, 'utf8')
|
||||||
'utf8'
|
: await getFile(lockFileName);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lockFileContentMap;
|
return lockFileContentMap;
|
||||||
|
@ -166,7 +167,10 @@ export async function updateArtifacts({
|
||||||
|
|
||||||
await runDotnetRestore(packageFileName, packageFiles, config);
|
await runDotnetRestore(packageFileName, packageFiles, config);
|
||||||
|
|
||||||
const newLockFileContentMap = await getLockFileContentMap(lockFileNames);
|
const newLockFileContentMap = await getLockFileContentMap(
|
||||||
|
lockFileNames,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
const retArray: UpdateArtifactsResult[] = [];
|
const retArray: UpdateArtifactsResult[] = [];
|
||||||
for (const lockFileName of lockFileNames) {
|
for (const lockFileName of lockFileNames) {
|
||||||
|
@ -175,15 +179,16 @@ export async function updateArtifacts({
|
||||||
newLockFileContentMap[lockFileName]
|
newLockFileContentMap[lockFileName]
|
||||||
) {
|
) {
|
||||||
logger.trace(`Lock file ${lockFileName} is unchanged`);
|
logger.trace(`Lock file ${lockFileName} is unchanged`);
|
||||||
} else {
|
} else if (newLockFileContentMap[lockFileName]) {
|
||||||
retArray.push({
|
retArray.push({
|
||||||
file: {
|
file: {
|
||||||
type: 'addition',
|
type: 'addition',
|
||||||
path: lockFileName,
|
path: lockFileName,
|
||||||
contents: newLockFileContentMap[lockFileName],
|
contents: newLockFileContentMap[lockFileName]!,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// TODO: else should we return an artifact error if new content is missing?
|
||||||
}
|
}
|
||||||
|
|
||||||
return retArray.length > 0 ? retArray : null;
|
return retArray.length > 0 ? retArray : null;
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { loadFixture } from '../../../../test/util';
|
||||||
import { GlobalConfig } from '../../../config/global';
|
import { GlobalConfig } from '../../../config/global';
|
||||||
import type { RepoGlobalConfig } from '../../../config/types';
|
import type { RepoGlobalConfig } from '../../../config/types';
|
||||||
import type { ExtractConfig } from '../types';
|
import type { ExtractConfig } from '../types';
|
||||||
import { extractPackageFile } from './extract';
|
import { extractPackageFile } from '.';
|
||||||
|
|
||||||
const config: ExtractConfig = {};
|
const config: ExtractConfig = {};
|
||||||
|
|
||||||
|
@ -32,24 +32,24 @@ describe('modules/manager/nuget/extract', () => {
|
||||||
'with-centralized-package-versions/Directory.Packages.props';
|
'with-centralized-package-versions/Directory.Packages.props';
|
||||||
const sample = loadFixture(packageFile);
|
const sample = loadFixture(packageFile);
|
||||||
const res = await extractPackageFile(sample, packageFile, config);
|
const res = await extractPackageFile(sample, packageFile, config);
|
||||||
expect(res.deps).toMatchSnapshot();
|
expect(res?.deps).toMatchSnapshot();
|
||||||
expect(res.deps).toHaveLength(1);
|
expect(res?.deps).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('extracts all dependencies', async () => {
|
it('extracts all dependencies', async () => {
|
||||||
const packageFile = 'sample.csproj';
|
const packageFile = 'sample.csproj';
|
||||||
const sample = loadFixture(packageFile);
|
const sample = loadFixture(packageFile);
|
||||||
const res = await extractPackageFile(sample, packageFile, config);
|
const res = await extractPackageFile(sample, packageFile, config);
|
||||||
expect(res.deps).toMatchSnapshot();
|
expect(res?.deps).toMatchSnapshot();
|
||||||
expect(res.deps).toHaveLength(17);
|
expect(res?.deps).toHaveLength(17);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('extracts all dependencies from global packages file', async () => {
|
it('extracts all dependencies from global packages file', async () => {
|
||||||
const packageFile = 'packages.props';
|
const packageFile = 'packages.props';
|
||||||
const sample = loadFixture(packageFile);
|
const sample = loadFixture(packageFile);
|
||||||
const res = await extractPackageFile(sample, packageFile, config);
|
const res = await extractPackageFile(sample, packageFile, config);
|
||||||
expect(res.deps).toMatchSnapshot();
|
expect(res?.deps).toMatchSnapshot();
|
||||||
expect(res.deps).toHaveLength(17);
|
expect(res?.deps).toHaveLength(17);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('considers NuGet.config', async () => {
|
it('considers NuGet.config', async () => {
|
||||||
|
|
|
@ -23,6 +23,7 @@ export function getSiblingFileName(
|
||||||
return upath.join(subDirectory, otherFileName);
|
return upath.join(subDirectory, otherFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: can return null #7154
|
||||||
export async function readLocalFile(fileName: string): Promise<Buffer>;
|
export async function readLocalFile(fileName: string): Promise<Buffer>;
|
||||||
export async function readLocalFile(
|
export async function readLocalFile(
|
||||||
fileName: string,
|
fileName: string,
|
||||||
|
|
Loading…
Reference in a new issue