Skip to content

pre-commit git hooks to validate CircleCI configuration

License

Notifications You must be signed in to change notification settings

zahorniak/pre-commit-circleci

Repository files navigation

Overview

GitHub release (latest by date) GitHub Release Date - Published_At

issues - pre-commit-circleci GitHub pull requests

Usage

1. Install dependencies

2. Create config file .pre-commit-config.yaml with content:

$ cat .pre-commit-config.yaml
- repo: https://github.com/zahorniak/pre-commit-circleci.git
  rev: v1.1.0 # Ensure this is the latest tag, comparing to the Releases tab
  hooks:
    - id: circleci_validate

If you wish to pass additional args to circleci_validate, you can specify them in the config. See circleci config validate --help for accepted args. You must use the form --arg=value, not --arg value.

For example, to set an org-slug:

$ cat .pre-commit-config.yaml
- repo: https://github.com/zahorniak/pre-commit-circleci.git
  rev: v1.1.0 # Ensure this is the latest tag, comparing to the Releases tab
  hooks:
    - id: circleci_validate
      args:
        - --org-slug=my/organization

Or specify a custom config file:

$ cat .pre-commit-config.yaml
- repo: https://github.com/zahorniak/pre-commit-circleci.git
  rev: v1.1.0 # Ensure this is the latest tag, comparing to the Releases tab
  hooks:
    - id: circleci_validate
      args:
        - .circleci/continue_config.yml

3. Install hook

$ pre-commit install
pre-commit installed at .git/hooks/pre-commit

4. Commit code

$ git commit -m "add circleci hook"
Validate CircleCI config.................................................Passed
[branchname 1111111] add circleci hook
 1 file changed, 5 insertions(+), 1 deletion(-)

How hook works

Hook Description
circleci_validate Validates CircleCI configuration using command circleci config validate

Run hook manually

$ pre-commit run -a
Validate CircleCI config.................................................Passed