Skip to content

Commit

Permalink
fix: remove extra conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
knechtionscoding committed Mar 15, 2024
1 parent 61b2e4e commit 8151a04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 78 deletions.
56 changes: 1 addition & 55 deletions lib/modules/manager/vendir/artifacts.spec.ts
Expand Up @@ -32,10 +32,6 @@ describe('modules/manager/vendir/artifacts', () => {
GlobalConfig.set(adminConfig);
});

afterEach(() => {
GlobalConfig.reset();
});

it('returns null if no vendir.lock.yml found', async () => {
const updatedDeps = [{ depName: 'dep1' }];
expect(
Expand All @@ -59,29 +55,8 @@ describe('modules/manager/vendir/artifacts', () => {
).toBeNull();
});

it('returns null if unchanged', async () => {
fs.readLocalFile.mockResolvedValueOnce(vendirLockFile1);
fs.getSiblingFileName.mockReturnValueOnce('vendir.lock.yml');
const execSnapshots = mockExecAll();
fs.readLocalFile.mockResolvedValueOnce(vendirLockFile1);
fs.privateCacheDir.mockReturnValue(
'/tmp/renovate/cache/__renovate-private-cache',
);
fs.getParentDir.mockReturnValue('');
const updatedDeps = [{ depName: 'dep1' }];
expect(
await vendir.updateArtifacts({
packageFileName: 'vendir.yml',
updatedDeps,
newPackageFileContent: vendirFile,
config,
}),
).toBeNull();
expect(execSnapshots).toMatchSnapshot([{ cmd: 'vendir sync' }]);
});

it('returns updated vendir.lock', async () => {
fs.readLocalFile.mockResolvedValueOnce(vendirLockFile1 as never);
fs.readLocalFile.mockResolvedValueOnce(vendirLockFile1);
fs.getSiblingFileName.mockReturnValueOnce('vendir.lock.yml');
const execSnapshots = mockExecAll();
fs.readLocalFile.mockResolvedValueOnce(vendirLockFile2);
Expand Down Expand Up @@ -109,34 +84,6 @@ describe('modules/manager/vendir/artifacts', () => {
expect(execSnapshots).toMatchObject([{ cmd: 'vendir sync' }]);
});

it('returns updated vendir.yml for lockfile maintenance', async () => {
fs.readLocalFile.mockResolvedValueOnce(vendirLockFile1);
fs.getSiblingFileName.mockReturnValueOnce('vendir.yml');
const execSnapshots = mockExecAll();
fs.readLocalFile.mockResolvedValueOnce(vendirLockFile2);
fs.privateCacheDir.mockReturnValue(
'/tmp/renovate/cache/__renovate-private-cache',
);
fs.getParentDir.mockReturnValue('');
expect(
await vendir.updateArtifacts({
packageFileName: 'vendir.yml',
updatedDeps: [],
newPackageFileContent: vendirFile,
config: { ...config, updateType: 'lockFileMaintenance' },
}),
).toEqual([
{
file: {
type: 'addition',
path: 'vendir.yml',
contents: vendirLockFile2,
},
},
]);
expect(execSnapshots).toMatchObject([{ cmd: 'vendir sync' }]);
});

it('catches errors', async () => {
fs.getSiblingFileName.mockReturnValueOnce('vendir.yml');
fs.readLocalFile.mockResolvedValueOnce(vendirLockFile1);
Expand Down Expand Up @@ -321,7 +268,6 @@ describe('modules/manager/vendir/artifacts', () => {
updatedDeps,
newPackageFileContent: vendirFile,
config: {
postUpdateOptions: ['vendirUpdateSubChartArchives'],
...config,
},
}),
Expand Down
31 changes: 8 additions & 23 deletions lib/modules/manager/vendir/artifacts.ts
@@ -1,4 +1,3 @@
import is from '@sindresorhus/is';
import { TEMPORARY_ERROR } from '../../../constants/error-messages';
import { logger } from '../../../logger';
import { exec } from '../../../util/exec';
Expand All @@ -20,16 +19,6 @@ export async function updateArtifacts({
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
logger.debug(`vendir.updateArtifacts(${packageFileName})`);

const isLockFileMaintenance = config.updateType === 'lockFileMaintenance';

if (
!isLockFileMaintenance &&
(updatedDeps === undefined || updatedDeps.length < 1)
) {
logger.debug('No updated vendir deps - returning null');
return null;
}

const lockFileName = getSiblingFileName(packageFileName, 'vendir.lock.yml');
const existingLockFileContent = await readLocalFile(lockFileName, 'utf8');
if (!existingLockFileContent) {
Expand All @@ -53,18 +42,14 @@ export async function updateArtifacts({

const fileChanges: UpdateArtifactsResult[] = [];

if (is.truthy(existingLockFileContent)) {
const newVendirLockContent = await readLocalFile(lockFileName, 'utf8');
fileChanges.push({
file: {
type: 'addition',
path: lockFileName,
contents: newVendirLockContent,
},
});
} else {
logger.debug('vendir.lock.yml is unchanged');
}
const newVendirLockContent = await readLocalFile(lockFileName, 'utf8');
fileChanges.push({
file: {
type: 'addition',
path: lockFileName,
contents: newVendirLockContent,
},
});

// add modified vendir archives to artifacts
logger.debug("Adding Sync'd files to git");
Expand Down

0 comments on commit 8151a04

Please sign in to comment.