Code Freeze CLI: Replace PHP script with TS (#38233)

This commit is contained in:
Paul Sealock 2023-05-16 10:33:53 +12:00 committed by GitHub
parent 06006619b3
commit e860e1f21f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 11 deletions

View File

@ -8686,9 +8686,9 @@ packages:
'@babel/core': 7.21.3
'@babel/helper-annotate-as-pure': 7.16.7
'@babel/helper-module-imports': 7.16.7
'@babel/helper-plugin-utils': 7.20.2
'@babel/helper-plugin-utils': 7.18.9
'@babel/plugin-syntax-jsx': 7.16.7(@babel/core@7.21.3)
'@babel/types': 7.21.3
'@babel/types': 7.17.0
dev: true
/@babel/plugin-transform-react-jsx@7.19.0(@babel/core@7.12.9):
@ -20812,8 +20812,8 @@ packages:
peerDependencies:
postcss: ^8.1.0
dependencies:
browserslist: 4.21.4
caniuse-lite: 1.0.30001418
browserslist: 4.20.2
caniuse-lite: 1.0.30001352
fraction.js: 4.2.0
normalize-range: 0.1.2
picocolors: 1.0.0
@ -22356,7 +22356,6 @@ packages:
escalade: 3.1.1
node-releases: 2.0.6
picocolors: 1.0.0
dev: true
/browserslist@4.20.4:
resolution: {integrity: sha512-ok1d+1WpnU24XYN7oC3QWgTyMhY/avPJ/r9T00xxvUOIparA/gc+UPUMaod3i+G6s+nI2nUb9xZ5k794uIwShw==}

View File

@ -13,7 +13,7 @@ import { updateTrunkChangelog, updateReleaseBranchChangelogs } from './lib';
import { Options } from './types';
export const changelogCommand = new Command( 'changelog' )
.description( 'Create a new release branch' )
.description( 'Make changelog pull requests to trunk and release branch' )
.option(
'-o --owner <owner>',
'Repository owner. Default: woocommerce',
@ -28,6 +28,11 @@ export const changelogCommand = new Command( 'changelog' )
'-d --dev-repo-path <devRepoPath>',
'Path to existing repo. Use this option to avoid cloning a fresh repo for development purposes. Note that using this option assumes dependencies are already installed.'
)
.option(
'-o, --override <override>',
"Time Override: The time to use in checking whether the action should run (default: 'now').",
'now'
)
.requiredOption( '-v, --version <version>', 'Version to bump to' )
.action( async ( options: Options ) => {
const { owner, name, version, devRepoPath } = options;

View File

@ -3,6 +3,8 @@
*/
import simpleGit from 'simple-git';
import { execSync } from 'child_process';
import { readFile, writeFile } from 'fs/promises';
import path from 'path';
/**
* Internal dependencies
@ -11,6 +13,58 @@ import { Logger } from '../../../../core/logger';
import { checkoutRemoteBranch } from '../../../../core/git';
import { createPullRequest } from '../../../../core/github/repo';
import { Options } from '../types';
import { getToday } from '../../verify-day/utils';
/**
* Perform changelog adjustments after Jetpack Changelogger has run.
*
* @param {string} override Time override.
* @param {string} tmpRepoPath Path where the temporary repo is cloned.
*/
const updateReleaseChangelogs = async (
override: string,
tmpRepoPath: string
) => {
const today = getToday( override );
// The release date is 22 days after the code freeze.
const releaseTime = new Date( today.getTime() + 22 * 24 * 60 * 60 * 1000 );
const releaseDate = releaseTime.toISOString().split( 'T' )[ 0 ];
const readmeFile = path.join(
tmpRepoPath,
'plugins',
'woocommerce',
'readme.txt'
);
const nextLogFile = path.join(
tmpRepoPath,
'plugins',
'woocommerce',
'NEXT_CHANGELOG.md'
);
let readme = await readFile( readmeFile, 'utf-8' );
let nextLog = await readFile( nextLogFile, 'utf-8' );
nextLog = nextLog.replace(
/= (\d+\.\d+\.\d+) YYYY-mm-dd =/,
`= $1 ${ releaseDate } =`
);
// Convert PR number to markdown link.
nextLog = nextLog.replace(
/\[#(\d+)\]/g,
'[$&](https://github.com/woocommerce/woocommerce/pull/$1)'
);
readme = readme.replace(
/== Changelog ==\n(.*?)\[See changelog for all versions\]/s,
`== Changelog ==\n\n${ nextLog }\n\n[See changelog for all versions]`
);
await writeFile( readmeFile, readme );
};
/**
* Perform changelog operations on release branch by submitting a pull request. The release branch is a remote branch.
@ -67,10 +121,7 @@ export const updateReleaseBranchChangelogs = async (
Logger.notice( `git deletion hash: ${ deletionCommitHash }` );
Logger.notice( `Updating readme.txt in ${ tmpRepoPath }` );
execSync( 'php .github/workflows/scripts/release-changelog.php', {
cwd: tmpRepoPath,
stdio: 'inherit',
} );
await updateReleaseChangelogs( options.override, tmpRepoPath );
Logger.notice(
`Committing readme.txt changes in ${ branch } on ${ tmpRepoPath }`

View File

@ -3,4 +3,5 @@ export type Options = {
name: string;
version: string;
devRepoPath?: string;
override: string;
};

View File

@ -20,7 +20,8 @@ export const verifyDayCommand = new Command( 'verify-day' )
.description( 'Verify if today is the code freeze day' )
.option(
'-o, --override <override>',
"Time Override: The time to use in checking whether the action should run (default: 'now')."
"Time Override: The time to use in checking whether the action should run (default: 'now').",
'now'
)
.action( ( { override } ) => {
const today = getToday( override );