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:
Paul Sealock 2023-05-18 10:42:09 +12:00 committed by GitHub
parent b7d17f3d8d
commit 600b19c6f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 7 deletions

View File

@ -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;

View File

@ -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(

View File

@ -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() );
}

View File

@ -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;
} );
} );

View File

@ -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 }` )
);
} );