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

[feat] Add a new option to skip enabling on CI #99

Closed
JounQin opened this issue Dec 7, 2023 · 26 comments · Fixed by #107
Closed

[feat] Add a new option to skip enabling on CI #99

JounQin opened this issue Dec 7, 2023 · 26 comments · Fixed by #107
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@JounQin
Copy link
Contributor

JounQin commented Dec 7, 2023

As title

@toplenboren
Copy link
Owner

Hi! I think this is going to be implemented once #96 make it to npm

@JounQin
Copy link
Contributor Author

JounQin commented Feb 25, 2024

#96 is a bit different for skipping on committing, while this issue aims skipping installation at the beginning.

I'd like to work on a PR soon.

@JounQin
Copy link
Contributor Author

JounQin commented Mar 4, 2024

@toplenboren I'd like to reuse SKIP_SIMPLE_GIT_HOOKS environment variable, how do you think?

@peschee
Copy link

peschee commented Mar 4, 2024

@JounQin Many CI environments normally set the CI variable by default (https://docs.travis-ci.com/user/environment-variables/#default-environment-variables, https://docs.travis-ci.com/user/environment-variables/#default-environment-variables, https://docs.github.com/en/actions/learn-github-actions/variables), so it would be best to also support this by default.

@JounQin
Copy link
Contributor Author

JounQin commented Mar 4, 2024

@peschee I think that would be a BREAKING CHANGE?

@peschee
Copy link

peschee commented Mar 4, 2024

Yes, probably. But are there instances where you'd want the hooks to be installed in a CI environment?

@JounQin
Copy link
Contributor Author

JounQin commented Mar 4, 2024

It's not about me personally, it's a behavior change which is a BREAKING CHANGE.

@peschee
Copy link

peschee commented Mar 4, 2024

Yes, I understand. Breaking changes can happen though, so I'd be inclined to still vote for handling CI env vars, since this is what many other tools do.

@JounQin
Copy link
Contributor Author

JounQin commented Mar 4, 2024

I'm fine with BREAKING CHANGE or major version personally, let's wait for @toplenboren to confirm.

@toplenboren
Copy link
Owner

Why do we need any git hooks to be set in CI ?

Maybe we can just add the guard to postinstall script, so that it does not install git hooks if it is executed inside CI environment

@peschee
Copy link

peschee commented Mar 4, 2024

Husky uses a custom env var for this: https://typicode.github.io/husky/how-to.html#ci-server-and-docker

Maybe it is easier to off-load the responsibility of skipping to the user all together. Using something like is-ci is pretty straightforward…

@JounQin
Copy link
Contributor Author

JounQin commented Mar 4, 2024

Why do we need any git hooks to be set in CI?

Checking commit message on CI for example.

Maybe we can just add the guard to postinstall script, so that it does not install git hooks if it is executed inside CI environment

I'd prefer to check SKIP_SIMPLE_GIT_HOOKS environment variable personally.

Using something like is-ci is pretty straightforward…

simple-git-hooks does have any dependencies to keep it simple as husky.

@toplenboren
Copy link
Owner

By the way, what is your usecase @JounQin?

@JounQin
Copy link
Contributor Author

JounQin commented Mar 4, 2024

@toplenboren

In my company, we have components which checks previous commit message on CI.

While in some other components, we don't want to enable git hooks because we could commit automatically with other tools.

@toplenboren
Copy link
Owner

@toplenboren

In my company, we have components which checks previous commit message on CI.

While in some other components, we don't want to enable git hooks because we could commit automatically with other tools.

Thank you for clarification!

Why simply using SKIP_SIMPLE_GIT_HOOKS would not work? Hooks will be installed, but not executed

@JounQin
Copy link
Contributor Author

JounQin commented Mar 7, 2024

@toplenboren

That's the point, we don't want the hooks to be installed and logs echo "[INFO] SKIP_SIMPLE_GIT_HOOKS is set to 1, skipping hook." on every commit.

@toplenboren
Copy link
Owner

Let's add SKIP_INSTALL_SIMPLE_GIT_HOOKS env variable support, and add CI variable support

  1. Case: SKIP_INSTALL_SIMPLE_GIT_HOOKS is not set
  • If not set and if in CI -> do NOT install hooks
  • If not set and not in CI -> install hooks
  1. SKIP_INSTALL_SIMPLE_GIT_HOOKS=1
  • Install hooks
  1. SKIP_INSTALL_SIMPLE_GIT_HOOKS=0
  • do NOT install hooks

This way we will:

  1. have the env var namings consistent: SKIP_*
  2. be able to address each case
  3. not need to do a major release

What do you think, @JounQin. Will this cover your usecases?

@JounQin
Copy link
Contributor Author

JounQin commented Mar 7, 2024

Do you want to add a dependency like is-ci? I think it's out scope of this tool, the user should easily add an environment variable on their needs.

@peschee
Copy link

peschee commented Mar 7, 2024

That‘s how I meant it: using is-ci should probably be outside of this library‘s scope, since it is easy enough.

@JounQin
Copy link
Contributor Author

JounQin commented Mar 7, 2024

That‘s how I meant it: using is-ci should probably be outside of this library‘s scope, since it is easy enough.

Checking isCI properly is not that simple AFAIK.

https://unpkg.com/browse/ci-info@4.0.0/index.js

@peschee
Copy link

peschee commented Mar 7, 2024

It seems we're talking about two different things…

The way I meant it is what is in the husky docs. They DO NOT include the is-ci package in husky, but rather rely on the user controlling whether they call husky install or not (using is-ci or any whatever other method).

My point was: this library is probably better off not including an additional dependency.

@JounQin
Copy link
Contributor Author

JounQin commented Mar 7, 2024

Oh, yes, I also think we should not check about CI on this lib's side. Do you have the consensus here?

@toplenboren
Copy link
Owner

toplenboren commented Mar 7, 2024

I honestly really like this idea:

@JounQin Many CI environments normally set the CI variable by default (https://docs.travis-ci.com/user/environment-variables/#default-environment-variables, https://docs.travis-ci.com/user/environment-variables/#default-environment-variables, https://docs.github.com/en/actions/learn-github-actions/variables), so it would be best to also support this by default.

Let's just check CI variable and add INSTALL_SIMPLE_GITH_HOOKS to explicitly configure this package for narrow usecases

@JounQin
Copy link
Contributor Author

JounQin commented Mar 8, 2024

Let's just check CI variable and add INSTALL_SIMPLE_GITH_HOOKS to explicitly configure this package for narrow usecases

OK, I'm personally fine with this strategy.


Case: SKIP_INSTALL_SIMPLE_GIT_HOOKS is not set

  • If not set and if in CI -> do NOT install hooks
  • If not set and not in CI -> install hooks

not need to do a major release

Isn't it a BREAKING CHANGE for not installing on CI by default?

@toplenboren
Copy link
Owner

Let's just check CI variable and add INSTALL_SIMPLE_GITH_HOOKS to explicitly configure this package for narrow usecases

OK, I'm personally fine with this strategy.

Case: SKIP_INSTALL_SIMPLE_GIT_HOOKS is not set

  • If not set and if in CI -> do NOT install hooks
  • If not set and not in CI -> install hooks

not need to do a major release

Isn't it a BREAKING CHANGE for not installing on CI by default?

Well.. technically yes.. :( I think we can do a major release, no problem

We can also split: first add the ability to configure INSTALL_SIMPLE_GIT_HOOKS and then add CI processing and update major

@JounQin
Copy link
Contributor Author

JounQin commented Mar 8, 2024

I'll work on it soon.

@toplenboren toplenboren added enhancement New feature or request good first issue Good for newcomers labels Mar 8, 2024
JounQin added a commit to JounQin/simple-git-hooks that referenced this issue Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants