Skip to content

feat: support specifying stages #52

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

Closed
wants to merge 12 commits into from
Closed

Conversation

blaggacao
Copy link
Contributor

@blaggacao blaggacao commented Jul 20, 2020

closes #49

Since I'm a newcomer, I have no way to judge (or even validate) if that's the right way at all: it's a shot into the darknix.
If it's a hit, I appreciate that I could seamlessly contribute. If it's a miss, please guild me around to get this merge-ready.

@roberth
Copy link
Contributor

roberth commented Jul 20, 2020

darknix

nice :D

I think it's missing the option declaration. I haven't read the pre-commit docs so maybe it's not accurate, but perhaps excludes can serve as an example https://github.com/cachix/pre-commit-hooks.nix/pull/52/files#diff-0920dde2a9dc0ea9c564d0c0131c8feeR251

You can test your change by using it in a project. We don't have a test suite yet.

@roberth
Copy link
Contributor

roberth commented Jul 20, 2020

You can replace the builtins.fetchTarbal "..." part in the README by an unquoted local path like ../pre-commit.nix for testing

@blaggacao
Copy link
Contributor Author

blaggacao commented Jul 20, 2020

Thanks! I broke things. 😢

nix-shell --show-trace
warning: unknown setting 'experimental-features'
unpacking 'https://github.com/blaggacao/pre-commit-hooks.nix/tarball/master'...
error: while evaluating the attribute 'lorriHook' of the derivation 'nix-shell' at /nix/store/isyka0a95cxhj1381bg3bbqdv78qrln9-nixpkgs-20.09pre235189.d7e20ee25ed/nixpkgs/pkgs/build-support/mkshell/default.nix:28:3:
while evaluating the attribute 'pre-commit-check.shellHook' at /home/blaggacao/ghq/git.p1.rocks/gitops/aedir-ldap.k8s/default.nix:6:3:
while evaluating anonymous function at /nix/store/b4jq885hsxy31h23f3b6c5dnizchgn5q-source/nix/run.nix:3:1, called from /home/blaggacao/ghq/git.p1.rocks/gitops/aedir-ldap.k8s/default.nix:6:22:
while evaluating the attribute 'config.pre-commit.run' at undefined position:
while evaluating anonymous function at /nix/store/ma3b77vjls3qrznwh66ix5ivvybx6003-source/lib/modules.nix:84:45, called from undefined position:
while evaluating 'yieldConfig' at /nix/store/ma3b77vjls3qrznwh66ix5ivvybx6003-source/lib/modules.nix:83:29, called from /nix/store/ma3b77vjls3qrznwh66ix5ivvybx6003-source/lib/modules.nix:86:16:
while evaluating anonymous function at /nix/store/ma3b77vjls3qrznwh66ix5ivvybx6003-source/lib/modules.nix:89:24, called from /nix/store/ma3b77vjls3qrznwh66ix5ivvybx6003-source/lib/modules.nix:89:11:
while evaluating anonymous function at /nix/store/ma3b77vjls3qrznwh66ix5ivvybx6003-source/lib/modules.nix:90:26, called from /nix/store/ma3b77vjls3qrznwh66ix5ivvybx6003-source/lib/modules.nix:90:13:
The option `pre-commit.default_stages' defined in `<unknown-file>' does not exist.

Yeay! I'm trying very hard to read between the line, yet this log doesn't talk to my brain.

@roberth
Copy link
Contributor

roberth commented Jul 20, 2020

Oh my link above is broken. You need to declare an option for default_stages with mkOption. It's using the NixOS module system.

@blaggacao blaggacao force-pushed the master branch 2 times, most recently from cf5087d to dc6efb8 Compare July 20, 2020 22:06
@blaggacao
Copy link
Contributor Author

blaggacao commented Jul 20, 2020

