Package release: Handle new package validation (#39008)

This commit is contained in:
Paul Sealock 2023-06-29 13:28:19 +12:00 committed by GitHub
parent 55b2c67eda
commit b6b093225e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 9 deletions

View File

@ -3,7 +3,7 @@ on:
workflow_dispatch:
inputs:
packages:
description: 'Enter a specific package to release, or packages separated by commas, ie @woocommerce/components,@woocommerce/number. Leaving this input to the default "-a" will prepare to release all eligible packages. When releasing a package for the first time, pass the "--initialRelease" flag.'
description: 'Enter a specific package to release, or packages separated by commas, ie @woocommerce/components,@woocommerce/number. Leaving this input to the default "-a" will prepare to release all eligible packages.'
required: false
default: '-a'

View File

@ -2,6 +2,8 @@
When a package contains sufficient changes to justify a release to [NPM](https://www.npmjs.com/), follow these instructions to create a new release from the monorepo.
Below are instructions for releasing using Github Workflows (recommended) and the command line. When releasing packages for the first time, release from the command line.
## Release packages using Github Workflows (recommended)
### Prepare packages
@ -36,7 +38,7 @@ In order to prepare a package for release, a changelog will need to be compiled
./tools/package-release/bin/dev prepare -a
```
When making an initial release for a new package, pass the `--initialRelease` flag to signify a new release for a new package.
When making an initial release for a new package, pass the `--initial-release` flag to signify a new release for a new package.
2. Create a pull request with the resulting changes and merge it.
@ -48,6 +50,8 @@ See more about the prepare script using `./tools/package-release/bin/dev publish
2. Run the release script from monorepo root, first as a dry run.
When making an initial release for a new package, pass the `--initial-release` flag to signify a new release for a new package.
```
./tools/package-release/bin/dev publish -a --dry-run
```

View File

@ -49,7 +49,7 @@ export default class PackagePrepare extends Command {
default: false,
description: 'Perform prepare function on all packages.',
} ),
initialRelease: Flags.boolean( {
'initial-release': Flags.boolean( {
default: false,
description: "Create a package's first release to NPM",
} ),
@ -72,7 +72,7 @@ export default class PackagePrepare extends Command {
const packages = args.packages.split( ',' );
if ( flags.initialRelease && packages.length > 1 ) {
if ( flags[ 'initial-release' ] && packages.length > 1 ) {
this.error(
'Please release only a single package when making an initial release'
);
@ -82,7 +82,7 @@ export default class PackagePrepare extends Command {
validatePackage( name, ( e: string ): void => this.error( e ) )
);
await this.preparePackages( packages, flags.initialRelease );
await this.preparePackages( packages, flags[ 'initial-release' ] );
}
/**

View File

@ -59,6 +59,10 @@ export default class PackageRelease extends Command {
description: 'Skip pnpm install',
default: false,
} ),
'initial-release': Flags.boolean( {
default: false,
description: "Create a package's first release to NPM",
} ),
};
/**
@ -112,13 +116,17 @@ export default class PackageRelease extends Command {
*/
private publishPackages(
packages: Array< string >,
{ 'dry-run': dryRun, branch }: { 'dry-run': boolean; branch: string }
{
'dry-run': dryRun,
branch,
'initial-release': initialRelease,
}: { 'dry-run': boolean; branch: string; 'initial-release': boolean }
) {
packages.forEach( ( name ) => {
try {
const verb = dryRun ? 'Performing dry run of' : 'Publishing';
CliUx.ux.action.start( `${ verb } ${ name }` );
if ( isValidUpdate( name ) ) {
if ( isValidUpdate( name, initialRelease ) ) {
const cwd = getFilepathFromPackageName( name );
execSync(
`SKIP_TURBO=true pnpm publish ${

View File

@ -130,10 +130,14 @@ export const validatePackage = (
/**
* Determine if an update is valid by comparing version numbers.
*
* @param {string} name package name.
* @param {string} name package name.
* @param {boolean} initialRelease if package has not been released yet.
* @return {boolean} If an update is valid.
*/
export const isValidUpdate = ( name: string ): boolean => {
export const isValidUpdate = (
name: string,
initialRelease: boolean
): boolean => {
const packageJson = getPackageJson( name );
if ( ! packageJson ) {
@ -146,6 +150,10 @@ export const isValidUpdate = ( name: string ): boolean => {
return false;
}
if ( initialRelease ) {
return true;
}
const npmVersion = execSync( `pnpm view ${ name } version`, {
encoding: 'utf-8',
} );