Closed mathew-fleisch closed 1 year ago
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.
🤔 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.
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.
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.
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.
Sorry. Been a crazy busy week for me. LMK if there is anything else I can do 😄
I've squashed/tweaked and committed this as a214763.
Thought it'd be nice to have an example pre-commit hook to reference in the read-me