Example result
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: .pre-commit-config.yaml
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ # DO NOT MODIFY
   2   │ # This file was generated by nix-pre-commit-hooks
   3   │ {
   4   │   "default_stages": [
   5   │     "manual",
   6   │     "pull"
   7   │   ],
   8   │   "exclude": "(^k8s/kustomize/|^images/ansible-ae-dir-server/|^images/config-initializer/ae-dir-configuration.sample.yml$|^images/config-initializer/ae-dir-customization.yml$|^images/config-initializer/ae-dir-container.yml$)",
   9   │   "repos": [
  10   │     {
  11   │       "hooks": [
  12   │         {
  13   │           "entry": "/nix/store/2pwj46x0qq9asnxkag1qcbvkz2zf2a9w-kubeval-0.15.0/bin/kubeval",
  14   │           "exclude": "^$",
  15   │           "files": "^k8s/.*?\\.(yaml|yml)$",
  16   │           "id": "kubeval",
  17   │           "language": "system",
  18   │           "name": "kubeval",
  19   │           "pass_filenames": true,
  20   │           "types": []
  21   │         },
  22   │         {
  23   │           "entry": "/nix/store/fisrj8c6cizy9df8hbg9cz1y64yvb1bv-node_prettier-2.0.5/bin/prettier --write --list-different",
  24   │           "exclude": "^$",
  25   │           "files": "\\.(css|less|scss|graphql|gql|html|js|jsx|json|md|markdown|mdown|mkdn|mdx|ts|tsx|vue|yaml|yml)$",
  26   │           "id": "prettier",
  27   │           "language": "system",
  28   │           "name": "prettier",
  29   │           "pass_filenames": true,
  30   │           "types": []
  31   │         },
  32   │         {
  33   │           "entry": "/nix/store/000llwy4g16jhmbi3yzngyzp1k4qykp0-ShellCheck-0.7.0/bin/shellcheck",
  34   │           "exclude": "^$",
  35   │           "files": "",
  36   │           "id": "shellcheck",
  37   │           "language": "system",
  38   │           "name": "shellcheck",
  39   │           "pass_filenames": true,
  40   │           "types": [
  41   │             "bash"
  42   │           ]
  43   │         },
  44   │         {
  45   │           "entry": "/nix/store/zihp6pxl6s8cb45zfbn2hcqkhis2zsnf-shfmt-3.1.2/bin/shfmt -w -l",
  46   │           "exclude": "^$",
  47   │           "files": "",
  48   │           "id": "shfmt",
  49   │           "language": "system",
  50   │           "name": "shfmt",
  51   │           "pass_filenames": true,
  52   │           "types": [
  53   │             "shell"
  54   │           ]
  55   │         }
  56   │       ],
  57   │       "repo": "local"
  58   │     }
  59   │   ]
  60   │ }

Easter egg: I don't think 'pull' actually exists. It's 'push' - I was trying to get in some entropy for lorri.

@blaggacao
Copy link
Contributor Author

Merge, 2, 3?
1, 2, merge?

😉 Thank you @roberth for your guidance!

blaggacao pushed a commit to blaggacao/pre-commit-hooks.nix that referenced this pull request Jul 20, 2020
@blaggacao blaggacao mentioned this pull request Jul 20, 2020
@blaggacao
Copy link
Contributor Author

blaggacao commented Jul 21, 2020

pre-commit uninstalled
pre-commit installed at .git/hooks/pre-push  # sic! pre-push

... now let's call it working!

The code before the last commit only ever installed 'commit' stage.

The code after the commit installs all known stages if they are configured or falls back to 'commit'.
It also removes old, eventually outdated stages.

Copy link
Contributor

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some simplifications around installation

@blaggacao
Copy link
Contributor Author

blaggacao commented Jul 21, 2020

@roberth
I'd like to apologize for my imperative opinions. However, without controlling the side effects, my use case gets completely jeopardized.

I'd suggest for the intermediate term to adopt a work around with a more involved error catcher.

Let's track pre-commit/pre-commit#1541 in complement to this course of action in a separate issue.

Would that be in line with your concerns?

@blaggacao
Copy link
Contributor Author

blaggacao commented Jul 21, 2020

We maybe, more fundamentally, have to ask ourselves, what stance to take on the pre-commit author's intentions:

pre-commit intentionally makes opting in and out an explicit action

Since in the current implementation pre-commit install (with or without this PR) is triggered, this would violate the author's intention.

On the other hand, shell.nix holds promises about repeatable development environments.
Opting out is still (somewhat) possible in this scenario until the declarative configuration updates.

