From a3955f2b0bd58208db30d94fdc82ee9df1a71d6c Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 1 Nov 2022 12:34:32 -0400 Subject: [PATCH] fix(gha-onboarding): don't run git commands in CI (#657) * fix(gha-onboarding): don't run git commands in CI * test: add test assertion for this case --- __tests__/lib/createGHA.test.ts | 2 ++ src/lib/createGHA/index.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/__tests__/lib/createGHA.test.ts b/__tests__/lib/createGHA.test.ts index 9dfedf574..86e15434d 100644 --- a/__tests__/lib/createGHA.test.ts +++ b/__tests__/lib/createGHA.test.ts @@ -177,6 +177,8 @@ describe('#createGHA', () => { it('should not run if in a CI environment', async () => { process.env.TEST_CI = 'true'; await expect(createGHA('success!', cmd, command.args, opts)).resolves.toBe('success!'); + // asserts that git commands aren't run in CI + expect(git.checkIsRepo).not.toHaveBeenCalled(); delete process.env.TEST_CI; }); diff --git a/src/lib/createGHA/index.ts b/src/lib/createGHA/index.ts index ef922081a..48c850974 100644 --- a/src/lib/createGHA/index.ts +++ b/src/lib/createGHA/index.ts @@ -165,6 +165,12 @@ export default async function createGHA( debug(`running GHA onboarding for ${command} command`); debug(`opts used in createGHA: ${JSON.stringify(opts)}`); + // if in a CI environment, + // don't even bother running the git commands + if (!opts.github && isCI()) { + return msg; + } + const { containsGitHubRemote, containsNonGitHubRemote, defaultBranch, isRepo, repoRoot } = await getGitData(); const configVal = configstore.get(getConfigStoreKey(repoRoot)); @@ -177,8 +183,6 @@ export default async function createGHA( if ( // not a repo !isRepo || - // in a CI environment - isCI() || // user has previously declined to set up GHA for current repo and `rdme` package version configVal === majorPkgVersion || // is a repo, but only contains non-GitHub remotes