Skip to content

Commit 532637c

Browse files
authored
fix(cargo-workspace): stop defaulting to updating all components (#1414)
* test: add failing test for not updating unnecessary components * fix(cargo-workspace): stop default to updating all components
1 parent 2a63ea2 commit 532637c

4 files changed

Lines changed: 71 additions & 31 deletions

File tree

__snapshots__/cargo-workspace.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ Release notes for path: packages/rustA, releaseType: rust
2727
* pkgB bumped from 2.2.2 to 2.2.3
2828
</details>
2929
30-
<details><summary>pkgD: 1.2.4</summary>
31-
32-
### Dependencies
33-
34-
35-
</details>
36-
3730
---
3831
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
3932
`
@@ -71,6 +64,29 @@ Release notes for path: packages/rustA, releaseType: rust
7164
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
7265
`
7366

67+
exports['CargoWorkspace plugin run skips component if not touched 1'] = `
68+
:robot: I have created a release *beep* *boop*
69+
---
70+
71+
72+
<details><summary>pkgB: 2.3.0</summary>
73+
74+
Release notes for path: packages/rustB, releaseType: rust
75+
</details>
76+
77+
<details><summary>pkgC: 3.3.4</summary>
78+
79+
### Dependencies
80+
81+
* The following workspace dependencies were updated
82+
* dependencies
83+
* pkgB bumped from 2.2.2 to 2.3.0
84+
</details>
85+
86+
---
87+
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
88+
`
89+
7490
exports['CargoWorkspace plugin run walks dependency tree and updates previously untouched packages 1'] = `
7591
:robot: I have created a release *beep* *boop*
7692
---

src/plugins/cargo-workspace.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,16 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import {
16-
CandidateReleasePullRequest,
17-
RepositoryConfig,
18-
ROOT_PROJECT_PATH,
19-
} from '../manifest';
15+
import {CandidateReleasePullRequest, ROOT_PROJECT_PATH} from '../manifest';
2016
import {logger} from '../util/logger';
21-
import {
22-
WorkspacePlugin,
23-
DependencyGraph,
24-
DependencyNode,
25-
WorkspacePluginOptions,
26-
} from './workspace';
17+
import {WorkspacePlugin, DependencyGraph, DependencyNode} from './workspace';
2718
import {
2819
CargoManifest,
2920
parseCargoManifest,
3021
CargoDependencies,
3122
CargoDependency,
3223
} from '../updaters/rust/common';
3324
import {VersionsMap, Version} from '../version';
34-
import {GitHub} from '../github';
3525
import {CargoToml} from '../updaters/rust/cargo-toml';
3626
import {RawContent} from '../updaters/raw-content';
3727
import {Changelog} from '../updaters/changelog';
@@ -82,17 +72,6 @@ interface CrateInfo {
8272
* into a single rust package.
8373
*/
8474
export class CargoWorkspace extends WorkspacePlugin<CrateInfo> {
85-
constructor(
86-
github: GitHub,
87-
targetBranch: string,
88-
repositoryConfig: RepositoryConfig,
89-
options: WorkspacePluginOptions = {}
90-
) {
91-
super(github, targetBranch, repositoryConfig, {
92-
...options,
93-
updateAllPackages: true,
94-
});
95-
}
9675
protected async buildAllPackages(
9776
candidates: CandidateReleasePullRequest[]
9877
): Promise<{

src/plugins/workspace.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ export abstract class WorkspacePlugin<T> extends ManifestPlugin {
277277
graph: DependencyGraph<T>,
278278
packageNamesToUpdate: string[]
279279
): T[] {
280+
logger.info(
281+
`building graph order, existing package names: ${packageNamesToUpdate}`
282+
);
283+
280284
// invert the graph so it's dependency name => packages that depend on it
281285
const dependentGraph = this.invertGraph(graph);
282286
const visited: Set<T> = new Set();

test/plugins/cargo-workspace.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
assertHasUpdate,
2424
dateSafe,
2525
stubFilesFromFixtures,
26+
assertNoHasUpdate,
2627
} from '../helpers';
2728
import {Version} from '../../src/version';
2829
import {ManifestPlugin} from '../../src/plugin';
@@ -300,7 +301,47 @@ describe('CargoWorkspace plugin', () => {
300301
assertHasUpdate(updates, 'packages/rustA/Cargo.toml', RawContent);
301302
assertHasUpdate(updates, 'packages/rustB/Cargo.toml', RawContent);
302303
assertHasUpdate(updates, 'packages/rustC/Cargo.toml', RawContent);
303-
assertHasUpdate(updates, 'packages/rustD/Cargo.toml', RawContent);
304+
snapshot(dateSafe(rustCandidate!.pullRequest.body.toString()));
305+
});
306+
it('skips component if not touched', async () => {
307+
const candidates: CandidateReleasePullRequest[] = [
308+
buildMockCandidatePullRequest(
309+
'packages/rustB',
310+
'rust',
311+
'2.3.0',
312+
'pkgB',
313+
[
314+
buildMockPackageUpdate(
315+
'packages/rustB/Cargo.toml',
316+
'packages/rustB/Cargo.toml'
317+
),
318+
]
319+
),
320+
];
321+
stubFilesFromFixtures({
322+
sandbox,
323+
github,
324+
fixturePath: fixturesPath,
325+
files: [
326+
'Cargo.toml',
327+
'packages/rustA/Cargo.toml',
328+
'packages/rustB/Cargo.toml',
329+
'packages/rustC/Cargo.toml',
330+
'packages/rustD/Cargo.toml',
331+
],
332+
flatten: false,
333+
targetBranch: 'main',
334+
});
335+
const newCandidates = await plugin.run(candidates);
336+
expect(newCandidates).lengthOf(1);
337+
const rustCandidate = newCandidates.find(
338+
candidate => candidate.config.releaseType === 'rust'
339+
);
340+
expect(rustCandidate).to.not.be.undefined;
341+
const updates = rustCandidate!.pullRequest.updates;
342+
// pkgA is not touched and does not have a dependency on pkgB
343+
assertNoHasUpdate(updates, 'packages/rustA/Cargo.toml');
344+
assertHasUpdate(updates, 'packages/rustB/Cargo.toml', RawContent);
304345
snapshot(dateSafe(rustCandidate!.pullRequest.body.toString()));
305346
});
306347
});

0 commit comments

Comments
 (0)