Skip to content

Commit

Permalink
fix(manager/cargo): only warn for non-locked on crates
Browse files Browse the repository at this point in the history
  • Loading branch information
mkniewallner committed Nov 2, 2024
1 parent 55282f2 commit ab69e05
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
5 changes: 5 additions & 0 deletions lib/modules/manager/cargo/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { RepoGlobalConfig } from '../../../config/types';
import * as docker from '../../../util/exec/docker';
import { ExecError } from '../../../util/exec/exec-error';
import * as _hostRules from '../../../util/host-rules';
import { CrateDatasource } from '../../datasource/crate';
import type { UpdateArtifactsConfig } from '../types';
import * as cargo from '.';

Expand Down Expand Up @@ -132,6 +133,7 @@ describe('modules/manager/cargo/artifacts', () => {
packageName: 'dep1',
lockedVersion: '1.0.0',
newVersion: '1.0.1',
datasource: CrateDatasource.id,
},
];
expect(
Expand Down Expand Up @@ -290,18 +292,21 @@ describe('modules/manager/cargo/artifacts', () => {
packageName: 'dep1',
lockedVersion: '1.0.0',
newVersion: '1.0.1',
datasource: CrateDatasource.id,
},
{
depName: 'dep2',
packageName: 'dep2',
lockedVersion: '1.0.0',
newVersion: '1.0.2',
datasource: CrateDatasource.id,
},
{
depName: 'dep3',
packageName: 'dep3',
lockedVersion: '1.0.0',
newVersion: '1.0.3',
datasource: CrateDatasource.id,
},
];

Expand Down
25 changes: 18 additions & 7 deletions lib/modules/manager/cargo/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '../../../util/fs';
import { getGitEnvironmentVariables } from '../../../util/git/auth';
import { regEx } from '../../../util/regex';
import { CrateDatasource } from '../../datasource/crate';
import type { UpdateArtifact, UpdateArtifactsResult, Upgrade } from '../types';
import { extractLockFileContentVersions } from './locked-version';

Expand Down Expand Up @@ -130,13 +131,23 @@ async function updateArtifactsImpl(
config.constraints?.rust,
);
} else {
const missingDep = updatedDeps.find((dep) => !dep.lockedVersion);
if (missingDep) {
// If there is a dependency without a locked version then log a warning
// and perform a regular workspace lockfile update.
logger.warn(
`Missing locked version for dependency \`${missingDep.depName}\``,
);
const nonCrateDep = updatedDeps.find(
(dep) => dep.datasource !== CrateDatasource.id,
);
const crateDepWithoutLockedVersion = updatedDeps.find(
(dep) => !dep.lockedVersion && dep.datasource === CrateDatasource.id,
);
// Non-crate dependencies (like git ones) do not have locked versions.
// For crate dependencies, not having a locked version is not expected.
// In both situations, perform a regular workspace lockfile update.
if (nonCrateDep || crateDepWithoutLockedVersion) {
if (crateDepWithoutLockedVersion) {
// Only warn when a crate dependency has no locked version, as this is
// not an expected situation.
logger.warn(

Check warning on line 147 in lib/modules/manager/cargo/artifacts.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/manager/cargo/artifacts.ts#L147

Added line #L147 was not covered by tests
`Missing locked version for dependency \`${crateDepWithoutLockedVersion.depName}\``,
);
}
await cargoUpdate(
packageFileName,
false,
Expand Down

0 comments on commit ab69e05

Please sign in to comment.