mpalmer / action-validator

Tool to validate GitHub Action and Workflow YAML files
GNU General Public License v3.0
277 stars 23 forks source link

Add pre-commit hook example to read-me #4

Closed mathew-fleisch closed 1 year ago

mathew-fleisch commented 2 years ago

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

mathew-fleisch commented 2 years 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.

mathew-fleisch commented 2 years ago

🤔 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 commented 2 years ago

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.

mpalmer commented 2 years ago

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.

mathew-fleisch commented 2 years ago

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 commented 2 years ago

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

mpalmer commented 1 year ago

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