Skip to content

Commit

Permalink
Add changelog.txt and readme.txt to GitHub repository (#18828)
Browse files Browse the repository at this point in the history
* Added the files

* Update build and release tools

* Use placeholder on readme.

* Implement the stable placeholder on Github logic
  • Loading branch information
jorgefilipecosta committed Dec 9, 2019
1 parent 8647dbf commit 992a9d4
Show file tree
Hide file tree
Showing 4 changed files with 6,036 additions and 32 deletions.
2 changes: 2 additions & 0 deletions bin/build-plugin-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ zip -r gutenberg.zip \
post-content.php \
$vendor_scripts \
$build_files \
readme.txt \
changelog.txt \
README.md

# Reset `gutenberg.php`.
Expand Down
88 changes: 56 additions & 32 deletions bin/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const warning = chalk.bold.keyword( 'orange' );
const success = chalk.bold.green;

// Utils
const STABLE_TAG_REGEX = /Stable tag: [0-9]+\.[0-9]+\.[0-9]+\s*\n/;
const STABLE_TAG_PLACEHOLDER = 'Stable tag: V.V.V\n';

/**
* Small utility used to read an uncached version of a JSON file
Expand Down Expand Up @@ -145,33 +147,24 @@ async function runUpdateTrunkContentStep( version, changelog, abortMessage ) {
await runStep( 'Updating trunk content', abortMessage, async () => {
console.log( '>> Replacing trunk content using the new plugin ZIP' );

// Delete everything except readme.txt and changelog.txt
runShellScript( 'find . -maxdepth 1 -not -name "changelog.txt" -not -name "readme.txt" -not -name ".svn" -not -name "." -not -name ".." -exec rm -rf {} +', svnWorkingDirectoryPath );
const readmePath = svnWorkingDirectoryPath + '/readme.txt';

const previousReadmeFileContent = fs.readFileSync( readmePath, 'utf8' );
const stableTag = previousReadmeFileContent.match( STABLE_TAG_REGEX )[ 0 ];

// Delete everything
runShellScript( 'find . -maxdepth 1 -not -name ".svn" -not -name "." -not -name ".." -exec rm -rf {} +', svnWorkingDirectoryPath );

// Update the content using the plugin ZIP
const gutenbergZipPath = gitWorkingDirectoryPath + '/gutenberg.zip';
runShellScript( 'unzip ' + gutenbergZipPath + ' -d ' + svnWorkingDirectoryPath );

console.log( '>> Updating the changelog in readme.txt and changelog.txt' );

// Update the content of the readme.txt file
const readmePath = svnWorkingDirectoryPath + '/readme.txt';
const readmeFileContent = fs.readFileSync( readmePath, 'utf8' );
const newReadmeContent =
readmeFileContent.substr( 0, readmeFileContent.indexOf( '== Changelog ==' ) ) +
'== Changelog ==\n\n' +
changelog + '\n';
fs.writeFileSync( readmePath, newReadmeContent );

// Update the content of the changelog.txt file
const changelogPath = svnWorkingDirectoryPath + '/changelog.txt';
const changelogFileContent = fs.readFileSync( changelogPath, 'utf8' );
const newChangelogContent =
'== Changelog ==\n\n' +
'= ' + version + ' =\n\n' +
changelog +
changelogFileContent.substr( changelogFileContent.indexOf( '== Changelog ==' ) + 16 );
fs.writeFileSync( changelogPath, newChangelogContent );
// Replace the stable tag placeholder with the existing stable tag on the SVN repository.
const newReadmeFileContent = fs.readFileSync( readmePath, 'utf8' );
fs.writeFileSync(
readmePath,
newReadmeFileContent.replace( STABLE_TAG_PLACEHOLDER, stableTag )
);

// Commit the content changes
runShellScript( "svn st | grep '^\?' | awk '{print $2}' | xargs svn add", svnWorkingDirectoryPath );
Expand Down Expand Up @@ -219,7 +212,7 @@ async function updateThePluginStableVersion( version, abortMessage ) {
const readmePath = svnWorkingDirectoryPath + '/readme.txt';
const readmeFileContent = fs.readFileSync( readmePath, 'utf8' );
const newReadmeContent = readmeFileContent.replace(
/Stable tag: [0-9]+.[0-9]+.[0-9]+\s*\n/,
STABLE_TAG_REGEX,
'Stable tag: ' + version + '\n'
);
fs.writeFileSync( readmePath, newReadmeContent );
Expand Down Expand Up @@ -342,11 +335,12 @@ async function runReleaseBranchCheckoutStep( abortMessage ) {
* and commit the changes.
*
* @param {string} version Version to use.
* @param {string} changelog Changelog to use.
* @param {string} abortMessage Abort message.
*
* @return {string} hash of the version bump commit.
*/
async function runBumpPluginVersionAndCommitStep( version, abortMessage ) {
async function runBumpPluginVersionAndCommitStep( version, changelog, abortMessage ) {
let commitHash;
await runStep( 'Updating the plugin version', abortMessage, async () => {
const simpleGit = SimpleGit( gitWorkingDirectoryPath );
Expand All @@ -369,6 +363,32 @@ async function runBumpPluginVersionAndCommitStep( version, abortMessage ) {
fs.writeFileSync( pluginFilePath, content.replace( ' * Version: ' + packageJson.version, ' * Version: ' + version ) );
console.log( '>> The plugin version has been updated successfully.' );

// Update the content of the readme.txt file
const readmePath = gitWorkingDirectoryPath + '/readme.txt';
const readmeFileContent = fs.readFileSync( readmePath, 'utf8' );
const newReadmeContent =
readmeFileContent.substr( 0, readmeFileContent.indexOf( '== Changelog ==' ) ) +
'== Changelog ==\n\n' +
changelog + '\n';
fs.writeFileSync( readmePath, newReadmeContent );

// Update the content of the changelog.txt file
const stableVersion = version.match( /[0-9]+\.[0-9]+\.[0-9]+/ )[ 0 ];
const changelogPath = gitWorkingDirectoryPath + '/changelog.txt';
const changelogFileContent = fs.readFileSync( changelogPath, 'utf8' );
const versionHeader = '= ' + version + ' =\n\n';
const regexToSearch = /=\s([0-9]+\.[0-9]+\.[0-9]+)(-rc\.[0-9]+)?\s=\n\n/g;
let lastDifferentVersionMatch = regexToSearch.exec( changelogFileContent );
if ( lastDifferentVersionMatch[ 1 ] === stableVersion ) {
lastDifferentVersionMatch = regexToSearch.exec( changelogFileContent );
}
const newChangelogContent =
'== Changelog ==\n\n' +
versionHeader +
changelog + '\n\n' +
changelogFileContent.substr( lastDifferentVersionMatch.index );
fs.writeFileSync( changelogPath, newChangelogContent );

// Commit the version bump
await askForConfirmationToContinue(
'Please check the diff. Proceed with the version bump commit?',
Expand All @@ -379,6 +399,8 @@ async function runBumpPluginVersionAndCommitStep( version, abortMessage ) {
packageJsonPath,
packageLockPath,
pluginFilePath,
readmePath,
changelogPath,
] );
const commitData = await simpleGit.commit( 'Bump plugin version to ' + version );
commitHash = commitData.commit;
Expand Down Expand Up @@ -450,12 +472,13 @@ async function runPushGitChangesStep( releaseBranch, abortMessage ) {
*
* @param {string} version Released version.
* @param {string} versionLabel Label of the released Version.
* @param {string} changelog Release changelog.
* @param {boolean} isPrerelease is a pre-release.
* @param {string} abortMessage Abort message.
*
* @return {Object} Github release object.
*/
async function runGithubReleaseStep( version, versionLabel, isPrerelease, abortMessage ) {
async function runGithubReleaseStep( version, versionLabel, changelog, isPrerelease, abortMessage ) {
let octokit;
let release;
await runStep( 'Creating the GitHub release', abortMessage, async () => {
Expand All @@ -464,11 +487,6 @@ async function runGithubReleaseStep( version, versionLabel, isPrerelease, abortM
true,
abortMessage
);
const { changelog } = await inquirer.prompt( [ {
type: 'editor',
name: 'changelog',
message: 'Please provide the CHANGELOG of the release (markdown)',
} ] );

const { token } = await inquirer.prompt( [ {
type: 'input',
Expand Down Expand Up @@ -550,6 +568,12 @@ async function releasePlugin( isRC = true ) {
let abortMessage = 'Aborting!';
await askForConfirmationToContinue( 'Ready to go? ' );

const { changelog } = await inquirer.prompt( [ {
type: 'editor',
name: 'changelog',
message: 'Please provide the CHANGELOG of the release (markdown)',
} ] );

// Cloning the Git repository
await runGitRepositoryCloneStep( abortMessage );

Expand All @@ -559,7 +583,7 @@ async function releasePlugin( isRC = true ) {
await runReleaseBranchCheckoutStep( abortMessage );

// Bumping the version and commit.
const commitHash = await runBumpPluginVersionAndCommitStep( version, abortMessage );
const commitHash = await runBumpPluginVersionAndCommitStep( version, changelog, abortMessage );

// Plugin ZIP creation
await runPluginZIPCreationStep();
Expand All @@ -572,7 +596,7 @@ async function releasePlugin( isRC = true ) {
abortMessage = 'Aborting! Make sure to ' + isRC ? 'remove' : 'reset' + ' the remote release branch and remove the git tag.';

// Creating the GitHub Release
const release = await runGithubReleaseStep( version, versionLabel, isRC, abortMessage );
const release = await runGithubReleaseStep( version, versionLabel, changelog, isRC, abortMessage );
abortMessage = 'Aborting! Make sure to manually cherry-pick the ' + success( commitHash ) + ' commit to the master branch.';
if ( ! isRC ) {
abortMessage += ' Make sure to perform the SVN release manually as well.';
Expand Down
Loading

0 comments on commit 992a9d4

Please sign in to comment.