Skip to content

Commit

Permalink
Merge branch 'add/release-script' into ttrunk
Browse files Browse the repository at this point in the history
# Conflicts:
#	scripts/release-create.mjs
  • Loading branch information
yscik committed Sep 11, 2023
2 parents 344d755 + 52790cc commit d877b37
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 45 deletions.
26 changes: 26 additions & 0 deletions scripts/RELEASE_PR_TEMPLATE.md.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default ( { changelog, version }) => `
> [!IMPORTANT]
> Merging this PR will build and publish the new version automatically as a GitHub release, then deploy the new version on the WordPress.org plugin repository.
>
## WP Job Manager ${version}
> [!NOTE]
> These release notes between the two \`---\` lines will be the final changelog entry for the release. Edit them freely here before merging.
>
### Release Notes
---
${ changelog }
---
### Release
> [!NOTE]
> Click 'Ready for Review', ping the team, review the PR and merge. Upon merging, automation will:
> - Write the release notes above to the changelog
> - Create and tag a new GitHub release
> - Deploy the release to WordPress.org
`;
30 changes: 16 additions & 14 deletions scripts/release-create.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,23 @@ const pluginName = pluginFileContents.match( /Plugin Name: (.*)/ )[ 1 ];

const prNumber = process.argv[ 3 ];

const releaseNotes = getReleaseChangelog();

const releaseNotes = getReleaseNotes();
updateChangelog();
commitChangelog();
tagRelease();
buildPluginZip();
createGithubRelease();
success();

function getReleaseNotes() {

console.log( chalk.bold.green( `✓ ${ pluginName } ${ pluginVersion } released!` ) );
console.log( `The GitHub release entry will trigger a deploy to WordPress.org. \nTrack here: https://github.com/${ plugin.repo }/actions/workflows/deploy-wporg-release.yml` );
execSync( ` open https://github.com/${ plugin.repo }/actions/workflows/deploy-wporg-release.yml` );

function getReleaseChangelog() {
// Get PR description
const prDescription = execSync( `gh pr view ${ prNumber } -R ${ plugin.repo } --json body` ).toString();
// Get changelog section
const changelogSection = prDescription.match( /### (?:Changelog|Release Notes)([\S\s]*?)(?:###|<!--)/ )[ 1 ]
.replace( /\\n/g, '\n' )
.replace( /\\r/g, '\r' )
const prDescription = JSON.parse( execSync( `gh pr view ${ prNumber } -R ${ plugin.repo } --json body` ).toString() ).body;
const releaseNotes = prDescription
.match( /### Release Notes\s*\n---([\S\s]*?)---/ )[ 1 ]
.replace( /^- /gm, '* ' )
.trim();

return changelogSection;
return releaseNotes;
}

function updateChangelog() {
Expand Down Expand Up @@ -101,3 +95,11 @@ function createGithubRelease() {
const notes = releaseNotes.replace( '"', '\\"' );
execSync( `gh release create ${ pluginVersion } -R ${ plugin.repo } --draft --title "Version ${ pluginVersion }" --notes "${ notes }" "${ pluginSlug }.zip"` );
}

function success() {
const deployWorkflow = `https://github.com/${ plugin.repo }/actions/workflows/deploy-wporg-release.yml`;
console.log( chalk.bold.green( `✓ ${ pluginName } ${ pluginVersion } released!` ) );
console.log( `The GitHub release entry will trigger a deploy to WordPress.org. \nTrack here: ${ deployWorkflow } ` );
execSync( `open ${ deployWorkflow }` );

}
37 changes: 6 additions & 31 deletions scripts/release-pr.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import process from 'process';
import inquirer from 'inquirer';
import chalk from 'chalk';
import { execSync } from 'child_process';
import prTemplate from './RELEASE_PR_TEMPLATE.md.mjs';

const PLUGINS = {
'wp-job-manager': {
Expand Down Expand Up @@ -136,13 +137,6 @@ async function askForConfirmation(
const currentWPTestedUpTo = fileContents.match( /Tested up to: (.*)/ )[ 1 ];
// PHP
const currentRequiresPhp = fileContents.match( /Requires PHP: (.*)/ )[ 1 ];
// WC
// const currentWCRequiresAtLeast = fileContents.match(
// /WC requires at least: (.*)/,
// )[ 1 ] ?? ' - ';
// const currentWCTestedUpTo = fileContents.match(
// /WC tested up to: (.*)/,
// )[ 1 ] ?? ' - ';

// Display all versioning information and ask for confirmation.
console.log( `🚀 Preparing new release:`, chalk.bold( `${ pluginSlug } ${ newVersion }` ) );
Expand All @@ -155,9 +149,10 @@ async function askForConfirmation(
console.log( `-----------------------------` );
console.log( `ℹ️️ Make sure a ` + chalk.bold( `milestone ${ newVersion }` ) + ` exists GitHub, and all PRs are assigned to the milestone.` );
console.log( `-----------------------------` );
console.log( `ℹ️️ Make sure you are logged in to GH CLI with \`gh auth login\`.` );
execSync( 'gh auth status' );
console.log( `-----------------------------` );
console.log( `Pull requests to include:` );
console.log( `Pull requests to include (milestone ${ newVersion }):` );

execSync( ghPrs, { stdio: 'inherit' } );

Expand All @@ -166,6 +161,8 @@ async function askForConfirmation(
const defaultBranch = 'trunk';
const warning = ( branch !== defaultBranch ) ? chalk.bgRed( ` ‼️ Not ${ defaultBranch }! ‼️ ` ) : '';

console.log( `-----------------------------` );

console.log( 'Branch:', chalk.bold[ branch !== defaultBranch ? 'red' : 'green' ]( branch ), warning );

console.log( `-----------------------------` );
Expand Down Expand Up @@ -317,29 +314,7 @@ function createPR( changelog ) {

const title = `Release ${ pluginName } ${ version }`;

let body = `
### Release Notes
${ changelog }
### Hooks, templates
...
### Release Automation
- [ ] 🤖 Plugin zip built.
- [ ] 🤖 New version deployed at test site.
- [ ] 🤠 Merge PR.
- [ ] 🤖 GH release tag created.
- [ ] 🤖 Plugin pushed to WordPress.org
- [ ] 🤖 WPJobManager.com release created.
- [ ] 🤖 P2 release post created.
⚠️ Merging this PR will publish the new release automatically.
`;
let body = prTemplate( { changelog, version } );
body = body.replace( '"', '\"' );

const prLink = execSync( `gh pr create -R ${ plugin.repo } -B trunk -H ${ releaseBranch } --assignee @me --base trunk --draft --title "${ title }" --body "${ body }"` );
Expand Down

0 comments on commit d877b37

Please sign in to comment.