alirezanet / Husky.Net

Git hooks made easy with Husky.Net internal task runner! 🐶 It brings the dev-dependency concept to the .NET world!
https://alirezanet.github.io/Husky.Net/
MIT License
632 stars 29 forks source link

Git hook failed on CI/CD git checkout #109

Open darthkurak opened 1 month ago

darthkurak commented 1 month ago

Version

Newest

Details

I have an advanced build system in Nuke for my .NET apps. That build system makes sure that dotnet husky install is called each time when I build the app. It works almost perfectly fine. I have one issue in CI/CD case. When my Azure DevOps pipeline uses git checkout task, and this is not a first run - I am getting: .husky/post-checkout: 2: .: Can't open .husky/_/husky.sh error. I debugged this and the flow is following:

What is the best recommendation here? I found a few workarounds, but I am not sure if they are valid and proper:

Steps to reproduce

I described above.

alirezanet commented 1 month ago

Hi @darthkurak,

Typically, I'd recommend disabling Husky in CI/CD pipelines by setting the environment variable HUSKY=0. However, if you need to keep it enabled, here are two options:

(I haven't personally tested reinstalling Husky in post-checkout, but it's worth considering.) Let me know if you have any questions!

darthkurak commented 1 month ago

But how is disabling with HUSKY=0 supposed to work? It fails on the first line in post-checkout: . "$(dirname "$0")/_/husky.sh" Isn't too early for HUSKY=0 to work? :)

alirezanet commented 1 month ago

You're right now I understand the problem, I would say this is outside the Husky.Net scope, you need to adjust your CI/CD pipeline to either avoid using git clean in a way that removes necessary files for your project setup or somehow explicitly restore the husky.sh file after the git clean step, (maybe even copy it manually in a separate step after git clean, since this file rarely changes)