Skip to content

Commit

Permalink
fix(gha-onboarding): don't run git commands in CI (#657)
Browse files Browse the repository at this point in the history
* fix(gha-onboarding): don't run git commands in CI

* test: add test assertion for this case
  • Loading branch information
kanadgupta authored Nov 1, 2022
1 parent 0007322 commit a3955f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions __tests__/lib/createGHA.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand Down
8 changes: 6 additions & 2 deletions src/lib/createGHA/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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
Expand Down

0 comments on commit a3955f2

Please sign in to comment.