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

Lefthook on windows can run powershell/pwsh as a runner #428

Open
j-byrnes opened this issue Feb 21, 2023 · 12 comments
Open

Lefthook on windows can run powershell/pwsh as a runner #428

j-byrnes opened this issue Feb 21, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@j-byrnes
Copy link

🔧 Summary

When attempting to run Lefthook on Windows, it doesn't seem to identify/see the config file.

Lefthook version

1.2.9 0e6aa81

Steps to reproduce

Install

$Path = [Environment]::GetEnvironmentVariable("PATH", "User") + [IO.Path]::PathSeparator + "C:\Lefthook"
[Environment]::SetEnvironmentVariable( "Path", $Path, "User" )

Prepare Repo

push-location c:\repo

lefthook_1.2.9_Windows_x86_64.exe install

lefthook_1.2.9_Windows_x86_64.exe add commit-msg

tree
C:\REPO
├───.lefthook
│   └───commit-msg
└───.lefthook-local
    └───commit-msg

Files

  • repo\lefthook.yml
# 'pwsh.exe -NoProfile -ExecutionPolicy Bypass -File ".\convcoGitHook.ps1 -MessagePath '$1'"'
commit-msg:
  conventional-commits-check:
    scripts:
      "convcoGitHook.ps1":
        runner: pwsh.exe -NoProfile -ExecutionPolicy Bypass -File
  • repo.lefthook\commit-msg\convcoGitHook.ps1
Write-Host "convcoGitHook.ps1 EXECUTED!!!!"

Expected results

> lefthook_1.2.9_Windows_x86_64.exe run commit-msg -v
Lefthook v1.2.9
SYNCING
SERVED HOOKS: commit-msg
RUNNING HOOK: commit-msg
convcoGitHook.ps1: (???Executing???)

convcoGitHook.ps1 EXECUTED!!!!

SUMMARY: (???NOT EMPTY???)

>

Actual results

> lefthook_1.2.9_Windows_x86_64.exe run commit-msg -v
Lefthook v1.2.9
SYNCING
SERVED HOOKS: commit-msg
RUNNING HOOK: commit-msg
convcoGitHook.ps1: (SKIP BY NOT EXIST IN CONFIG)

SUMMARY: (SKIP EMPTY)

>

Possible Solution

It is as if the config file isn't getting picked up/read/processed. The file lefthoook.yml is located in the root of the repo c:\repo which was the location it was created during install.

-v argument doesn't seem to include any additional output,

Per usage and configuration, I haven't been able to validate all the configuration file names/locations it would check.

While I'm not a Go programmer, I'm happy to do the heavy lifting on any/all testing for Windows since I know it's not the main focus.

  • at the end of the day, I'm trying to use pwsh.exe as a runner (possibly with some parameters)
  • validate the correct configuration file location that is expected.

Screenshots (if appropriate)

@j-byrnes j-byrnes added the bug Something isn't working label Feb 21, 2023
@mrexox
Copy link
Member

mrexox commented Feb 21, 2023

Hey! Thank you for the issue. Could you show your lefthook.yml config content, please?

@j-byrnes
Copy link
Author

Yeah, I included it above, repo\lefthook.yml

But here it is (in it's entirety;I did remove the default content)

# 'pwsh.exe -NoProfile -ExecutionPolicy Bypass -File ".\convcoGitHook.ps1 -MessagePath '$1'"'
commit-msg:
  conventional-commits-check:
    scripts:
      "convcoGitHook.ps1":
        runner: pwsh.exe -NoProfile -ExecutionPolicy Bypass -File

I get the same result if I use the above runner or one of the following:

        runner: pwsh.exe

#OR

        runner: pwsh

@mrexox
Copy link
Member

mrexox commented Feb 22, 2023

Hey! I guess you've misconfigured lefthook.yml. Could you try this?

# 'pwsh.exe -NoProfile -ExecutionPolicy Bypass -File ".\convcoGitHook.ps1 -MessagePath '$1'"'
commit-msg:
  scripts:
    "convcoGitHook.ps1":
      runner: pwsh.exe -NoProfile -ExecutionPolicy Bypass -File

There is conventional-commits-check: key that breaks the config format (although no error is thrown 🤔)

@j-byrnes
Copy link
Author

Ok, Made the change to lefthook.yml

# 'pwsh.exe -NoProfile -ExecutionPolicy Bypass -File ".\convcoGitHook.ps1 -MessagePath '$1'"'
commit-msg:
  scripts:
    "convcoGitHook.ps1":
      runner: pwsh.exe -NoProfile -ExecutionPolicy Bypass -File

Results: No change

> lefthook_1.2.9_Windows_x86_64.exe run commit-msg -v
Lefthook v1.2.9
SYNCING
SERVED HOOKS: commit-msg
RUNNING HOOK: commit-msg
convcoGitHook.ps1: (SKIP BY NOT EXIST IN CONFIG)

SUMMARY: (SKIP EMPTY)

@mrexox
Copy link
Member

mrexox commented Mar 2, 2023

Sorry for the delay. Could you share a github repository with the example configuration? I mean lefthook.yml, .lefthook/pre-commit/* scripts and other files that are related to lefthook configuration. It would help to investigate the issue because it's hard for me to identify the problem 🤔

@j-byrnes
Copy link
Author

Sorry for the delay. Could you share a github repository with the example configuration? I mean lefthook.yml, .lefthook/pre-commit/* scripts and other files that are related to lefthook configuration. It would help to investigate the issue because it's hard for me to identify the problem 🤔

Hey @mrexox, I apologize for the delayed response as work got in the way of responding... I've created a test repo to do further testing as requested:

https://github.com/j-byrnes/testLefthook

Since I see you've had several releases since my original post, I wasn't sure if the procedure for working on Windows had been updated.

Please let me know what the next steps are for troubleshooting.

@mrexox
Copy link
Member

mrexox commented Apr 11, 2023

Hey @j-byrnes! Thank you for the test repo. I just noticed that the .lefthook/ contains the script testScript.ps1. But the correct path for scripts is - .lefthook/<hook name>/<script name>. See docs for details.

Could you please move the testScript.ps1 into .lefthook/commit-msg/ folder and check if it works?

@j-byrnes
Copy link
Author

Thanks for the catch, it looks a little better... now the output is the following

> lefthook run commit-msg
Lefthook v1.3.9
RUNNING HOOK: commit-msg
testScript.ps1: (skip) not specified in config file

SUMMARY: (SKIP EMPTY)

I've commited the changes to the repo... not sure what it is referring to that the file isn't specified in the config file.

@mrexox
Copy link
Member

mrexox commented Apr 11, 2023

Oh, I see. The problem is - script name is converted to the lowercase when YAML is parsed. That's the problem I guess 😕

As a workaround I can suggest making script name in all lower case letters with - or _ to separate words. I'll check if it is possible to save the original case when parsing.

@j-byrnes
Copy link
Author

That worked, I'm going to explore testing a little more, that may be it.

Also, one more question: Do you have any suggestions for the "rc" configuration, does it have to be shell and can it use relative path names?

@j-byrnes
Copy link
Author

The need is to leverage rc to set an environment variable to add lefthook path during execution.

@mrexox
Copy link
Member

mrexox commented Apr 11, 2023

You can specify this:

# lefthook.yml

rc: ./testrc.sh

# ...

But this is not tested enough, however it should work (note ./ is important, it doesn't work for me without it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants