Skip to content

Commit

Permalink
fix(php-yoshi): do not add version to root version map (#2199)
Browse files Browse the repository at this point in the history
* fix: do not add version to root version map

* add versionmap for directories

* add test case

* chore: fix lint

---------

Co-authored-by: Jeff Ching <chingor@google.com>
  • Loading branch information
bshaffer and chingor13 authored Jan 26, 2024
1 parent 03e12ef commit 32a972a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/strategies/php-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export class PHPYoshi extends BaseStrategy {
splitCommits[directory]
);
versionsMap.set(composer.name, newVersion);
versionsMap.set('version', newVersion);
const partialReleaseNotes = await this.changelogNotes.buildNotes(
splitCommits[directory],
{
Expand Down Expand Up @@ -173,6 +172,16 @@ export class PHPYoshi extends BaseStrategy {
version,
}),
});
const directoryVersion: VersionsMap = new Map();
directoryVersion.set('version', version);
updates.push({
path: this.addPath(`${directory}/composer.json`),
createIfMissing: false,
updater: new RootComposerUpdatePackages({
version,
versionsMap: directoryVersion,
}),
});
if (componentInfo.composer.extra?.component?.entry) {
updates.push({
path: this.addPath(
Expand Down
42 changes: 41 additions & 1 deletion test/strategies/php-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ describe('PHPYoshi', () => {
.resolves(buildGitHubFileRaw('0.1.2'));
getFileStub
.withArgs('Client1/composer.json', 'main')
.resolves(buildGitHubFileRaw('{"name": "google/client1"}'));
.resolves(
buildGitHubFileRaw('{"name": "google/client1", "version": "1.2.3"}')
);
getFileStub
.withArgs('Client2/composer.json', 'main')
.resolves(buildGitHubFileRaw('{"name": "google/client2"}'));
Expand Down Expand Up @@ -164,8 +166,15 @@ describe('PHPYoshi', () => {
);
const updates = release!.updates;
assertHasUpdate(updates, 'Client1/VERSION', DefaultUpdater);
assertHasUpdate(
updates,
'Client1/composer.json',
RootComposerUpdatePackages
);
assertHasUpdate(updates, 'Client2/VERSION', DefaultUpdater);
assertHasUpdate(updates, 'Client2/composer.json');
assertHasUpdate(updates, 'Client3/VERSION', DefaultUpdater);
assertHasUpdate(updates, 'Client3/composer.json');
assertHasUpdate(updates, 'Client3/src/Entry.php', PHPClientVersion);
});
it('ignores non client top level directories', async () => {
Expand Down Expand Up @@ -194,10 +203,41 @@ describe('PHPYoshi', () => {
);
const updates = release!.updates;
assertHasUpdate(updates, 'Client1/VERSION', DefaultUpdater);
assertHasUpdate(
updates,
'Client1/composer.json',
RootComposerUpdatePackages
);
assertHasUpdate(updates, 'Client2/VERSION', DefaultUpdater);
assertHasUpdate(updates, 'Client2/composer.json');
assertHasUpdate(updates, 'Client3/VERSION', DefaultUpdater);
assertHasUpdate(updates, 'Client3/composer.json');
assertHasUpdate(updates, 'Client3/src/Entry.php', PHPClientVersion);
});
it('updates component composer version', async () => {
const strategy = new PHPYoshi({
targetBranch: 'main',
github,
});
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
commits,
latestRelease
);
const updates = release!.updates;
assertHasUpdate(
updates,
'Client1/composer.json',
RootComposerUpdatePackages
);
const client1Composer = updates.find(update => {
return update.path === 'Client1/composer.json';
});
const newContent = client1Composer!.updater.updateContent(
'{"name":"google/client1","version":"1.2.3"}'
);
expect(newContent).to.eql('{"name":"google/client1","version":"1.2.4"}');
});
});
describe('buildRelease', () => {
it('parses the release notes', async () => {
Expand Down

0 comments on commit 32a972a

Please sign in to comment.