Code Freeze CLI: Remove old version bump tool (#38182)

* remove old tool

* remove from pnpm-workspace.yaml
This commit is contained in:
Paul Sealock 2023-05-12 09:15:03 +12:00 committed by GitHub
parent 345cca1e09
commit 36d4ad1150
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 0 additions and 375 deletions

View File

@ -8,6 +8,5 @@ packages:
- 'tools/package-release'
- 'tools/cherry-pick'
- 'tools/release-posts'
- 'tools/version-bump'
- 'tools/storybook'
- 'tools/monorepo-utils'

View File

@ -1,3 +0,0 @@
{
"extends": [ "plugin:@woocommerce/eslint-plugin/recommended" ]
}

View File

@ -1,26 +0,0 @@
# Version Bump
## Description
`version-bump` is a CLI tool to bump versions in plugins found in the Monorepo.
## Usage
Bump WooCommerce to version 7.1.0:
```
pnpm --filter version-bump run version bump woocommerce -v 7.1.0
```
**Arguments**:
plugin - Monorepo plugin
**Options**:
-v, --version <string> Version to bump to
-h, --help display help for command
### Prereleases
Prerelease versions such as `7.3.0-dev` and `7.5.0-beta.1` are acceptable.
When updating with a `-dev` prerelease suffix, the tool will not update the stable tag but will update the readme changelog to prepare for the next release cycle.

View File

@ -1,54 +0,0 @@
/**
* External dependencies
*/
import { prerelease } from 'semver';
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
/**
* Internal dependencies
*/
import { program } from '../program';
import { validateArgs, stripPrereleaseParameters } from '../lib/validate';
import {
updatePluginFile,
updateReadmeChangelog,
updateJSON,
updateClassPluginFile,
updateReadmeStableTag,
} from '../lib/update';
program
.command( 'bump' )
.description( 'CLI to automate version bumping.' )
.argument( '<plugin>', 'Monorepo plugin' )
.requiredOption( '-v, --version <string>', 'Version to bump to' )
.action( async ( plugin: string, options ) => {
Logger.startTask( `Bumping versions to ${ options.version }` );
await validateArgs( plugin, options );
let nextVersion = options.version;
const prereleaseParameters = prerelease( nextVersion );
const isDevVersionBump =
prereleaseParameters && prereleaseParameters[ 0 ] === 'dev';
await updatePluginFile( plugin, nextVersion );
// Any updated files besides the plugin file get a version stripped of prerelease parameters.
nextVersion = stripPrereleaseParameters( nextVersion );
if ( isDevVersionBump ) {
// Bumping the dev version means updating the readme's changelog.
await updateReadmeChangelog( plugin, nextVersion );
} else {
// Only update stable tag on real releases.
await updateReadmeStableTag( plugin, nextVersion );
}
await updateJSON( 'composer', plugin, nextVersion );
await updateJSON( 'package', plugin, nextVersion );
await updateClassPluginFile( plugin, nextVersion );
Logger.endTask();
} );

View File

@ -1,8 +0,0 @@
/**
* Internal dependencies
*/
import { program } from './program';
import './commands/bump';
// Start the program
program.parse();

View File

@ -1,7 +0,0 @@
/**
* External dependencies
*/
import { dirname } from 'path';
// Escape from ./tools/package-release/src
export const MONOREPO_ROOT = dirname( dirname( dirname( __dirname ) ) );

View File

@ -1,152 +0,0 @@
/**
* External dependencies
*/
import { readFile, writeFile, stat } from 'fs/promises';
import { join } from 'path';
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
/**
* Internal dependencies
*/
import { MONOREPO_ROOT } from './const';
/**
* Update plugin readme stable tag.
*
* @param plugin plugin to update
* @param nextVersion version to bump to
*/
export const updateReadmeStableTag = async (
plugin: string,
nextVersion: string
): Promise< void > => {
const filePath = join( MONOREPO_ROOT, `plugins/${ plugin }/readme.txt` );
try {
const readmeContents = await readFile( filePath, 'utf8' );
const updatedReadmeContents = readmeContents.replace(
/Stable tag: \d+\.\d+\.\d+\n/m,
`Stable tag: ${ nextVersion }\n`
);
await writeFile( filePath, updatedReadmeContents );
} catch ( e ) {
Logger.error( 'Unable to update readme stable tag' );
}
};
/**
* Update plugin readme changelog.
*
* @param plugin plugin to update
* @param nextVersion version to bump to
*/
export const updateReadmeChangelog = async (
plugin: string,
nextVersion: string
): Promise< void > => {
const filePath = join( MONOREPO_ROOT, `plugins/${ plugin }/readme.txt` );
try {
const readmeContents = await readFile( filePath, 'utf8' );
const updatedReadmeContents = readmeContents.replace(
/= \d+\.\d+\.\d+ \d\d\d\d-XX-XX =\n/m,
`= ${ nextVersion } ${ new Date().getFullYear() }-XX-XX =\n`
);
await writeFile( filePath, updatedReadmeContents );
} catch ( e ) {
Logger.error( 'Unable to update readme changelog' );
}
};
/**
* Update plugin class file.
*
* @param plugin plugin to update
* @param nextVersion version to bump to
*/
export const updateClassPluginFile = async (
plugin: string,
nextVersion: string
): Promise< void > => {
const filePath = join(
MONOREPO_ROOT,
`plugins/${ plugin }/includes/class-${ plugin }.php`
);
try {
await stat( filePath );
} catch ( e ) {
// Class file does not exist, return early.
return;
}
try {
const classPluginFileContents = await readFile( filePath, 'utf8' );
const updatedClassPluginFileContents = classPluginFileContents.replace(
/public \$version = '\d+\.\d+\.\d+';\n/m,
`public $version = '${ nextVersion }';\n`
);
await writeFile( filePath, updatedClassPluginFileContents );
} catch ( e ) {
Logger.error( 'Unable to update plugin file.' );
}
};
/**
* Update plugin JSON files.
*
* @param {string} type plugin to update
* @param {string} plugin plugin to update
* @param {string} nextVersion version to bump to
*/
export const updateJSON = async (
type: 'package' | 'composer',
plugin: string,
nextVersion: string
): Promise< void > => {
const filePath = join(
MONOREPO_ROOT,
`plugins/${ plugin }/${ type }.json`
);
try {
const composerJson = JSON.parse( await readFile( filePath, 'utf8' ) );
composerJson.version = nextVersion;
await writeFile(
filePath,
JSON.stringify( composerJson, null, '\t' ) + '\n'
);
} catch ( e ) {
Logger.error( 'Unable to update composer.json' );
}
};
/**
* Update plugin main file.
*
* @param plugin plugin to update
* @param nextVersion version to bump to
*/
export const updatePluginFile = async (
plugin: string,
nextVersion: string
): Promise< void > => {
const filePath = join(
MONOREPO_ROOT,
`plugins/${ plugin }/${ plugin }.php`
);
try {
const pluginFileContents = await readFile( filePath, 'utf8' );
const updatedPluginFileContents = pluginFileContents.replace(
/Version: \d+\.\d+\.\d+.*\n/m,
`Version: ${ nextVersion }\n`
);
await writeFile( filePath, updatedPluginFileContents );
} catch ( e ) {
Logger.error( 'Unable to update plugin file.' );
}
};

View File

@ -1,76 +0,0 @@
/**
* External dependencies
*/
import { valid, lt as versionLessThan, parse } from 'semver';
import { join } from 'path';
import { readFile } from 'fs/promises';
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
/**
* Internal dependencies
*/
import { MONOREPO_ROOT } from './const';
/**
* Get a plugin's current version.
*
* @param plugin plugin to update.
*/
export const getCurrentVersion = async (
plugin: string
): Promise< string | void > => {
const filePath = join( MONOREPO_ROOT, `plugins/${ plugin }/composer.json` );
try {
const composerJSON = JSON.parse( await readFile( filePath, 'utf8' ) );
return composerJSON.version;
} catch ( e ) {
Logger.error( 'Unable to read current version.' );
}
};
/**
* When given a prerelease version, return just the version.
*
* @param {string} prereleaseVersion version with prerelease params
* @return {string} version
*/
export const stripPrereleaseParameters = (
prereleaseVersion: string
): string => {
const parsedVersion = parse( prereleaseVersion );
if ( parsedVersion ) {
const { major, minor, patch } = parsedVersion;
return `${ major }.${ minor }.${ patch }`;
}
return prereleaseVersion;
};
/**
* Validate inputs.
*
* @param plugin plugin
* @param options options
* @param options.version version
*/
export const validateArgs = async (
plugin: string,
options: { version: string }
): Promise< void > => {
const nextVersion = options.version;
if ( ! valid( nextVersion ) ) {
Logger.error(
'Invalid version supplied, please pass in a semantically correct version.'
);
}
const currentVersion = await getCurrentVersion( plugin );
if ( ! currentVersion ) {
Logger.error( 'Unable to determine current version' );
} else if ( versionLessThan( nextVersion, currentVersion ) ) {
Logger.error(
'The version supplied is less than the current version, please supply a valid version.'
);
}
};

View File

@ -1,31 +0,0 @@
{
"name": "version-bump",
"version": "0.1.0",
"description": "Automate version bumping for WooCommerce plugins",
"main": " ",
"author": "",
"license": "GPL-2.0-or-later",
"engines": {
"node": "^16.14.1",
"pnpm": "^8.3.1"
},
"devDependencies": {
"@tsconfig/node16": "^1.0.3",
"@types/express": "^4.17.13",
"typescript": "^4.9.5"
},
"dependencies": {
"@commander-js/extra-typings": "^0.1.0",
"@woocommerce/monorepo-utils": "workspace:*",
"chalk": "^4.1.2",
"commander": "9.4.0",
"express": "^4.18.1",
"ora": "^5.4.1",
"semver": "^7.3.2",
"ts-node": "^10.9.1"
},
"scripts": {
"lint": "eslint . --ext .ts --config .eslintrc",
"version": "node -r ts-node/register ./index.ts"
}
}

View File

@ -1,10 +0,0 @@
/**
* External dependencies
*/
import { Command } from '@commander-js/extra-typings';
export const program = new Command();
program
.name( 'version-bump' )
.description( 'CLI to automate version bumping for WooCommerce plugins.' );

View File

@ -1,7 +0,0 @@
{
"extends": "@tsconfig/node16/tsconfig.json",
"ts-node": {
"transpileOnly": true,
"files": true
}
}