Skip to content

Commit

Permalink
chore(hook): add several bump hooks and update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Oct 11, 2020
1 parent dcd28e8 commit 8ace14d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ features related to the conventional commit specification. Anything else shall b
- [Conventional commit logs](#Conventional-commit-logs)
- [Generate changelogs](#Generate-changelogs)
- [Auto bump](#Auto-bump)
- [Run pre-bump hook](#Run-pre-bump-hook)
- [Bump hooks](#Bump-hooks)
- [Pre bump hooks](#pre-bump-hooks)
- [Post bump hooks](#post-bump-hooks)
- [Install pre-commit hook](#Install-pre-commit-hook)
- [Contributing](#Contributing)
- [Licence](#Licence)
Expand Down Expand Up @@ -336,7 +338,9 @@ Note that if your project already contains a changelog you can tell `cog` about

You might also need to adjust `changelog_path` in `cog.toml`.

## Run pre bump hook
## Bump hooks

### Pre bump hooks

Creating git tag automatically is great but sometimes you need to edit some file with the new version number,
or perform some additional checks before doing so.
Expand All @@ -355,6 +359,19 @@ pre_bump_hooks = [
When running `cog bump` these command will be run before creating the version commit.
Assuming we are bumping to `1.1.0`, the `%version` alias will be replaced with `1.1.0`.

### Post bump hooks

You can tell `cog` to run commands after the bump.

```toml
# cog.toml
post_bump_hooks = [
"git push",
"git push origin %version",
"cargo publish"
]
```


### Install pre commit hook

Expand Down
9 changes: 9 additions & 0 deletions ci/check_branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

branch=$(git rev-parse --abbrev-ref HEAD)

if [ $branch != "master" ]
then
echo "Needs to be on master to bump current version"
exit 1
fi
16 changes: 15 additions & 1 deletion cog.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,28 @@ authors = [
# Optional changelog path ("CHANGELOG.md" if omitted)
changelog_path = "CHANGELOG.md"

# A list of command to run before creating a version.
# A list of command to run BEFORE creating a version.
# All change generated by those commands will be committed with the generated version commit.
# `%version` will be interpretted as your target version
pre_bump_hooks = [
"sh -c \"./ci/check_branch.sh\"",
"cargo test -- --test-threads 1",
"cargo clippy",
"cargo build --release",
"cargo package",
"cargo fmt --all",
"cargo bump %version",
]


# A list of command to run AFTER creating a version.
# `%version` will be interpretted as your target version
post_bump_hooks = [
"git push",
"git push origin %version",
"cargo publish"
]

# An optional list of additional allowed commit type
# `coco {commit_type}` commit command will be generated at runtime
[commit_types]
Expand Down

0 comments on commit 8ace14d

Please sign in to comment.