Monorepo Utils: Migrate cli-core (#38018)
* move source files * add uuid type dependency
This commit is contained in:
parent
6b158648e3
commit
ce7733ae78
|
@ -22,7 +22,7 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
npm install -g pnpm
|
npm install -g pnpm
|
||||||
npm -g i @wordpress/env@5.1.0
|
npm -g i @wordpress/env@5.1.0
|
||||||
pnpm install --filter code-analyzer --filter cli-core
|
pnpm install --filter code-analyzer --filter monorepo-utils
|
||||||
- name: Run analyzer
|
- name: Run analyzer
|
||||||
id: run
|
id: run
|
||||||
working-directory: tools/code-analyzer
|
working-directory: tools/code-analyzer
|
||||||
|
|
866
pnpm-lock.yaml
866
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -8,7 +8,6 @@ packages:
|
||||||
- 'tools/package-release'
|
- 'tools/package-release'
|
||||||
- 'tools/cherry-pick'
|
- 'tools/cherry-pick'
|
||||||
- 'tools/release-posts'
|
- 'tools/release-posts'
|
||||||
- 'tools/cli-core'
|
|
||||||
- 'tools/version-bump'
|
- 'tools/version-bump'
|
||||||
- 'tools/storybook'
|
- 'tools/storybook'
|
||||||
- 'tools/monorepo-utils'
|
- 'tools/monorepo-utils'
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
### CLI Core
|
|
||||||
|
|
||||||
This package contains utilities and libraries providing core functionality to
|
|
||||||
cli tools within `tools` so that this functionality can be easily reused.
|
|
|
@ -1,25 +0,0 @@
|
||||||
{
|
|
||||||
"name": "cli-core",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"description": "Core functionality for CLI tools/commands.",
|
|
||||||
"main": " ",
|
|
||||||
"author": "Automattic",
|
|
||||||
"license": "GPL-2.0-or-later",
|
|
||||||
"engines": {
|
|
||||||
"node": "^16.13.1",
|
|
||||||
"pnpm": "^8.3.1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@tsconfig/node16": "^1.0.3",
|
|
||||||
"@types/uuid": "^9.0.0",
|
|
||||||
"typescript": "^4.9.5"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"chalk": "^4.1.2",
|
|
||||||
"dotenv": "^10.0.0",
|
|
||||||
"ora": "^5.4.1",
|
|
||||||
"simple-git": "^3.10.0",
|
|
||||||
"ts-node": "^10.9.1",
|
|
||||||
"uuid": "^8.3.2"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
{
|
|
||||||
"extends": "@tsconfig/node16/tsconfig.json",
|
|
||||||
"ts-node": {
|
|
||||||
"transpileOnly": true,
|
|
||||||
"files": true,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,10 +9,10 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
"@commander-js/extra-typings": "^0.1.0",
|
"@commander-js/extra-typings": "^0.1.0",
|
||||||
|
"@woocommerce/monorepo-utils": "workspace:*",
|
||||||
"@oclif/core": "^2.4.0",
|
"@oclif/core": "^2.4.0",
|
||||||
"@tsconfig/node16": "^1.0.3",
|
"@tsconfig/node16": "^1.0.3",
|
||||||
"@types/uuid": "^8.3.4",
|
"@types/uuid": "^8.3.4",
|
||||||
"cli-core": "workspace:*",
|
|
||||||
"commander": "^9.4.0",
|
"commander": "^9.4.0",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"simple-git": "^3.10.0",
|
"simple-git": "^3.10.0",
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { Command } from '@commander-js/extra-typings';
|
import { Command } from '@commander-js/extra-typings';
|
||||||
import { Logger } from 'cli-core/src/logger';
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { readFile } from 'fs/promises';
|
import { readFile } from 'fs/promises';
|
||||||
import simpleGit from 'simple-git';
|
import simpleGit from 'simple-git';
|
||||||
import { cloneRepo } from 'cli-core/src/git';
|
import { cloneRepo } from '@woocommerce/monorepo-utils/src/core/git';
|
||||||
import { Logger } from 'cli-core/src/logger';
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
import { Command } from '@commander-js/extra-typings';
|
import { Command } from '@commander-js/extra-typings';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { Command } from '@commander-js/extra-typings';
|
import { Command } from '@commander-js/extra-typings';
|
||||||
import { Logger } from 'cli-core/src/logger';
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,7 +3,11 @@
|
||||||
*/
|
*/
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { simpleGit } from 'simple-git';
|
import { simpleGit } from 'simple-git';
|
||||||
import { execAsync, startWPEnv, stopWPEnv } from 'cli-core/src/util';
|
import { execAsync } from '@woocommerce/monorepo-utils/src/core/util';
|
||||||
|
import {
|
||||||
|
startWPEnv,
|
||||||
|
stopWPEnv,
|
||||||
|
} from '@woocommerce/monorepo-utils/src/core/wpenv';
|
||||||
|
|
||||||
export type SchemaDump = {
|
export type SchemaDump = {
|
||||||
schema: string;
|
schema: string;
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { getFilename, getPatches } from 'cli-core/src/git';
|
import {
|
||||||
|
getFilename,
|
||||||
|
getPatches,
|
||||||
|
} from '@woocommerce/monorepo-utils/src/core/git';
|
||||||
|
|
||||||
export const scanForDBChanges = ( content: string ) => {
|
export const scanForDBChanges = ( content: string ) => {
|
||||||
const matchPatches = /^a\/(.+).php/g;
|
const matchPatches = /^a\/(.+).php/g;
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { getFilename, getPatches } from 'cli-core/src/util';
|
import {
|
||||||
|
getFilename,
|
||||||
|
getPatches,
|
||||||
|
} from '@woocommerce/monorepo-utils/src/core/git';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { Logger } from 'cli-core/src/logger';
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { cloneRepo, generateDiff } from 'cli-core/src/git';
|
import {
|
||||||
|
cloneRepo,
|
||||||
|
generateDiff,
|
||||||
|
} from '@woocommerce/monorepo-utils/src/core/git';
|
||||||
import { readFile } from 'fs/promises';
|
import { readFile } from 'fs/promises';
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { Logger } from 'cli-core/src/logger';
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
import { readFile } from 'fs/promises';
|
import { readFile } from 'fs/promises';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ import {
|
||||||
getPullRequestNumberFromHash,
|
getPullRequestNumberFromHash,
|
||||||
getPatches,
|
getPatches,
|
||||||
getLineCommitHash,
|
getLineCommitHash,
|
||||||
} from 'cli-core/src/git';
|
} from '@woocommerce/monorepo-utils/src/core/git';
|
||||||
import { Logger } from 'cli-core/src/logger';
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
|
|
||||||
export type TemplateChangeDescription = {
|
export type TemplateChangeDescription = {
|
||||||
filePath: string;
|
filePath: string;
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
"@commander-js/extra-typings": "^0.1.0",
|
"@commander-js/extra-typings": "^0.1.0",
|
||||||
"@octokit/graphql": "4.8.0",
|
"@octokit/graphql": "4.8.0",
|
||||||
"@octokit/graphql-schema": "^14.1.0",
|
"@octokit/graphql-schema": "^14.1.0",
|
||||||
|
"@types/uuid": "^9.0.1",
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"commander": "^9.4.0",
|
"commander": "^9.4.0",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
|
@ -20,7 +21,9 @@
|
||||||
"octokit": "^2.0.14",
|
"octokit": "^2.0.14",
|
||||||
"ora": "^5.4.1",
|
"ora": "^5.4.1",
|
||||||
"promptly": "^3.2.0",
|
"promptly": "^3.2.0",
|
||||||
"semver": "^7.3.2"
|
"semver": "^7.3.2",
|
||||||
|
"simple-git": "^3.10.0",
|
||||||
|
"uuid": "^9.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.4.1",
|
"@types/jest": "^27.4.1",
|
||||||
|
|
|
@ -12,17 +12,18 @@ import { setOutput } from '@actions/core';
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
getLatestReleaseVersion,
|
getLatestGithubReleaseVersion,
|
||||||
doesGithubBranchExist,
|
doesGithubBranchExist,
|
||||||
getRefFromGithubBranch,
|
getRefFromGithubBranch,
|
||||||
createGithubBranch,
|
createGithubBranch,
|
||||||
deleteGithubBranch,
|
deleteGithubBranch,
|
||||||
} from '../../../github/repo';
|
} from '../../../core/github/repo';
|
||||||
import { WPIncrement } from '../milestone/utils';
|
import { WPIncrement } from '../../../core/version';
|
||||||
|
import { Logger } from '../../../core/logger';
|
||||||
import { Options } from './types';
|
import { Options } from './types';
|
||||||
|
|
||||||
const getNextReleaseBranch = async ( options: Options ) => {
|
const getNextReleaseBranch = async ( options: Options ) => {
|
||||||
const latestReleaseVersion = await getLatestReleaseVersion( options );
|
const latestReleaseVersion = await getLatestGithubReleaseVersion( options );
|
||||||
const nextReleaseVersion = WPIncrement( latestReleaseVersion );
|
const nextReleaseVersion = WPIncrement( latestReleaseVersion );
|
||||||
const parsedNextReleaseVersion = parse( nextReleaseVersion );
|
const parsedNextReleaseVersion = parse( nextReleaseVersion );
|
||||||
const nextReleaseMajorMinor = `${ parsedNextReleaseVersion.major }.${ parsedNextReleaseVersion.minor }`;
|
const nextReleaseMajorMinor = `${ parsedNextReleaseVersion.major }.${ parsedNextReleaseVersion.minor }`;
|
||||||
|
@ -66,11 +67,7 @@ export const branchCommand = new Command( 'branch' )
|
||||||
)
|
)
|
||||||
).start();
|
).start();
|
||||||
nextReleaseBranch = await getNextReleaseBranch( options );
|
nextReleaseBranch = await getNextReleaseBranch( options );
|
||||||
console.log(
|
Logger.warn( `The next release branch is ${ nextReleaseBranch }` );
|
||||||
chalk.yellow(
|
|
||||||
`The next release branch is ${ nextReleaseBranch }`
|
|
||||||
)
|
|
||||||
);
|
|
||||||
versionSpinner.succeed();
|
versionSpinner.succeed();
|
||||||
} else {
|
} else {
|
||||||
nextReleaseBranch = branch;
|
nextReleaseBranch = branch;
|
||||||
|
@ -90,10 +87,8 @@ export const branchCommand = new Command( 'branch' )
|
||||||
|
|
||||||
if ( branchExists ) {
|
if ( branchExists ) {
|
||||||
if ( github ) {
|
if ( github ) {
|
||||||
console.log(
|
Logger.error(
|
||||||
chalk.red(
|
`Release branch ${ nextReleaseBranch } already exists`
|
||||||
`Release branch ${ nextReleaseBranch } already exists`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
// When in Github Actions, we don't want to prompt the user for input.
|
// When in Github Actions, we don't want to prompt the user for input.
|
||||||
process.exit( 0 );
|
process.exit( 0 );
|
||||||
|
@ -104,18 +99,18 @@ export const branchCommand = new Command( 'branch' )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if ( deleteExistingReleaseBranch ) {
|
if ( deleteExistingReleaseBranch ) {
|
||||||
const deleteBranchSpinner = ora(
|
if ( ! dryRun ) {
|
||||||
chalk.yellow(
|
const deleteBranchSpinner = ora(
|
||||||
`Delete branch ${ nextReleaseBranch } on ${ owner }/${ name } and create new one from ${ source }`
|
chalk.yellow(
|
||||||
)
|
`Delete branch ${ nextReleaseBranch } on ${ owner }/${ name } and create new one from ${ source }`
|
||||||
).start();
|
)
|
||||||
await deleteGithubBranch( options, nextReleaseBranch );
|
).start();
|
||||||
deleteBranchSpinner.succeed();
|
await deleteGithubBranch( options, nextReleaseBranch );
|
||||||
|
deleteBranchSpinner.succeed();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
Logger.notice(
|
||||||
chalk.green(
|
`Branch ${ nextReleaseBranch } already exist on ${ owner }/${ name }, no action taken.`
|
||||||
`Branch ${ nextReleaseBranch } already exist on ${ owner }/${ name }, no action taken.`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
process.exit( 0 );
|
process.exit( 0 );
|
||||||
}
|
}
|
||||||
|
@ -127,10 +122,8 @@ export const branchCommand = new Command( 'branch' )
|
||||||
|
|
||||||
if ( dryRun ) {
|
if ( dryRun ) {
|
||||||
createBranchSpinner.succeed();
|
createBranchSpinner.succeed();
|
||||||
console.log(
|
Logger.notice(
|
||||||
chalk.green(
|
`DRY RUN: Skipping actual creation of branch ${ nextReleaseBranch } on ${ owner }/${ name }`
|
||||||
`DRY RUN: Skipping actual creation of branch ${ nextReleaseBranch } on ${ owner }/${ name }`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
process.exit( 0 );
|
process.exit( 0 );
|
||||||
|
@ -144,9 +137,7 @@ export const branchCommand = new Command( 'branch' )
|
||||||
setOutput( 'nextReleaseBranch', nextReleaseBranch );
|
setOutput( 'nextReleaseBranch', nextReleaseBranch );
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
Logger.notice(
|
||||||
chalk.green(
|
`Branch ${ nextReleaseBranch } successfully created on ${ owner }/${ name }`
|
||||||
`Branch ${ nextReleaseBranch } successfully created on ${ owner }/${ name }`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -2,16 +2,17 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { Command } from '@commander-js/extra-typings';
|
import { Command } from '@commander-js/extra-typings';
|
||||||
import chalk from 'chalk';
|
|
||||||
import ora from 'ora';
|
import ora from 'ora';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { getLatestReleaseVersion } from '../../../github/repo';
|
import { getLatestGithubReleaseVersion } from '../../../core/github/repo';
|
||||||
import { octokitWithAuth } from '../../../github/api';
|
import { octokitWithAuth } from '../../../core/github/api';
|
||||||
import { setGithubMilestoneOutputs, WPIncrement } from './utils';
|
import { setGithubMilestoneOutputs } from './utils';
|
||||||
|
import { WPIncrement } from '../../../core/version';
|
||||||
import { Options } from './types';
|
import { Options } from './types';
|
||||||
|
import { Logger } from '../../../core/logger';
|
||||||
|
|
||||||
export const milestoneCommand = new Command( 'milestone' )
|
export const milestoneCommand = new Command( 'milestone' )
|
||||||
.description( 'Create a milestone' )
|
.description( 'Create a milestone' )
|
||||||
|
@ -38,10 +39,8 @@ export const milestoneCommand = new Command( 'milestone' )
|
||||||
const { owner, name, dryRun, milestone, github } = options;
|
const { owner, name, dryRun, milestone, github } = options;
|
||||||
|
|
||||||
if ( milestone && github ) {
|
if ( milestone && github ) {
|
||||||
console.log(
|
Logger.error(
|
||||||
chalk.red(
|
"You can't manually supply a milestone using Github mode. Please use the CLI locally to add a milestone."
|
||||||
"You can't manually supply a milestone using Github mode. Please use the CLI locally to add a milestone."
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
process.exit( 1 );
|
process.exit( 1 );
|
||||||
}
|
}
|
||||||
|
@ -50,17 +49,15 @@ export const milestoneCommand = new Command( 'milestone' )
|
||||||
let nextReleaseVersion;
|
let nextReleaseVersion;
|
||||||
|
|
||||||
if ( milestone ) {
|
if ( milestone ) {
|
||||||
console.log(
|
Logger.warn(
|
||||||
chalk.yellow(
|
`Manually creating milestone ${ milestone } in ${ owner }/${ name }`
|
||||||
`Manually creating milestone ${ milestone } in ${ owner }/${ name }`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
nextMilestone = milestone;
|
nextMilestone = milestone;
|
||||||
} else {
|
} else {
|
||||||
const versionSpinner = ora(
|
const versionSpinner = ora(
|
||||||
'No milestone supplied, going off the latest release version'
|
'No milestone supplied, going off the latest release version'
|
||||||
).start();
|
).start();
|
||||||
const latestReleaseVersion = await getLatestReleaseVersion(
|
const latestReleaseVersion = await getLatestGithubReleaseVersion(
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
versionSpinner.succeed();
|
versionSpinner.succeed();
|
||||||
|
@ -68,22 +65,16 @@ export const milestoneCommand = new Command( 'milestone' )
|
||||||
nextReleaseVersion = WPIncrement( latestReleaseVersion );
|
nextReleaseVersion = WPIncrement( latestReleaseVersion );
|
||||||
nextMilestone = WPIncrement( nextReleaseVersion );
|
nextMilestone = WPIncrement( nextReleaseVersion );
|
||||||
|
|
||||||
console.log(
|
Logger.warn(
|
||||||
chalk.yellow(
|
`The latest release in ${ owner }/${ name } is version: ${ latestReleaseVersion }`
|
||||||
`The latest release in ${ owner }/${ name } is version: ${ latestReleaseVersion }`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
Logger.warn(
|
||||||
chalk.yellow(
|
`The next release in ${ owner }/${ name } will be version: ${ nextReleaseVersion }`
|
||||||
`The next release in ${ owner }/${ name } will be version: ${ nextReleaseVersion }`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
Logger.warn(
|
||||||
chalk.yellow(
|
`The next milestone in ${ owner }/${ name } will be: ${ nextMilestone }`
|
||||||
`The next milestone in ${ owner }/${ name } will be: ${ nextMilestone }`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,10 +84,8 @@ export const milestoneCommand = new Command( 'milestone' )
|
||||||
|
|
||||||
if ( dryRun ) {
|
if ( dryRun ) {
|
||||||
milestoneSpinner.succeed();
|
milestoneSpinner.succeed();
|
||||||
console.log(
|
Logger.notice(
|
||||||
chalk.green(
|
`DRY RUN: Skipping actual creation of milestone ${ nextMilestone }`
|
||||||
`DRY RUN: Skipping actual creation of milestone ${ nextMilestone }`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
process.exit( 0 );
|
process.exit( 0 );
|
||||||
|
@ -116,10 +105,8 @@ export const milestoneCommand = new Command( 'milestone' )
|
||||||
|
|
||||||
if ( milestoneAlreadyExistsError ) {
|
if ( milestoneAlreadyExistsError ) {
|
||||||
milestoneSpinner.succeed();
|
milestoneSpinner.succeed();
|
||||||
console.log(
|
Logger.notice(
|
||||||
chalk.green(
|
`Milestone ${ nextMilestone } already exists in ${ owner }/${ name }`
|
||||||
`Milestone ${ nextMilestone } already exists in ${ owner }/${ name }`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
if ( github ) {
|
if ( github ) {
|
||||||
setGithubMilestoneOutputs(
|
setGithubMilestoneOutputs(
|
||||||
|
@ -130,12 +117,10 @@ export const milestoneCommand = new Command( 'milestone' )
|
||||||
process.exit( 0 );
|
process.exit( 0 );
|
||||||
} else {
|
} else {
|
||||||
milestoneSpinner.fail();
|
milestoneSpinner.fail();
|
||||||
console.log(
|
Logger.error(
|
||||||
chalk.red(
|
`\nFailed to create milestone ${ nextMilestone } in ${ owner }/${ name }`
|
||||||
`\nFailed to create milestone ${ nextMilestone } in ${ owner }/${ name }`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
console.log( chalk.red( e.response.data.message ) );
|
Logger.error( e.response.data.message );
|
||||||
process.exit( 1 );
|
process.exit( 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,9 +129,7 @@ export const milestoneCommand = new Command( 'milestone' )
|
||||||
if ( github ) {
|
if ( github ) {
|
||||||
setGithubMilestoneOutputs( nextReleaseVersion, nextMilestone );
|
setGithubMilestoneOutputs( nextReleaseVersion, nextMilestone );
|
||||||
}
|
}
|
||||||
console.log(
|
Logger.notice(
|
||||||
chalk.green(
|
`Successfully created milestone ${ nextMilestone } in ${ owner }/${ name }`
|
||||||
`Successfully created milestone ${ nextMilestone } in ${ owner }/${ name }`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -1,24 +1,12 @@
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { parse, inc } from 'semver';
|
|
||||||
import { setOutput } from '@actions/core';
|
import { setOutput } from '@actions/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bumps the version according to WP rules.
|
* Internal dependencies
|
||||||
*
|
|
||||||
* @param {string} version Version to increment
|
|
||||||
* @return {string} Incremented version
|
|
||||||
*/
|
*/
|
||||||
export const WPIncrement = ( version: string ): string => {
|
import { getMajorMinor } from '../../../core/version';
|
||||||
const parsedVersion = parse( version );
|
|
||||||
return inc( parsedVersion, parsedVersion.minor === 9 ? 'major' : 'minor' );
|
|
||||||
};
|
|
||||||
|
|
||||||
const getMajorMinor = ( version: string ) => {
|
|
||||||
const parsedVersion = parse( version );
|
|
||||||
return `${ parsedVersion.major }.${ parsedVersion.minor }`;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Github outputs.
|
* Set Github outputs.
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { Command } from '@commander-js/extra-typings';
|
import { Command } from '@commander-js/extra-typings';
|
||||||
import chalk from 'chalk';
|
|
||||||
import { setOutput } from '@actions/core';
|
import { setOutput } from '@actions/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,6 +13,7 @@ import {
|
||||||
getToday,
|
getToday,
|
||||||
getFutureDate,
|
getFutureDate,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
import { Logger } from '../../../core/logger';
|
||||||
|
|
||||||
export const verifyDayCommand = new Command( 'verify-day' )
|
export const verifyDayCommand = new Command( 'verify-day' )
|
||||||
.description( 'Verify if today is the code freeze day' )
|
.description( 'Verify if today is the code freeze day' )
|
||||||
|
@ -28,28 +28,18 @@ export const verifyDayCommand = new Command( 'verify-day' )
|
||||||
.action( ( { override, github } ) => {
|
.action( ( { override, github } ) => {
|
||||||
const today = getToday( override );
|
const today = getToday( override );
|
||||||
const futureDate = getFutureDate( today );
|
const futureDate = getFutureDate( today );
|
||||||
console.log(
|
Logger.warn( "Today's timestamp UTC is: " + today.toUTCString() );
|
||||||
chalk.yellow( "Today's timestamp UTC is: " + today.toUTCString() )
|
Logger.warn(
|
||||||
);
|
`Checking to see if ${ DAYS_BETWEEN_CODE_FREEZE_AND_RELEASE } days from today is the second Tuesday of the month.`
|
||||||
console.log(
|
|
||||||
chalk.yellow(
|
|
||||||
`Checking to see if ${ DAYS_BETWEEN_CODE_FREEZE_AND_RELEASE } days from today is the second Tuesday of the month.`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
const isCodeFreezeDay = isTodayCodeFreezeDay( override );
|
const isCodeFreezeDay = isTodayCodeFreezeDay( override );
|
||||||
console.log(
|
Logger.notice(
|
||||||
chalk.green(
|
`${ futureDate.toUTCString() } ${
|
||||||
`${ futureDate.toUTCString() } ${
|
isCodeFreezeDay ? 'is' : 'is not'
|
||||||
isCodeFreezeDay ? 'is' : 'is not'
|
} release day.`
|
||||||
} release day.`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
console.log(
|
Logger.notice(
|
||||||
chalk.green(
|
`Today is ${ isCodeFreezeDay ? 'indeed' : 'not' } code freeze day.`
|
||||||
`Today is ${
|
|
||||||
isCodeFreezeDay ? 'indeed' : 'not'
|
|
||||||
} code freeze day.`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( github ) {
|
if ( github ) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { getLatestReleaseVersion } from '../repo';
|
import { getLatestGithubReleaseVersion } from '../repo';
|
||||||
|
|
||||||
jest.mock( '../api', () => {
|
jest.mock( '../api', () => {
|
||||||
return {
|
return {
|
||||||
|
@ -50,7 +50,7 @@ jest.mock( '../api', () => {
|
||||||
|
|
||||||
it( 'should return the latest release version', async () => {
|
it( 'should return the latest release version', async () => {
|
||||||
expect(
|
expect(
|
||||||
await getLatestReleaseVersion( {
|
await getLatestGithubReleaseVersion( {
|
||||||
owner: 'woocommerce',
|
owner: 'woocommerce',
|
||||||
name: 'woocommerce',
|
name: 'woocommerce',
|
||||||
} )
|
} )
|
|
@ -8,7 +8,7 @@ import { Repository } from '@octokit/graphql-schema';
|
||||||
*/
|
*/
|
||||||
import { graphqlWithAuth, octokitWithAuth } from './api';
|
import { graphqlWithAuth, octokitWithAuth } from './api';
|
||||||
|
|
||||||
export const getLatestReleaseVersion = async ( options: {
|
export const getLatestGithubReleaseVersion = async ( options: {
|
||||||
owner?: string;
|
owner?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
} ): Promise< string > => {
|
} ): Promise< string > => {
|
|
@ -0,0 +1,7 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { promisify } from 'util';
|
||||||
|
import { exec } from 'child_process';
|
||||||
|
|
||||||
|
export const execAsync = promisify( exec );
|
|
@ -0,0 +1,26 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { parse, inc } from 'semver';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bumps the version according to WP rules.
|
||||||
|
*
|
||||||
|
* @param {string} version Version to increment
|
||||||
|
* @return {string} Incremented version
|
||||||
|
*/
|
||||||
|
export const WPIncrement = ( version: string ): string => {
|
||||||
|
const parsedVersion = parse( version );
|
||||||
|
return inc( parsedVersion, parsedVersion.minor === 9 ? 'major' : 'minor' );
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the major-minor of a given version number.
|
||||||
|
*
|
||||||
|
* @param {string} version Version to gather major minor from.
|
||||||
|
* @return {string} major minor
|
||||||
|
*/
|
||||||
|
export const getMajorMinor = ( version: string ) => {
|
||||||
|
const parsedVersion = parse( version );
|
||||||
|
return `${ parsedVersion.major }.${ parsedVersion.minor }`;
|
||||||
|
};
|
|
@ -3,60 +3,11 @@
|
||||||
*/
|
*/
|
||||||
import { createServer, Server } from 'net';
|
import { createServer, Server } from 'net';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { writeFile } from 'fs/promises';
|
|
||||||
import { exec } from 'child_process';
|
|
||||||
import { promisify } from 'util';
|
|
||||||
|
|
||||||
export const execAsync = promisify( exec );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format version string for regex.
|
* Internal dependencies
|
||||||
*
|
|
||||||
* @param {string} rawVersion Raw version number.
|
|
||||||
* @return {string} version regex.
|
|
||||||
*/
|
*/
|
||||||
export const getVersionRegex = ( rawVersion: string ): string => {
|
import { execAsync } from './util';
|
||||||
const version = rawVersion.replace( /\./g, '\\.' );
|
|
||||||
|
|
||||||
if ( rawVersion.endsWith( '.0' ) ) {
|
|
||||||
return version + '|' + version.slice( 0, -3 ) + '\\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
return version;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get filename from patch
|
|
||||||
*
|
|
||||||
* @param {string} str String to extract filename from.
|
|
||||||
* @return {string} formatted filename.
|
|
||||||
*/
|
|
||||||
export const getFilename = ( str: string ): string => {
|
|
||||||
return str.replace( /^a(.*)\s.*/, '$1' );
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get patches
|
|
||||||
*
|
|
||||||
* @param {string} content Patch content.
|
|
||||||
* @param {RegExp} regex Regex to find specific patches.
|
|
||||||
* @return {string[]} Array of patches.
|
|
||||||
*/
|
|
||||||
export const getPatches = ( content: string, regex: RegExp ): string[] => {
|
|
||||||
const patches = content.split( 'diff --git ' );
|
|
||||||
const changes: string[] = [];
|
|
||||||
|
|
||||||
for ( const p in patches ) {
|
|
||||||
const patch = patches[ p ];
|
|
||||||
const id = patch.match( regex );
|
|
||||||
|
|
||||||
if ( id ) {
|
|
||||||
changes.push( patch );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return changes;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the default port for wp-env is already taken. If so, see
|
* Determine if the default port for wp-env is already taken. If so, see
|
||||||
|
@ -149,24 +100,3 @@ export const stopWPEnv = async (
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a JSON file with the data passed.
|
|
||||||
*
|
|
||||||
* @param filePath - path to the file to be created.
|
|
||||||
* @param data - data to be written to the file.
|
|
||||||
* @return {Promise<void>} - promise that resolves when the file is written.
|
|
||||||
*/
|
|
||||||
export const generateJSONFile = ( filePath: string, data: unknown ) => {
|
|
||||||
const json = JSON.stringify(
|
|
||||||
data,
|
|
||||||
function replacer( _, value ) {
|
|
||||||
if ( value instanceof Map ) {
|
|
||||||
return Array.from( value.entries() );
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
},
|
|
||||||
2
|
|
||||||
);
|
|
||||||
return writeFile( filePath, json );
|
|
||||||
};
|
|
|
@ -5,7 +5,8 @@ import semver from 'semver';
|
||||||
import { writeFile } from 'fs/promises';
|
import { writeFile } from 'fs/promises';
|
||||||
import { tmpdir } from 'os';
|
import { tmpdir } from 'os';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { Logger } from 'cli-core/src/logger';
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
|
import { getEnvVar } from '@woocommerce/monorepo-utils/src/core/environment';
|
||||||
import { Command } from '@commander-js/extra-typings';
|
import { Command } from '@commander-js/extra-typings';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
// @ts-expect-error - The enquirer types are incorrect.
|
// @ts-expect-error - The enquirer types are incorrect.
|
||||||
|
@ -17,7 +18,6 @@ import { Select } from 'enquirer';
|
||||||
*/
|
*/
|
||||||
import { renderTemplate } from '../../lib/render-template';
|
import { renderTemplate } from '../../lib/render-template';
|
||||||
import { getWordpressComAuthToken } from '../../lib/oauth-helper';
|
import { getWordpressComAuthToken } from '../../lib/oauth-helper';
|
||||||
import { getEnvVar } from '../../lib/environment';
|
|
||||||
import { getMostRecentFinal } from '../../lib/github-api';
|
import { getMostRecentFinal } from '../../lib/github-api';
|
||||||
import {
|
import {
|
||||||
getFirstTuesdayOfTheMonth,
|
getFirstTuesdayOfTheMonth,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { Command } from '@commander-js/extra-typings';
|
import { Command } from '@commander-js/extra-typings';
|
||||||
import { Logger } from 'cli-core/src/logger';
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
import { writeFile } from 'fs/promises';
|
import { writeFile } from 'fs/promises';
|
||||||
import { tmpdir } from 'os';
|
import { tmpdir } from 'os';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
|
@ -5,7 +5,8 @@ import semver from 'semver';
|
||||||
import { writeFile } from 'fs/promises';
|
import { writeFile } from 'fs/promises';
|
||||||
import { tmpdir } from 'os';
|
import { tmpdir } from 'os';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { Logger } from 'cli-core/src/logger';
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
|
import { getEnvVar } from '@woocommerce/monorepo-utils/src/core/environment';
|
||||||
import { Command } from '@commander-js/extra-typings';
|
import { Command } from '@commander-js/extra-typings';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
// @ts-expect-error - The enquirer types are incorrect.
|
// @ts-expect-error - The enquirer types are incorrect.
|
||||||
|
@ -17,12 +18,8 @@ import { Select } from 'enquirer';
|
||||||
*/
|
*/
|
||||||
import { renderTemplate } from '../../lib/render-template';
|
import { renderTemplate } from '../../lib/render-template';
|
||||||
import { getWordpressComAuthToken } from '../../lib/oauth-helper';
|
import { getWordpressComAuthToken } from '../../lib/oauth-helper';
|
||||||
import { getEnvVar } from '../../lib/environment';
|
import { getMostRecentBeta } from '../../lib/github-api';
|
||||||
import { getMostRecentBeta, getMostRecentFinal } from '../../lib/github-api';
|
import { getSecondTuesdayOfTheMonth } from '../../lib/dates';
|
||||||
import {
|
|
||||||
getFirstTuesdayOfTheMonth,
|
|
||||||
getSecondTuesdayOfTheMonth,
|
|
||||||
} from '../../lib/dates';
|
|
||||||
import {
|
import {
|
||||||
createWpComDraftPost,
|
createWpComDraftPost,
|
||||||
searchForPostsByCategory,
|
searchForPostsByCategory,
|
||||||
|
|
|
@ -6,8 +6,12 @@ import semver from 'semver';
|
||||||
import { writeFile } from 'fs/promises';
|
import { writeFile } from 'fs/promises';
|
||||||
import { tmpdir } from 'os';
|
import { tmpdir } from 'os';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { cloneRepo, getCommitHash } from 'cli-core/src/git';
|
import {
|
||||||
import { Logger } from 'cli-core/src/logger';
|
cloneRepo,
|
||||||
|
getCommitHash,
|
||||||
|
} from '@woocommerce/monorepo-utils/src/core/git';
|
||||||
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
|
import { getEnvVar } from '@woocommerce/monorepo-utils/src/core/environment';
|
||||||
import { Command } from '@commander-js/extra-typings';
|
import { Command } from '@commander-js/extra-typings';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
|
@ -21,7 +25,6 @@ import {
|
||||||
editWpComPostContent,
|
editWpComPostContent,
|
||||||
} from '../../lib/draft-post';
|
} from '../../lib/draft-post';
|
||||||
import { getWordpressComAuthToken } from '../../lib/oauth-helper';
|
import { getWordpressComAuthToken } from '../../lib/oauth-helper';
|
||||||
import { getEnvVar } from '../../lib/environment';
|
|
||||||
import { generateContributors } from '../../lib/contributors';
|
import { generateContributors } from '../../lib/contributors';
|
||||||
import { editPostHTML } from '../../lib/edit-post';
|
import { editPostHTML } from '../../lib/edit-post';
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { checkoutRef, sparseCheckoutRepo } from 'cli-core/src/git';
|
import {
|
||||||
|
checkoutRef,
|
||||||
|
sparseCheckoutRepo,
|
||||||
|
} from '@woocommerce/monorepo-utils/src/core/git';
|
||||||
import { readFile } from 'fs/promises';
|
import { readFile } from 'fs/promises';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import { Logger } from 'cli-core/src/logger';
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
|
|
||||||
// Typing just the things we need from the WP.com Post object.
|
// Typing just the things we need from the WP.com Post object.
|
||||||
// (which is not the same as WP Post object or API Post object).
|
// (which is not the same as WP Post object or API Post object).
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
/**
|
|
||||||
* External dependencies
|
|
||||||
*/
|
|
||||||
import { Logger } from 'cli-core/src/logger';
|
|
||||||
|
|
||||||
export const getEnvVar = ( varName: string, isRequired = false ) => {
|
|
||||||
const value = process.env[ varName ];
|
|
||||||
|
|
||||||
if ( value === undefined && isRequired ) {
|
|
||||||
Logger.error(
|
|
||||||
`You need to provide a value for ${ varName } in your environment either via an environment variable or the .env file.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return value || '';
|
|
||||||
};
|
|
|
@ -3,11 +3,7 @@
|
||||||
*/
|
*/
|
||||||
import { Octokit } from '@octokit/rest';
|
import { Octokit } from '@octokit/rest';
|
||||||
import shuffle from 'lodash.shuffle';
|
import shuffle from 'lodash.shuffle';
|
||||||
|
import { getEnvVar } from '@woocommerce/monorepo-utils/src/core/environment';
|
||||||
/**
|
|
||||||
* Internal dependencies
|
|
||||||
*/
|
|
||||||
import { getEnvVar } from './environment';
|
|
||||||
|
|
||||||
export type ContributorData = {
|
export type ContributorData = {
|
||||||
totalCommits: number;
|
totalCommits: number;
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@commander-js/extra-typings": "^0.1.0",
|
"@commander-js/extra-typings": "^0.1.0",
|
||||||
"@octokit/rest": "^19.0.4",
|
"@octokit/rest": "^19.0.4",
|
||||||
"cli-core": "workspace:*",
|
"@woocommerce/monorepo-utils": "workspace:*",
|
||||||
"code-analyzer": "workspace:*",
|
"code-analyzer": "workspace:*",
|
||||||
"commander": "9.4.0",
|
"commander": "9.4.0",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { prerelease } from 'semver';
|
import { prerelease } from 'semver';
|
||||||
import { Logger } from 'cli-core/src/logger';
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
import { readFile, writeFile, stat } from 'fs/promises';
|
import { readFile, writeFile, stat } from 'fs/promises';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { Logger } from 'cli-core/src/logger';
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import { valid, lt as versionLessThan, parse } from 'semver';
|
import { valid, lt as versionLessThan, parse } from 'semver';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { readFile } from 'fs/promises';
|
import { readFile } from 'fs/promises';
|
||||||
import { Logger } from 'cli-core/src/logger';
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@commander-js/extra-typings": "^0.1.0",
|
"@commander-js/extra-typings": "^0.1.0",
|
||||||
|
"@woocommerce/monorepo-utils": "workspace:*",
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"commander": "9.4.0",
|
"commander": "9.4.0",
|
||||||
"cli-core": "workspace:*",
|
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"ora": "^5.4.1",
|
"ora": "^5.4.1",
|
||||||
"semver": "^7.3.2",
|
"semver": "^7.3.2",
|
||||||
|
|
Loading…
Reference in New Issue