Skip to content

Commit

Permalink
fix(cargo): Revert "fix(cargo): Only use cargo update --precise in …
Browse files Browse the repository at this point in the history
…case of lockfile updates" (#31332)
  • Loading branch information
rarkins committed Sep 11, 2024
1 parent 9e68623 commit 252e140
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 65 deletions.
62 changes: 1 addition & 61 deletions lib/modules/manager/cargo/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '../../../../test/exec-util';
import { env, fs, git, mocked } from '../../../../test/util';
import { GlobalConfig } from '../../../config/global';
import type { RepoGlobalConfig, UpdateType } from '../../../config/types';
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';
Expand Down Expand Up @@ -132,7 +132,6 @@ describe('modules/manager/cargo/artifacts', () => {
packageName: 'dep1',
lockedVersion: '1.0.0',
newVersion: '1.0.1',
updateType: 'lockfileUpdate' satisfies UpdateType as UpdateType,
},
];
expect(
Expand Down Expand Up @@ -291,21 +290,18 @@ describe('modules/manager/cargo/artifacts', () => {
packageName: 'dep1',
lockedVersion: '1.0.0',
newVersion: '1.0.1',
updateType: 'lockfileUpdate' satisfies UpdateType as UpdateType,
},
{
depName: 'dep2',
packageName: 'dep2',
lockedVersion: '1.0.0',
newVersion: '1.0.2',
updateType: 'lockfileUpdate' satisfies UpdateType as UpdateType,
},
{
depName: 'dep3',
packageName: 'dep3',
lockedVersion: '1.0.0',
newVersion: '1.0.3',
updateType: 'lockfileUpdate' satisfies UpdateType as UpdateType,
},
];

Expand All @@ -332,62 +328,6 @@ describe('modules/manager/cargo/artifacts', () => {
]);
});

it('runs cargo update precise only for lockfile update', async () => {
fs.statLocalFile.mockResolvedValueOnce({ name: 'Cargo.lock' } as any);
fs.findLocalSiblingOrParent.mockResolvedValueOnce('Cargo.lock');
git.getFile.mockResolvedValueOnce('Old Cargo.lock');
const execSnapshots = mockExecAll();
fs.findLocalSiblingOrParent.mockResolvedValueOnce('Cargo.lock');
fs.readLocalFile.mockResolvedValueOnce('New Cargo.lock');
const updatedDeps = [
{
depName: 'dep1',
packageName: 'dep1',
updateType: 'minor' satisfies UpdateType as UpdateType,
lockedVersion: '1.0.0',
newVersion: '1.0.1',
},
{
depName: 'dep2',
packageName: 'dep2',
updateType: 'minor' satisfies UpdateType as UpdateType,
lockedVersion: '1.0.0',
newVersion: '1.0.2',
},
{
depName: 'dep3',
packageName: 'dep3',
updateType: 'lockfileUpdate' satisfies UpdateType as UpdateType,
lockedVersion: '1.0.0',
newVersion: '1.0.3',
},
];
expect(
await cargo.updateArtifacts({
packageFileName: 'Cargo.toml',
updatedDeps,
newPackageFileContent: '{}',
config,
}),
).toEqual([
{ file: { contents: undefined, path: 'Cargo.lock', type: 'addition' } },
]);
expect(execSnapshots).toMatchObject([
{
cmd:
'cargo update --config net.git-fetch-with-cli=true' +
' --manifest-path Cargo.toml' +
' --workspace',
},
{
cmd:
'cargo update --config net.git-fetch-with-cli=true' +
' --manifest-path Cargo.toml' +
' --package dep3@1.0.0 --precise 1.0.3',
},
]);
});

it('returns updated Cargo.lock when there are no more dependencies to update', async () => {
fs.findLocalSiblingOrParent.mockResolvedValueOnce('Cargo.lock');
fs.readLocalFile.mockResolvedValueOnce('New Cargo.lock');
Expand Down
5 changes: 1 addition & 4 deletions lib/modules/manager/cargo/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ async function cargoUpdatePrecise(
// Update individual dependencies to their `newVersion`. Necessary when
// using the `update-lockfile` rangeStrategy which doesn't touch Cargo.toml.
for (const dep of updatedDeps) {
// Cargo update should already have handled any non-lockfile updates
if (dep.updateType !== 'lockfileUpdate') {
continue;
}
cmds.push(
`cargo update --config net.git-fetch-with-cli=true` +
` --manifest-path ${quote(manifestPath)}` +
Expand Down Expand Up @@ -148,6 +144,7 @@ async function updateArtifactsImpl(
config.constraints?.rust,
);
} else {
// If all dependencies have locked versions then update them precisely.
await cargoUpdatePrecise(
packageFileName,
updatedDeps,
Expand Down

0 comments on commit 252e140

Please # to comment.