Skip to content

Commit 32a972a

Browse files
bshafferchingor13
andauthored
fix(php-yoshi): do not add version to root version map (#2199)
* fix: do not add version to root version map * add versionmap for directories * add test case * chore: fix lint --------- Co-authored-by: Jeff Ching <[email protected]>
1 parent 03e12ef commit 32a972a

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/strategies/php-yoshi.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ export class PHPYoshi extends BaseStrategy {
114114
splitCommits[directory]
115115
);
116116
versionsMap.set(composer.name, newVersion);
117-
versionsMap.set('version', newVersion);
118117
const partialReleaseNotes = await this.changelogNotes.buildNotes(
119118
splitCommits[directory],
120119
{
@@ -173,6 +172,16 @@ export class PHPYoshi extends BaseStrategy {
173172
version,
174173
}),
175174
});
175+
const directoryVersion: VersionsMap = new Map();
176+
directoryVersion.set('version', version);
177+
updates.push({
178+
path: this.addPath(`${directory}/composer.json`),
179+
createIfMissing: false,
180+
updater: new RootComposerUpdatePackages({
181+
version,
182+
versionsMap: directoryVersion,
183+
}),
184+
});
176185
if (componentInfo.composer.extra?.component?.entry) {
177186
updates.push({
178187
path: this.addPath(

test/strategies/php-yoshi.ts

+41-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ describe('PHPYoshi', () => {
6464
.resolves(buildGitHubFileRaw('0.1.2'));
6565
getFileStub
6666
.withArgs('Client1/composer.json', 'main')
67-
.resolves(buildGitHubFileRaw('{"name": "google/client1"}'));
67+
.resolves(
68+
buildGitHubFileRaw('{"name": "google/client1", "version": "1.2.3"}')
69+
);
6870
getFileStub
6971
.withArgs('Client2/composer.json', 'main')
7072
.resolves(buildGitHubFileRaw('{"name": "google/client2"}'));
@@ -164,8 +166,15 @@ describe('PHPYoshi', () => {
164166
);
165167
const updates = release!.updates;
166168
assertHasUpdate(updates, 'Client1/VERSION', DefaultUpdater);
169+
assertHasUpdate(
170+
updates,
171+
'Client1/composer.json',
172+
RootComposerUpdatePackages
173+
);
167174
assertHasUpdate(updates, 'Client2/VERSION', DefaultUpdater);
175+
assertHasUpdate(updates, 'Client2/composer.json');
168176
assertHasUpdate(updates, 'Client3/VERSION', DefaultUpdater);
177+
assertHasUpdate(updates, 'Client3/composer.json');
169178
assertHasUpdate(updates, 'Client3/src/Entry.php', PHPClientVersion);
170179
});
171180
it('ignores non client top level directories', async () => {
@@ -194,10 +203,41 @@ describe('PHPYoshi', () => {
194203
);
195204
const updates = release!.updates;
196205
assertHasUpdate(updates, 'Client1/VERSION', DefaultUpdater);
206+
assertHasUpdate(
207+
updates,
208+
'Client1/composer.json',
209+
RootComposerUpdatePackages
210+
);
197211
assertHasUpdate(updates, 'Client2/VERSION', DefaultUpdater);
212+
assertHasUpdate(updates, 'Client2/composer.json');
198213
assertHasUpdate(updates, 'Client3/VERSION', DefaultUpdater);
214+
assertHasUpdate(updates, 'Client3/composer.json');
199215
assertHasUpdate(updates, 'Client3/src/Entry.php', PHPClientVersion);
200216
});
217+
it('updates component composer version', async () => {
218+
const strategy = new PHPYoshi({
219+
targetBranch: 'main',
220+
github,
221+
});
222+
const latestRelease = undefined;
223+
const release = await strategy.buildReleasePullRequest(
224+
commits,
225+
latestRelease
226+
);
227+
const updates = release!.updates;
228+
assertHasUpdate(
229+
updates,
230+
'Client1/composer.json',
231+
RootComposerUpdatePackages
232+
);
233+
const client1Composer = updates.find(update => {
234+
return update.path === 'Client1/composer.json';
235+
});
236+
const newContent = client1Composer!.updater.updateContent(
237+
'{"name":"google/client1","version":"1.2.3"}'
238+
);
239+
expect(newContent).to.eql('{"name":"google/client1","version":"1.2.4"}');
240+
});
201241
});
202242
describe('buildRelease', () => {
203243
it('parses the release notes', async () => {

0 commit comments

Comments
 (0)