action-validator icon indicating copy to clipboard operation
action-validator copied to clipboard

Add pre-commit hook example to read-me

Open mathew-fleisch opened this issue 4 years ago • 6 comments

Thought it'd be nice to have an example pre-commit hook to reference in the read-me

mathew-fleisch avatar Nov 02 '21 13:11 mathew-fleisch

There's probably a better way to create a pre-commit hook; this is my first attempt at one. If you have any suggestions on improving/standardizing that example, please let me know.

mathew-fleisch avatar Nov 02 '21 13:11 mathew-fleisch

🤔 maybe it should iterate through the files being committed rather than all github actions. Currently a commit will fail if a broken action exists, even if it isn't being committed. You can also bypass the error by fixing the error and NOT committing the change.

mathew-fleisch avatar Nov 02 '21 18:11 mathew-fleisch

Ok. I took a slightly different approach iterating over the staged files, and grepping out all but files that contain .github/workflows in the filename. This should avoid the problem I was seeing about only linting those files that are to be committed. Note: I was not able to get the action-validator to cause the pre-commit hook to exit without evaluating the output in a variable. Running the command directly with no variable shows an error, but continues to the next iteration of the loop and does not block the commit (same with checking if action-validator binary exists). Also, the benefit of evaluating the output is you can use emojis 😏 If you can show me how to do this properly, I'd gladly change it.

mathew-fleisch avatar Nov 03 '21 13:11 mathew-fleisch

One thing to bear in mind is that action-validator can also validate Action definitions (.github/actions/*/action.y*ml), so a "full-service" example pre-commit hook it should also look for those files.

mpalmer avatar Nov 05 '21 23:11 mpalmer

One thing to bear in mind is that action-validator can also validate Action definitions (.github/actions/*/action.y*ml), so a "full-service" example pre-commit hook it should also look for those files.

I've never seen this subdirectory used before. However, I've modified the loop to look in .github/workflows AND .github/actions directories for yaml|yml files. Let me know if this works as a more full service example.

mathew-fleisch avatar Nov 08 '21 13:11 mathew-fleisch

Sorry. Been a crazy busy week for me. LMK if there is anything else I can do 😄

mathew-fleisch avatar Nov 19 '21 16:11 mathew-fleisch

I've squashed/tweaked and committed this as a214763.

mpalmer avatar Jan 19 '23 23:01 mpalmer