Skip to content

Commit

Permalink
fix(cargo-workspaces): expand globs in crate paths (#1852)
Browse files Browse the repository at this point in the history
* fix(cargo-workspaces): expand globs in crate paths

* fix(cargo-workspaces): expand globs with github

* test: fix tests

---------

Co-authored-by: Jeff Ching <chingor@google.com>
  • Loading branch information
Stonks3141 and chingor13 authored Mar 13, 2023
1 parent f11ba18 commit 0179f25
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 1 deletion.
19 changes: 19 additions & 0 deletions __snapshots__/cargo-workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ Release notes for path: packages/rustA, releaseType: rust
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
`

exports['CargoWorkspace plugin run handles glob paths 1'] = `
:robot: I have created a release *beep* *boop*
---
<details><summary>@here/pkgA: 1.1.2</summary>
Release notes for path: packages/rustA, releaseType: rust
</details>
<details><summary>@here/pkgD: 4.4.5</summary>
Release notes for path: packages/rustD, releaseType: rust
</details>
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
`

exports['CargoWorkspace plugin run skips component if not touched 1'] = `
:robot: I have created a release *beep* *boop*
---
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/cargo-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,16 @@ export class CargoWorkspace extends WorkspacePlugin<CrateInfo> {

const allCrates: CrateInfo[] = [];
const candidatesByPackage: Record<string, CandidateReleasePullRequest> = {};
const members = cargoManifest.workspace.members;

const members = (
await Promise.all(
cargoManifest.workspace.members.map(member =>
this.github.findFilesByGlob(member)
)
)
).flat();
members.push(ROOT_PROJECT_PATH);

for (const path of members) {
const manifestPath = addPath(path, 'Cargo.toml');
this.logger.info(`looking for candidate with path: ${path}`);
Expand Down
111 changes: 111 additions & 0 deletions test/plugins/cargo-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ describe('CargoWorkspace plugin', () => {
releaseType: 'rust',
},
});
sandbox
.stub(github, 'findFilesByGlob')
.withArgs('packages/rustA')
.resolves(['packages/rustA']);
const newCandidates = await plugin.run(candidates);
expect(newCandidates).lengthOf(2);
const rustCandidate = newCandidates.find(
Expand Down Expand Up @@ -166,6 +170,65 @@ describe('CargoWorkspace plugin', () => {
],
],
});
sandbox
.stub(github, 'findFilesByGlob')
.withArgs('packages/rustA')
.resolves(['packages/rustA'])
.withArgs('packages/rustD')
.resolves(['packages/rustD']);
plugin = new CargoWorkspace(github, 'main', {
'packages/rustA': {
releaseType: 'rust',
},
'packages/rustD': {
releaseType: 'rust',
},
});
const newCandidates = await plugin.run(candidates);
expect(newCandidates).lengthOf(1);
const rustCandidate = newCandidates.find(
candidate => candidate.config.releaseType === 'rust'
);
expect(rustCandidate).to.not.be.undefined;
const updates = rustCandidate!.pullRequest.updates;
assertHasUpdate(updates, 'packages/rustA/Cargo.toml');
assertHasUpdate(updates, 'packages/rustD/Cargo.toml');
snapshot(dateSafe(rustCandidate!.pullRequest.body.toString()));
});
it('handles glob paths', async () => {
const candidates: CandidateReleasePullRequest[] = [
buildMockCandidatePullRequest('packages/rustA', 'rust', '1.1.2', {
component: '@here/pkgA',
updates: [
buildMockPackageUpdate(
'packages/rustA/Cargo.toml',
'packages/rustA/Cargo.toml'
),
],
}),
buildMockCandidatePullRequest('packages/rustD', 'rust', '4.4.5', {
component: '@here/pkgD',
updates: [
buildMockPackageUpdate(
'packages/rustD/Cargo.toml',
'packages/rustD/Cargo.toml'
),
],
}),
];
stubFilesFromFixtures({
sandbox,
github,
fixturePath: fixturesPath,
files: ['packages/rustA/Cargo.toml', 'packages/rustD/Cargo.toml'],
flatten: false,
targetBranch: 'main',
inlineFiles: [['Cargo.toml', '[workspace]\nmembers = ["packages/*"]']],
});
sandbox
.stub(github, 'findFilesByGlob')
.withArgs('packages/*')
.resolves(['packages/rustA', 'packages/rustD']);
plugin = new CargoWorkspace(github, 'main', {
'packages/rustA': {
releaseType: 'rust',
Expand Down Expand Up @@ -221,6 +284,18 @@ describe('CargoWorkspace plugin', () => {
flatten: false,
targetBranch: 'main',
});
sandbox
.stub(github, 'findFilesByGlob')
.withArgs('packages/rustA')
.resolves(['packages/rustA'])
.withArgs('packages/rustB')
.resolves(['packages/rustB'])
.withArgs('packages/rustC')
.resolves(['packages/rustC'])
.withArgs('packages/rustD')
.resolves(['packages/rustD'])
.withArgs('packages/rustE')
.resolves(['packages/rustE']);
const newCandidates = await plugin.run(candidates);
expect(newCandidates).lengthOf(1);
const rustCandidate = newCandidates.find(
Expand Down Expand Up @@ -272,6 +347,18 @@ describe('CargoWorkspace plugin', () => {
flatten: false,
targetBranch: 'main',
});
sandbox
.stub(github, 'findFilesByGlob')
.withArgs('packages/rustA')
.resolves(['packages/rustA'])
.withArgs('packages/rustB')
.resolves(['packages/rustB'])
.withArgs('packages/rustC')
.resolves(['packages/rustC'])
.withArgs('packages/rustD')
.resolves(['packages/rustD'])
.withArgs('packages/rustE')
.resolves(['packages/rustE']);
plugin = new CargoWorkspace(
github,
'main',
Expand Down Expand Up @@ -332,6 +419,18 @@ describe('CargoWorkspace plugin', () => {
flatten: false,
targetBranch: 'main',
});
sandbox
.stub(github, 'findFilesByGlob')
.withArgs('packages/rustA')
.resolves(['packages/rustA'])
.withArgs('packages/rustB')
.resolves(['packages/rustB'])
.withArgs('packages/rustC')
.resolves(['packages/rustC'])
.withArgs('packages/rustD')
.resolves(['packages/rustD'])
.withArgs('packages/rustE')
.resolves(['packages/rustE']);
const newCandidates = await plugin.run(candidates);
expect(newCandidates).lengthOf(1);
const rustCandidate = newCandidates.find(
Expand Down Expand Up @@ -372,6 +471,18 @@ describe('CargoWorkspace plugin', () => {
flatten: false,
targetBranch: 'main',
});
sandbox
.stub(github, 'findFilesByGlob')
.withArgs('packages/rustA')
.resolves(['packages/rustA'])
.withArgs('packages/rustB')
.resolves(['packages/rustB'])
.withArgs('packages/rustC')
.resolves(['packages/rustC'])
.withArgs('packages/rustD')
.resolves(['packages/rustD'])
.withArgs('packages/rustE')
.resolves(['packages/rustE']);
const newCandidates = await plugin.run(candidates);
expect(newCandidates).lengthOf(1);
const rustCandidate = newCandidates.find(
Expand Down
6 changes: 6 additions & 0 deletions test/plugins/compatibility/linked-versions-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ describe('Plugin compatibility', () => {
],
],
});
sandbox
.stub(github, 'findFilesByGlob')
.withArgs('packages/rustA')
.resolves(['packages/rustA'])
.withArgs('packages/rustB')
.resolves(['packages/rustB']);
const manifest = new Manifest(
github,
'main',
Expand Down

0 comments on commit 0179f25

Please sign in to comment.