simple-git-hooks icon indicating copy to clipboard operation
simple-git-hooks copied to clipboard

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

Open JounQin opened this issue 2 years ago • 14 comments

As title

JounQin avatar Dec 07 '23 07:12 JounQin

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

toplenboren avatar Feb 25 '24 16:02 toplenboren

#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 avatar Feb 25 '24 17:02 JounQin

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

JounQin avatar Mar 04 '24 06:03 JounQin

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

peschee avatar Mar 04 '24 07:03 peschee

@peschee I think that would be a BREAKING CHANGE?

JounQin avatar Mar 04 '24 07:03 JounQin

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

peschee avatar Mar 04 '24 07:03 peschee

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

JounQin avatar Mar 04 '24 08:03 JounQin

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.

peschee avatar Mar 04 '24 08:03 peschee

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

JounQin avatar Mar 04 '24 10:03 JounQin

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

toplenboren avatar Mar 04 '24 10:03 toplenboren

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…

peschee avatar Mar 04 '24 10:03 peschee

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.

JounQin avatar Mar 04 '24 11:03 JounQin

By the way, what is your usecase @JounQin?

toplenboren avatar Mar 04 '24 12:03 toplenboren

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

JounQin avatar Mar 04 '24 12:03 JounQin

@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

toplenboren avatar Mar 05 '24 09:03 toplenboren

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

JounQin avatar Mar 07 '24 08:03 JounQin

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?

toplenboren avatar Mar 07 '24 11:03 toplenboren

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.

JounQin avatar Mar 07 '24 11:03 JounQin

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

peschee avatar Mar 07 '24 12:03 peschee

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/[email protected]/index.js

JounQin avatar Mar 07 '24 12:03 JounQin

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.

peschee avatar Mar 07 '24 12:03 peschee

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

JounQin avatar Mar 07 '24 12:03 JounQin

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

toplenboren avatar Mar 07 '24 12:03 toplenboren

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?

JounQin avatar Mar 08 '24 04:03 JounQin

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

toplenboren avatar Mar 08 '24 12:03 toplenboren

I'll work on it soon.

JounQin avatar Mar 08 '24 13:03 JounQin