Skip to content

Commit b9849ba

Browse files
committed
prep build 02/22
2 parents ce15df2 + 8c3ca76 commit b9849ba

File tree

163 files changed

+2887
-1835
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+2887
-1835
lines changed

bin/plugin/commands/changelog.js

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,7 @@ function getEntry( issue ) {
541541
title,
542542
issue.number,
543543
issue.html_url
544-
) +
545-
' - @' +
546-
issue.user.login;
544+
);
547545
}
548546

549547
/**
@@ -683,7 +681,10 @@ async function fetchAllPullRequests( octokit, settings ) {
683681
function getChangelog( pullRequests ) {
684682
let changelog = '## Changelog\n\n';
685683

686-
const groupedPullRequests = groupBy( pullRequests, getIssueType );
684+
const groupedPullRequests = groupBy(
685+
skipCreatedByBots( pullRequests ),
686+
getIssueType
687+
);
687688

688689
const sortedGroups = Object.keys( groupedPullRequests ).sort( sortGroup );
689690

@@ -781,10 +782,6 @@ function sortFeatureGroups( featureGroups ) {
781782
*/
782783
function getFirstTimeContributorPRs( pullRequests ) {
783784
return pullRequests.filter( ( pr ) => {
784-
if ( pr.user.type.toLowerCase() === 'bot' ) {
785-
return false;
786-
}
787-
788785
return pr.labels.find(
789786
( { name } ) => name.toLowerCase() === 'first-time contributor'
790787
);
@@ -799,7 +796,7 @@ function getFirstTimeContributorPRs( pullRequests ) {
799796
*
800797
* @return {string} The formatted markdown list of contributors and their PRs.
801798
*/
802-
function getContributorMarkdownList( ftcPRs ) {
799+
function getContributorPropsMarkdownList( ftcPRs ) {
803800
return ftcPRs.reduce( ( markdownList, pr ) => {
804801
const title = getNormalizedTitle( pr.title, pr ) || '';
805802

@@ -822,7 +819,7 @@ function getContributorMarkdownList( ftcPRs ) {
822819
* @return {IssuesListForRepoResponseItem[]} The sorted list of pull requests.
823820
*/
824821
function sortByUsername( items ) {
825-
return sortBy( items, ( item ) => item.user.login );
822+
return sortBy( items, ( item ) => item.user.login.toLowerCase() );
826823
}
827824

828825
/**
@@ -836,19 +833,32 @@ function getUniqueByUsername( items ) {
836833
}
837834

838835
/**
839-
* Produces the formatted markdown for the full time contributors section of
840-
* the changelog output.
836+
* Excludes users who should not be included in the changelog.
837+
* Typically this is "bot" users.
838+
*
839+
* @param {IssuesListForRepoResponseItem[]} pullRequests List of pull requests.
840+
* @return {IssuesListForRepoResponseItem[]} The list of filtered pull requests.
841+
*/
842+
function skipCreatedByBots( pullRequests ) {
843+
return pullRequests.filter(
844+
( pr ) => pr.user.type.toLowerCase() !== 'bot'
845+
);
846+
}
847+
848+
/**
849+
* Produces the formatted markdown for the contributor props seciton.
841850
*
842851
* @param {IssuesListForRepoResponseItem[]} pullRequests List of pull requests.
843852
*
844-
* @return {string} The formatted contributors section.
853+
* @return {string} The formatted props section.
845854
*/
846-
function getContributors( pullRequests ) {
855+
function getContributorProps( pullRequests ) {
847856
const contributorsList = flow( [
857+
skipCreatedByBots,
848858
getFirstTimeContributorPRs,
849859
getUniqueByUsername,
850860
sortByUsername,
851-
getContributorMarkdownList,
861+
getContributorPropsMarkdownList,
852862
] )( pullRequests );
853863

854864
return (
@@ -860,6 +870,46 @@ function getContributors( pullRequests ) {
860870
);
861871
}
862872

873+
/**
874+
*
875+
* @param {IssuesListForRepoResponseItem[]} pullRequests List of first time contributor PRs.
876+
* @return {string} The formatted markdown list of contributor usernames.
877+
*/
878+
function getContributorsMarkdownList( pullRequests ) {
879+
return pullRequests
880+
.reduce( ( markdownList = '', pr ) => {
881+
markdownList += ` @${ pr.user.login }`;
882+
return markdownList;
883+
}, '' )
884+
.trim();
885+
}
886+
887+
/**
888+
* Produces the formatted markdown for the full time contributors section of
889+
* the changelog output.
890+
*
891+
* @param {IssuesListForRepoResponseItem[]} pullRequests List of pull requests.
892+
*
893+
* @return {string} The formatted contributors section.
894+
*/
895+
function getContributorsList( pullRequests ) {
896+
const contributorsList = flow( [
897+
skipCreatedByBots,
898+
getUniqueByUsername,
899+
sortByUsername,
900+
getContributorsMarkdownList,
901+
] )( pullRequests );
902+
903+
return (
904+
'\n\n' +
905+
'## Contributors' +
906+
'\n\n' +
907+
'The following contributors merged PRs in this release:' +
908+
'\n\n' +
909+
contributorsList
910+
);
911+
}
912+
863913
/**
864914
* Generates and logs changelog for a milestone.
865915
*
@@ -882,9 +932,14 @@ async function createChangelog( settings ) {
882932
const pullRequests = await fetchAllPullRequests( octokit, settings );
883933

884934
const changelog = getChangelog( pullRequests );
885-
const contributors = getContributors( pullRequests );
935+
const contributorProps = getContributorProps( pullRequests );
936+
const contributorsList = getContributorsList( pullRequests );
886937

887-
releaselog = releaselog.concat( changelog, contributors );
938+
releaselog = releaselog.concat(
939+
changelog,
940+
contributorProps,
941+
contributorsList
942+
);
888943
} catch ( error ) {
889944
if ( error instanceof Error ) {
890945
releaselog = formats.error( error.stack );
@@ -935,7 +990,9 @@ async function getReleaseChangelog( options ) {
935990
getTypesByLabels,
936991
getTypesByTitle,
937992
getFormattedItemDescription,
938-
getContributors,
993+
getContributorProps,
994+
getContributorsList,
939995
getChangelog,
940996
getUniqueByUsername,
997+
skipCreatedByBots,
941998
};

bin/plugin/commands/packages.js

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ async function runWordPressReleaseBranchSyncStep(
111111
* @param {SemVer} minimumVersionBump Minimum version bump for the packages.
112112
* @param {ReleaseType} releaseType Release type selected from CLI.
113113
* @param {string} abortMessage Abort Message.
114+
*
115+
* @return {?string} The optional commit's hash when changelog files updated.
114116
*/
115117
async function updatePackages(
116118
gitWorkingDirectoryPath,
@@ -251,8 +253,14 @@ async function updatePackages(
251253
true,
252254
abortMessage
253255
);
254-
git.commit( gitWorkingDirectoryPath, 'Update changelog files', [ './*' ] );
256+
const commitHash = await git.commit(
257+
gitWorkingDirectoryPath,
258+
'Update changelog files',
259+
[ './*' ]
260+
);
255261
log( '>> Changelog files changes have been committed successfully.' );
262+
263+
return commitHash;
256264
}
257265

258266
/**
@@ -283,6 +291,8 @@ async function runPushGitChangesStep(
283291
* @param {string} gitWorkingDirectoryPath Git working directory path.
284292
* @param {SemVer} minimumVersionBump Minimum version bump for the packages.
285293
* @param {ReleaseType} releaseType Release type selected from CLI.
294+
*
295+
* @return {?string} The optional commit's hash when changelog files updated.
286296
*/
287297
async function publishPackagesToNpm(
288298
gitWorkingDirectoryPath,
@@ -298,9 +308,11 @@ async function publishPackagesToNpm(
298308
log(
299309
'>> Bumping version of public packages changed since the last release.'
300310
);
301-
const { stdout: sha } = await command( 'git rev-parse --short HEAD' );
311+
const commitHash = await git.getLastCommitHash(
312+
gitWorkingDirectoryPath
313+
);
302314
await command(
303-
`npx lerna version pre${ minimumVersionBump } --preid next.${ sha } --no-private`,
315+
`npx lerna version pre${ minimumVersionBump } --preid next.${ commitHash } --no-private`,
304316
{
305317
cwd: gitWorkingDirectoryPath,
306318
stdio: 'inherit',
@@ -336,6 +348,39 @@ async function publishPackagesToNpm(
336348
stdio: 'inherit',
337349
} );
338350
}
351+
352+
return await git.getLastCommitHash( gitWorkingDirectoryPath );
353+
}
354+
355+
/**
356+
* Backports commits from the release branch to the `trunk` branch.
357+
*
358+
* @param {string} gitWorkingDirectoryPath Git working directory path.
359+
* @param {ReleaseType} releaseType Release type selected from CLI.
360+
* @param {string[]} commits The list of commits to backport.
361+
*
362+
*/
363+
async function backportCommitsToTrunk(
364+
gitWorkingDirectoryPath,
365+
releaseType,
366+
commits
367+
) {
368+
if (
369+
! [ 'latest', 'bugfix' ].includes( releaseType ) ||
370+
commits.length === 0
371+
) {
372+
return;
373+
}
374+
375+
log( '>> Backporting commits.' );
376+
await git.resetLocalBranchAgainstOrigin( gitWorkingDirectoryPath, 'trunk' );
377+
for ( const commitHash of commits ) {
378+
await git.cherrypickCommitIntoBranch(
379+
gitWorkingDirectoryPath,
380+
commitHash
381+
);
382+
}
383+
await git.pushBranchToOrigin( gitWorkingDirectoryPath, 'trunk' );
339384
}
340385

341386
/**
@@ -369,7 +414,7 @@ async function prepareForPackageRelease(
369414
abortMessage
370415
);
371416

372-
await updatePackages(
417+
const commitHashChangelogUpdates = await updatePackages(
373418
gitWorkingDirectoryPath,
374419
minimumVersionBump,
375420
releaseType,
@@ -382,12 +427,18 @@ async function prepareForPackageRelease(
382427
`Aborting! Make sure to push changes applied to WordPress release branch "${ releaseBranch }" manually.`
383428
);
384429

385-
await publishPackagesToNpm(
430+
const commitHashNpmPublish = await publishPackagesToNpm(
386431
gitWorkingDirectoryPath,
387432
minimumVersionBump,
388433
releaseType
389434
);
390435

436+
await backportCommitsToTrunk(
437+
gitWorkingDirectoryPath,
438+
releaseType,
439+
[ commitHashChangelogUpdates, commitHashNpmPublish ].filter( Boolean )
440+
);
441+
391442
await runCleanLocalFoldersStep( temporaryFolders, 'Cleaning failed.' );
392443
}
393444

@@ -417,10 +468,7 @@ async function publishNpmLatestDistTag() {
417468

418469
log(
419470
'\n>> 🎉 WordPress packages are now published!\n\n',
420-
'Please remember to run `git cherry-pick` in the `trunk` branch for the newly created commits during the release with labels:\n',
421-
' - Update changelog files (if exists)\n',
422-
' - chore(release): publish\n\n',
423-
'Finally, let also people know on WordPress Slack and celebrate together.'
471+
'Let also people know on WordPress Slack and celebrate together.'
424472
);
425473
}
426474

@@ -439,15 +487,12 @@ async function publishNpmBugfixLatestDistTag() {
439487
await prepareForPackageRelease(
440488
'bugfix',
441489
'patch',
442-
'Before we proceed, can you confirm that all required changes have beed already cherry-picked to the release branch?'
490+
'Before we proceed, can you confirm that all required changes have been already cherry-picked to the release branch?'
443491
);
444492

445493
log(
446494
'\n>> 🎉 WordPress packages are now published!\n\n',
447-
'Please remember to run `git cherry-pick` in the `trunk` branch for the newly created commits during the release with labels:\n',
448-
' - Update changelog files (if exists)\n',
449-
' - chore(release): publish\n\n',
450-
'Finally, let also people know on WordPress Slack and celebrate together.'
495+
'Let also people know on WordPress Slack and celebrate together.'
451496
);
452497
}
453498

0 commit comments

Comments
 (0)