Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions src/plugins/cargo-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ interface CrateInfo {
export class CargoWorkspace extends WorkspacePlugin<CrateInfo> {
private strategiesByPath: Record<string, Strategy> = {};
private releasesByPath: Record<string, Release> = {};
private workspaceManifestPaths = new Set<string>();

protected async buildAllPackages(
candidates: CandidateReleasePullRequest[]
Expand Down Expand Up @@ -164,6 +165,7 @@ export class CargoWorkspace extends WorkspacePlugin<CrateInfo> {
manifestContent: manifestContent.parsedContent,
manifestPath,
});
this.workspaceManifestPaths.add(manifestPath);
}
return {
allPackages: allCrates,
Expand Down Expand Up @@ -198,22 +200,37 @@ export class CargoWorkspace extends WorkspacePlugin<CrateInfo> {
);

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) {
Expand Down
81 changes: 81 additions & 0 deletions test/plugins/cargo-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
Loading