Monorepo Utils: Consolidate checking environment to use isGithubCI (#38310)
* use isGithubCI * Add basic tests for isGithubCI and fix failing existing test. --------- Co-authored-by: Sam Seay <samueljseay@gmail.com>
This commit is contained in:
parent
b7d17f3d8d
commit
600b19c6f8
|
@ -20,7 +20,7 @@ import {
|
|||
} from '../../../core/github/repo';
|
||||
import { WPIncrement } from '../../../core/version';
|
||||
import { Logger } from '../../../core/logger';
|
||||
import { getEnvVar } from '../../../core/environment';
|
||||
import { isGithubCI } from '../../../core/environment';
|
||||
|
||||
const getNextReleaseBranch = async ( options: {
|
||||
owner?: string;
|
||||
|
@ -57,7 +57,7 @@ export const branchCommand = new Command( 'branch' )
|
|||
)
|
||||
.action( async ( options ) => {
|
||||
const { source, branch, owner, name, dryRun } = options;
|
||||
const isGithub = getEnvVar( 'CI' );
|
||||
const isGithub = isGithubCI();
|
||||
|
||||
let nextReleaseBranch;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import { octokitWithAuth } from '../../../core/github/api';
|
|||
import { setGithubMilestoneOutputs } from './utils';
|
||||
import { WPIncrement } from '../../../core/version';
|
||||
import { Logger } from '../../../core/logger';
|
||||
import { getEnvVar } from '../../../core/environment';
|
||||
import { isGithubCI } from '../../../core/environment';
|
||||
|
||||
export const milestoneCommand = new Command( 'milestone' )
|
||||
.description( 'Create a milestone' )
|
||||
|
@ -33,7 +33,7 @@ export const milestoneCommand = new Command( 'milestone' )
|
|||
)
|
||||
.action( async ( options ) => {
|
||||
const { owner, name, dryRun, milestone } = options;
|
||||
const isGithub = getEnvVar( 'CI' );
|
||||
const isGithub = isGithubCI();
|
||||
|
||||
if ( milestone && isGithub ) {
|
||||
Logger.error(
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
getFutureDate,
|
||||
} from './utils';
|
||||
import { Logger } from '../../../core/logger';
|
||||
import { getEnvVar } from '../../../core/environment';
|
||||
import { isGithubCI } from '../../../core/environment';
|
||||
|
||||
export const verifyDayCommand = new Command( 'verify-day' )
|
||||
.description( 'Verify if today is the code freeze day' )
|
||||
|
@ -40,7 +40,7 @@ export const verifyDayCommand = new Command( 'verify-day' )
|
|||
`Today is ${ isCodeFreezeDay ? 'indeed' : 'not' } code freeze day.`
|
||||
);
|
||||
|
||||
if ( getEnvVar( 'CI' ) ) {
|
||||
if ( isGithubCI() ) {
|
||||
setOutput( 'freeze', isCodeFreezeDay.toString() );
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { isGithubCI } from '../environment';
|
||||
|
||||
describe( 'isGithubCI', () => {
|
||||
it( 'should return true if GITHUB_ACTIONS is true', () => {
|
||||
process.env.GITHUB_ACTIONS = 'true';
|
||||
expect( isGithubCI() ).toBe( true );
|
||||
} );
|
||||
|
||||
it( 'should return false if GITHUB_ACTIONS is false', () => {
|
||||
process.env.GITHUB_ACTIONS = 'false';
|
||||
expect( isGithubCI() ).toBe( false );
|
||||
} );
|
||||
|
||||
it( 'should return false if GITHUB_ACTIONS is not set', () => {
|
||||
process.env.GITHUB_ACTIONS = undefined;
|
||||
expect( isGithubCI() ).toBe( false );
|
||||
} );
|
||||
|
||||
afterAll( () => {
|
||||
delete process.env.GITHUB_ACTIONS;
|
||||
} );
|
||||
} );
|
|
@ -36,7 +36,7 @@ describe( 'Logger', () => {
|
|||
Logger.error( error );
|
||||
|
||||
expect( global.console.error ).toHaveBeenCalledWith(
|
||||
chalk.red( error.message )
|
||||
chalk.red( `${ error.message }\n${ error.stack }` )
|
||||
);
|
||||
} );
|
||||
|
||||
|
|
Loading…
Reference in New Issue