EDIT: @domenkozar @roberth What do you think of out-factoring the install phase into another optional option, so we more faithfully maintain the opt-in + opt-out nature of pre-commit? - I don't have any better idea at the moment.

@domenkozar
Copy link
Member

Since the tool is called pre-commit I would expect the default to be running hooks before committing.

@blaggacao
Copy link
Contributor Author

blaggacao commented Jul 22, 2020

Since the tool is called pre-commit I would expect the default to be running hooks before committing.

Fair enough 😄

In reality though, pre-commit is evolving into a repo-scoped (per-repo cache) packager for task runners of all sorts.

To that end, I really like that you cut this sprout and called it local 👍

So once we strip that we are left with — despite the name — a git hook manager similar to husky.

Husky, contrary to pre-commit does make version controlled pretentions about which hooks to be installed.

See also:

npm uninstall husky
Git hooks installed by husky will be removed.

Contrary to pre-commit, it also cleans up after itself, by default.

I like husky's approach better and I think we should take the liberty and "fix" pre-commit for the nix community.

I can assure you, pre-commit's model is not useful as-is for me who has to make sure my collaborator is always up to date with the latest coding guidelines. That's why I'm turning to nix altogether in the first place.

@roberth
Copy link
Contributor

roberth commented Jul 22, 2020

At first glance, husky doesn't seem to provide help with the optimization of running only on modified files. Also iirc some users of this project also use or want to use existing non-Nixified pre-commit "repos" (packaged via other language-specific means)

I don't think it would be beneficial to kick out pre-commit in favor of another tool for these reasons.
The issue this PR is facing is minor. The lack of a pre-commit uninstall --all can be worked around, as you have done. Sure that means maintaining a list of hooks, but that's far better than fragmenting the Nix community's git hook packaging effort.

@blaggacao
Copy link
Contributor Author

@roberth Totally agree with both apsects (keeping pre-commit and working around its limitations).

Thanks for your opinion!

Counting your vote, my implicit vote (via this PR) and @domenkozar apparent abstention for a clear vote (please correct), I might summarize that we agree moving forward with what this PR tries to attempt.

I have already deployed it in our organization and did a last fixup yesterday.

Therefore, may I suggest you proceed with a formal incremental review?

@blaggacao
Copy link
Contributor Author

Oh, I'll have a look at the tests after lunch.

@blaggacao
Copy link
Contributor Author

Shall we proceed?

@blaggacao blaggacao requested a review from domenkozar August 7, 2020 01:05
@blaggacao
Copy link
Contributor Author

Ahm... From the CI.

 error: attribute 'Cabal_3_0_0_0' missing, at /home/runner/work/pre-commit-hooks.nix/pre-commit-hooks.nix/nix/default.nix:20:27
(use '--show-trace' to show detailed location information)
##[error]Process completed with exit code 1.

I hope that's not because of my latest commit, if so, I'd ask you to solve this the right way so I can learn by example.

jiribenes added a commit to jiribenes/pre-commit-hooks.nix that referenced this pull request Aug 13, 2020
@blaggacao
Copy link
Contributor Author

@domenkozar What's holding this back? Is it time?

@domenkozar
Copy link
Member

Bumping nixpkgs to master broke a few things, so we probably best revert that and have two versions of nixpkgs for tooling. I think eventually we'll need that sooner than later.

@blaggacao
Copy link
Contributor Author

blaggacao commented Sep 3, 2020

@domenkozar Ok I reverted it but I do unfortunately not know how to enable two nixpkgs versions.

Since on my side this is at sharp risk of getting stale, and I'm not able to give it the final touch, might I ask for your help to finish this off?

@domenkozar
Copy link
Member

Since I don't have time for this I recommend we wait for 20.10 to come out and pin that one which should also unblock this merge.

@domenkozar
Copy link
Member

I've bump nixpkgs in #65 and this issue is a good reminder that #61 is quite error prone.

@domenkozar
Copy link
Member

Alright master is ready!

@blaggacao
Copy link
Contributor Author

replaced by #79

@blaggacao blaggacao closed this Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support specifying stages
3 participants