Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

major0/pre-commit-exec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pre-commit-exec

This is a pre-commit plugin which allows the execution of arbitrary commands/scripts. This plugin grants generic access to system commands and repository scripts without the need to create a new repository. This is particularly useful when a single check requires the combination of multiple steps. I.e. a CI/CD workflow pattern.

For example, in building a static website and testing the HTML links in the generated website we can launch script handler, such as:

- repo: https://github.com/major0/pre-commit-exec
  rev: v0.1.2
  hooks:
    - id: command
      alias: hugo-build
      always_run: true
      name: Hugo Build
      args: ["hugo", "--cleanDestinationDir", "--noTimes", "--destination", ".build", "--baseUrl", "file:///.build/"]
- repo: https://github.com/major0/pre-commit-exec
  rev: v0.1.2
  hooks:
    - id: command
      alias: link-check
      always_run: true
      name: Check site links
      args: ["sh", "scripts/link-check.sh"]
- repo: https://github.com/major0/pre-commit-exec
  rev: v0.1.2
  hooks:
    - id: command
      alias: link-check-all
      stages: [manual]
      name: Check all links
      args: ["sh", "scripts/link-check.sh", "--all"]

This plugin supports 2 hooks: command and shell. Both are handled by Python's subprocess.run() interface. The only difference between them is that the shell hook grants access to various shell features.

From https://docs.python.org/3/library/subprocess.html:

This can be useful if you are using Python primarily for the enhanced control flow it offers over most system shells and still want convenient access to other shell features such as shell pipes, filename wildcards, environment variable expansion, and expansion of ~ to a user’s home directory.

About

Execute arbitrary commands/scripts from pre-commit

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages