-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add recursive 'actions' option * fix: inherit glob and root from action options * fix: implement merging named actions and groups * chore: add unit tests * chore: add unit tests * chore: rename actions to jobs * fix: rename to run jobs * chore: fix integrity test * fix: rename actions to jobs * fix: add integrity tests and fix some odd merging * docs: add docs about jobs * fix: replace panics with readable errors
- Loading branch information
Showing
39 changed files
with
1,435 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## `group` | ||
|
||
Specifies a group of jobs and option to run them with. | ||
|
||
- [`parallel`](./parallel.md) | ||
- [`piped`](./piped.md) | ||
- [`jobs`](./jobs.md) | ||
|
||
### Example | ||
|
||
```yml | ||
# lefthook.yml | ||
|
||
pre-commit: | ||
jobs: | ||
- group: | ||
parallel: true | ||
jobs: | ||
- run: echo hello from a group | ||
``` | ||
> **Note:** To make a group mergeable with settings defined in local config or extends you have to specify the name of the job group belongs to: | ||
> ```yml | ||
> pre-commit: | ||
> jobs: | ||
> - name: a name of a group | ||
> group: | ||
> jobs: | ||
> - run: echo from a group job | ||
> ``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
## `jobs` | ||
|
||
Job can either be a command or a script. Configuring `jobs` is more flexible than configuring `commands` and `scripts`, although all options are supported now. | ||
|
||
```yml | ||
# lefthook.yml | ||
|
||
pre-commit: | ||
jobs: | ||
- run: yarn lint | ||
- run: yarn test | ||
``` | ||
This is how jobs configuration differ from commands and scripts: | ||
- Jobs have optional names. Lefthook merges named jobs across [extends](./extends.md) and [local configs](../examples/lefthook-local.md). Unnamed jobs get appended in the definition order. | ||
- Jobs can have groups of other jobs. For groups you can specify [`parallel`](./parallel.md) or [`piped`](./piped.md) flow for a bunch of jobs. Also [`glob`](./glob.md) and [`root`](./root.md) parameters of a group apply to all its jobs (even nested). | ||
|
||
### Job options | ||
|
||
- [`name`](./name.md) | ||
- [`run`](./run.md) | ||
- [`script`](./script.md) | ||
- [`runner`](./runner.md) | ||
- [`group`](./group.md) | ||
- [`parallel`](./parallel.md) | ||
- [`piped`](./piped.md) | ||
- [`jobs`](./jobs.md) | ||
- [`skip`](./skip.md) | ||
- [`only`](./only.md) | ||
- [`tags`](./tags.md) | ||
- [`glob`](./glob.md) | ||
- [`files`](./files.md) | ||
- [`file_types`](./file_types.md) | ||
- [`env`](./env.md) | ||
- [`root`](./root.md) | ||
- [`exclude`](./exclude.md) | ||
- [`fail_text`](./fail_text.md) | ||
- [`stage_fixed`](./stage_fixed.md) | ||
- [`interactive`](./interactive.md) | ||
- [`use_stdin`](./use_stdin.md) | ||
|
||
### Example | ||
|
||
> **Note:** Currently only `root` and `glob` options are applied to group jobs. Other options must be set for each job separately. If you find this inconvenient, please submit a [feature request](https://github.com/evilmartians/lefthook/issues/new?assignees=&labels=feature+request&projects=&template=feature_request.md). | ||
|
||
A simple configuration with one piped group which executes in parallel with other jobs. | ||
|
||
```yml | ||
# lefthook.yml | ||
pre-commit: | ||
parallel: true | ||
jobs: | ||
- name: migrate | ||
root: backend/ | ||
glob: "db/migrations/*" | ||
group: | ||
piped: true | ||
jobs: | ||
- run: bundle install | ||
- run: rails db:migrate | ||
- run: yarn lint --fix {staged_files} | ||
root: frontend/ | ||
stage_fixed: true | ||
- run: bundle exec rubocop | ||
root: backend/ | ||
- run: golangci-lint | ||
root: proxy/ | ||
- script: verify.sh | ||
runner: bash | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## `name` | ||
|
||
Name of a job. Will be printed in summary. If specified, the jobs can be merged with a jobs of the same name in a [local config](../examples/lefthook-local.md) or [extends](./extends.md). | ||
|
||
### Example | ||
|
||
```yml | ||
# lefthook.yml | ||
|
||
pre-commit: | ||
jobs: | ||
- name: lint and fix | ||
run: yarn run eslint --fix {staged_files} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## `script` | ||
|
||
Name of a script to execute. The rules are the same as for [`scripts`](./Scripts.md) | ||
|
||
### Example | ||
|
||
```yml | ||
# lefthook.yml | ||
|
||
pre-commit: | ||
jobs: | ||
- script: linter.sh | ||
runner: bash | ||
``` | ||
```bash | ||
# .lefthook/pre-commit/linter.sh | ||
|
||
echo "Everything is OK" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,28 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/evilmartians/lefthook/internal/git" | ||
"github.com/evilmartians/lefthook/internal/system" | ||
) | ||
|
||
const CMD = "{cmd}" | ||
|
||
var errPipedAndParallelSet = errors.New("conflicting options 'piped' and 'parallel' are set to 'true', remove one of this option from hook group") | ||
|
||
type Hook struct { | ||
Commands map[string]*Command `json:"commands,omitempty" mapstructure:"-" toml:"commands,omitempty" yaml:",omitempty"` | ||
Scripts map[string]*Script `json:"scripts,omitempty" mapstructure:"-" toml:"scripts,omitempty" yaml:",omitempty"` | ||
|
||
Files string `json:"files,omitempty" mapstructure:"files" toml:"files,omitempty" yaml:",omitempty"` | ||
Parallel bool `json:"parallel,omitempty" mapstructure:"parallel" toml:"parallel,omitempty" yaml:",omitempty"` | ||
Piped bool `json:"piped,omitempty" mapstructure:"piped" toml:"piped,omitempty" yaml:",omitempty"` | ||
Follow bool `json:"follow,omitempty" mapstructure:"follow" toml:"follow,omitempty" yaml:",omitempty"` | ||
Files string `json:"files,omitempty" mapstructure:"files" toml:"files,omitempty" yaml:",omitempty"` | ||
ExcludeTags []string `json:"exclude_tags,omitempty" koanf:"exclude_tags" mapstructure:"exclude_tags" toml:"exclude_tags,omitempty" yaml:"exclude_tags,omitempty"` | ||
Skip interface{} `json:"skip,omitempty" mapstructure:"skip" toml:"skip,omitempty,inline" yaml:",omitempty"` | ||
Only interface{} `json:"only,omitempty" mapstructure:"only" toml:"only,omitempty,inline" yaml:",omitempty"` | ||
} | ||
|
||
func (h *Hook) Validate() error { | ||
if h.Parallel && h.Piped { | ||
return errPipedAndParallelSet | ||
} | ||
Jobs []*Job `json:"jobs,omitempty" mapstructure:"jobs" toml:"jobs,omitempty" yaml:",omitempty"` | ||
|
||
return nil | ||
Commands map[string]*Command `json:"commands,omitempty" mapstructure:"-" toml:"commands,omitempty" yaml:",omitempty"` | ||
Scripts map[string]*Script `json:"scripts,omitempty" mapstructure:"-" toml:"scripts,omitempty" yaml:",omitempty"` | ||
} | ||
|
||
func (h *Hook) DoSkip(state func() git.State) bool { | ||
skipChecker := NewSkipChecker(system.Cmd) | ||
return skipChecker.check(state, h.Skip, h.Only) | ||
return skipChecker.Check(state, h.Skip, h.Only) | ||
} |
Oops, something went wrong.