diff --git a/src/plugins/cargo-workspace.ts b/src/plugins/cargo-workspace.ts index 0a6efe6f2..acc1783f9 100644 --- a/src/plugins/cargo-workspace.ts +++ b/src/plugins/cargo-workspace.ts @@ -84,6 +84,7 @@ interface CrateInfo { export class CargoWorkspace extends WorkspacePlugin { private strategiesByPath: Record = {}; private releasesByPath: Record = {}; + private workspaceManifestPaths = new Set(); protected async buildAllPackages( candidates: CandidateReleasePullRequest[] @@ -164,6 +165,7 @@ export class CargoWorkspace extends WorkspacePlugin { manifestContent: manifestContent.parsedContent, manifestPath, }); + this.workspaceManifestPaths.add(manifestPath); } return { allPackages: allCrates, @@ -198,22 +200,37 @@ export class CargoWorkspace extends WorkspacePlugin { ); existingCandidate.pullRequest.updates = - existingCandidate.pullRequest.updates.map(update => { - if (update.path === addPath(existingCandidate.path, 'Cargo.toml')) { - update.updater = new RawContent(updatedContent); - } else if (update.updater instanceof Changelog && dependencyNotes) { - update.updater.changelogEntry = appendDependenciesSectionToChangelog( - update.updater.changelogEntry, - dependencyNotes, - this.logger + existingCandidate.pullRequest.updates + .filter(update => { + if (existingCandidate.path !== ROOT_PROJECT_PATH) { + return true; + } + const rootManifestPath = addPath( + existingCandidate.path, + 'Cargo.toml' ); - } else if ( - update.path === addPath(existingCandidate.path, 'Cargo.lock') - ) { - update.updater = new CargoLock(updatedVersions); - } - return update; - }); + return ( + !this.workspaceManifestPaths.has(update.path) || + update.path === rootManifestPath + ); + }) + .map(update => { + if (update.path === addPath(existingCandidate.path, 'Cargo.toml')) { + update.updater = new RawContent(updatedContent); + } else if (update.updater instanceof Changelog && dependencyNotes) { + update.updater.changelogEntry = + appendDependenciesSectionToChangelog( + update.updater.changelogEntry, + dependencyNotes, + this.logger + ); + } else if ( + update.path === addPath(existingCandidate.path, 'Cargo.lock') + ) { + update.updater = new CargoLock(updatedVersions); + } + return update; + }); // append dependency notes if (dependencyNotes) { diff --git a/test/plugins/cargo-workspace.ts b/test/plugins/cargo-workspace.ts index 65f46ad22..8f74bbded 100644 --- a/test/plugins/cargo-workspace.ts +++ b/test/plugins/cargo-workspace.ts @@ -608,5 +608,86 @@ describe('CargoWorkspace plugin', () => { } ); }); + + it('removes root rust strategy member updates outside workspace decisions', async () => { + const candidates: CandidateReleasePullRequest[] = [ + buildMockCandidatePullRequest('.', 'rust', '2.33.1', { + component: 'root', + updates: [ + buildMockPackageUpdate('Cargo.toml', 'packages/rustA/Cargo.toml'), + buildMockPackageUpdate( + 'packages/rustA/Cargo.toml', + 'packages/rustA/Cargo.toml' + ), + buildMockPackageUpdate( + 'packages/rustB/Cargo.toml', + 'packages/rustB/Cargo.toml' + ), + ], + }), + ]; + stubFilesFromFixtures({ + sandbox, + github, + fixturePath: fixturesPath, + files: [ + 'Cargo.toml', + 'packages/rustA/Cargo.toml', + 'packages/rustB/Cargo.toml', + 'packages/rustC/Cargo.toml', + 'packages/rustD/Cargo.toml', + 'packages/rustE/Cargo.toml', + ], + flatten: false, + targetBranch: 'main', + }); + sandbox + .stub(github, 'findFilesByGlobAndRef') + .withArgs('packages/rustA', 'main') + .resolves(['packages/rustA']) + .withArgs('packages/rustB', 'main') + .resolves(['packages/rustB']) + .withArgs('packages/rustC', 'main') + .resolves(['packages/rustC']) + .withArgs('packages/rustD', 'main') + .resolves(['packages/rustD']) + .withArgs('packages/rustE', 'main') + .resolves(['packages/rustE']); + plugin = new CargoWorkspace( + github, + 'main', + { + '.': { + releaseType: 'rust', + }, + 'packages/rustA': { + releaseType: 'rust', + }, + 'packages/rustB': { + releaseType: 'rust', + }, + 'packages/rustC': { + releaseType: 'rust', + }, + 'packages/rustD': { + releaseType: 'rust', + }, + 'packages/rustE': { + releaseType: 'rust', + }, + }, + {merge: false} + ); + const newCandidates = await plugin.run(candidates); + const rustCandidate = newCandidates.find( + candidate => candidate.path === '.' + ); + expect(rustCandidate).to.not.be.undefined; + const updates = rustCandidate!.pullRequest.updates; + assertHasUpdate(updates, 'Cargo.toml', RawContent); + assertHasUpdate(updates, 'Cargo.lock'); + assertNoHasUpdate(updates, 'packages/rustA/Cargo.toml'); + assertNoHasUpdate(updates, 'packages/rustB/Cargo.toml'); + }); }); });