Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gha-onboarding): don't run git commands in CI #657

Merged
merged 4 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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