relnote docs · GitHub Action · CI · CHANGELOG.md · Single-file install

Release notes with pre-commit / git hooks

relnote reads commits that are already in the repository and prints a GitHub Release body. A pre-push hook runs after those commits exist. The pre-commit stage runs before the new commit object is written, so the notes stop at the previous commit. relnote has no --check flag. The exit status is the signal.

1. Exit status

Install so the relnote command is on PATH (pip install git+https://github.com/loki-inu/relnote.git, pipx, brew install loki-inu/tap/relnote, or the single file). From a checkout, python3 -m relnote is the same command. relnote --help has no --check flag and no --dry-run flag.

StatusWhen
0 Notes were written to stdout. --output FILE writes the same text to that file. --quiet with --output or --changelog leaves stdout empty. --next-version prints the next tag and writes no notes.
1 relnote: not a git repository (or any parent). relnote: unknown ref: no-such-tag. relnote: no commits in range HEAD..HEAD when nothing is left after filters. relnote: --max must be >= 1. relnote: --date must look like YYYY-MM-DD. relnote: output directory does not exist. relnote: changelog already has a section for that title, and the file is left unchanged. relnote: tag 'not-semver' is not a semantic version (x.y.z) from --next-version.
2 relnote: --quiet requires --output or --changelog. unrecognized arguments: README when a filename or other unknown argument is passed.

Merge commits are omitted unless you pass --include-merges. chore(release): ... commits are omitted unless you pass --include-release-commits. A subject that looks like a token is omitted. When every commit in the range is omitted, the status is 1 and stderr is relnote: no commits in range SINCE..UNTIL.

These three commands are the status 2 case and two status 1 cases. Each one prints to stderr and writes nothing to stdout:

python3 -m relnote --quiet
python3 -m relnote README
python3 -m relnote --since no-such-tag
python3 -m relnote --since HEAD

The GitHub Action treats the empty-range line as success and sets has-changes to false, unless fail-on-empty is true. A hook runs the CLI, which exits 1. See the GitHub Action guide.

2. Notes since the latest tag

Two commits after v1.2.0:

git log --oneline v1.2.0..HEAD
fix: return a sentinel error from Open
feat(api): add a context to Client.Do
python3 -m relnote
## What's changed

### Features

- **api:** add a context to Client.Do (`4febe8e`) — Ada Lovelace

### Fixes

- return a sentinel error from Open (`9034e17`) — Ada Lovelace

---

Range: `v1.2.0` → `HEAD`.

**Full changelog:** https://github.com/you/demo/compare/v1.2.0...HEAD

Output from a test repository built in relnote's CI (tests/test_pre_commit_docs.py); your hashes differ. To write a file and stay quiet:

python3 -m relnote --output notes.md --quiet

After you tag that commit, the same command with no flags ends the range at the tag. On a tag push, HEAD is the new tag, and the compare link uses it:

git tag -a v1.3.0 -m v1.3.0
python3 -m relnote
## What's changed

### Features

- **api:** add a context to Client.Do (`4febe8e`) — Ada Lovelace

### Fixes

- return a sentinel error from Open (`9034e17`) — Ada Lovelace

---

Range: `v1.2.0` → `v1.3.0`.

**Full changelog:** https://github.com/you/demo/compare/v1.2.0...v1.3.0

3. An empty range exits 1

The only commit after v1.2.0 is the release commit, which is omitted by default:

git log --oneline v1.2.0..HEAD
chore(release): v1.3.0
python3 -m relnote
relnote: no commits in range v1.2.0..HEAD

The status is 1. --include-release-commits keeps that commit and exits 0:

python3 -m relnote --include-release-commits
## What's changed

### Other

- **release:** v1.3.0 (`b077e70`) — Ada Lovelace

---

Range: `v1.2.0` → `HEAD`.

**Full changelog:** https://github.com/you/demo/compare/v1.2.0...HEAD

4. A pre-push hook that prints and does not block

Save this as .git/hooks/pre-push and run chmod +x .git/hooks/pre-push. git push runs it. The script prints the notes for HEAD, then exits 0, so an empty range does not block the push. If relnote is missing from PATH, the script still exits 0.

#!/bin/sh
# .git/hooks/pre-push
# Print notes for HEAD. The push continues even when relnote exits non-zero.
relnote
exit 0

Git writes the refs being pushed to the hook's standard input, one line per ref. This script does not read that list. The notes are always for HEAD. Pushing a different branch, or deleting a remote branch, still prints HEAD.

5. A pre-push hook that checks

This script replaces the shell with relnote, so the push is blocked when the status is non-zero. That includes an empty range, a missing relnote on PATH (status 127), and a push whose stdin lists some other ref: the check still evaluates HEAD.

#!/bin/sh
# .git/hooks/pre-push
# Block the push when relnote exits non-zero.
exec relnote

Tagging itself does not run a hook. After git tag, HEAD is that tag and the notes cover the range from the previous tag, as in the sample above. Pushing the tag runs pre-push.

6. pre-commit framework, local hook

A local hook calls the relnote already on PATH. pass_filenames: false is required: the default is to append staged paths, and python3 -m relnote README exits 2 with unrecognized arguments: README. always_run: true runs the hook when no file matches. stages is pre-push and manual, so a normal git commit does not run it. verbose: true prints the notes when the hook passes.

pre-commit 4.4.0 renamed language: system to language: unsupported. The old name still loads and is scheduled to be removed. On 4.3 and earlier, use system.

default_install_hook_types: [pre-push]
repos:
  - repo: local
    hooks:
      - id: relnote
        name: relnote
        entry: relnote
        language: unsupported
        types: [file]
        pass_filenames: false
        always_run: true
        stages: [pre-push, manual]
        verbose: true

default_install_hook_types makes pre-commit install write .git/hooks/pre-push. The default install list is only the pre-commit hook, and this hook's stages do not include that one, so nothing would run. You can also install the type by hand:

pre-commit install --hook-type pre-push
pre-commit run relnote --hook-stage pre-push

The status from relnote is the hook status. An empty range fails the hook.

7. pre-commit preview that does not fail the push

pre-commit 4.5.0 added pre-commit hazmat ignore-exit-code. It runs the command and then exits 0. The pre-commit docs put a trailing -- on that entry so filename arguments stay separate. relnote rejects a trailing -- as an unrecognized argument (status 2), so this entry does not end with --. pass_filenames: false keeps filenames off the command, and args is empty so nothing else is appended. verbose: true is what shows the notes when the hook passes.

minimum_pre_commit_version: "4.5.0"
repos:
  - repo: local
    hooks:
      - id: relnote-preview
        name: preview release notes
        entry: pre-commit hazmat ignore-exit-code relnote
        language: unsupported
        types: [file]
        args: []
        pass_filenames: false
        always_run: true
        stages: [pre-push, manual]
        verbose: true
pre-commit run relnote-preview --hook-stage manual

8. repo: https://github.com/loki-inu/relnote

The repository root contains .pre-commit-hooks.yaml. pre-commit clones the rev you pin, installs that revision with pip (the project declares the relnote console script), and runs it. The hook id, entry, and stages are:

- id: relnote
  name: relnote
  description: >-
    Print release notes from the latest tag to HEAD.
    Exit 0 when notes are written. Exit 1 when nothing is left to
    print (merge commits and chore(release) commits are omitted, and
    a subject that looks like a token is omitted), when the directory
    is not a git repository, or when a ref is unknown. Exit 2 when
    --quiet has no --output or --changelog, or when an unexpected
    argument is passed.
  entry: relnote
  language: python
  always_run: true
  pass_filenames: false
  stages: [pre-push, manual]
  verbose: true
  minimum_pre_commit_version: "3.2.0"

Pin rev to v0.3.8. That tag contains .pre-commit-hooks.yaml. The v0.3.7 tag does not contain that file, so that tag cannot be the rev. A branch name such as main moves; pre-commit warns that a mutable rev is not updated after the first install.

default_install_hook_types: [pre-push]
repos:
  - repo: https://github.com/loki-inu/relnote
    rev: v0.3.8
    hooks:
      - id: relnote

minimum_pre_commit_version is 3.2.0 because the stage names are pre-push and manual. The hook fails when relnote exits non-zero, including relnote: no commits in range v1.2.0..HEAD. To print the notes and let the push continue, use the shell script in section 4 or the ignore-exit-code hook in section 7.

FAQ

Does relnote have a --check flag?

No. relnote --help has no --check flag and no --dry-run flag. The exit status is the signal a hook can use. Exit 0 means notes were written (or --next-version printed a tag). Exit 1 covers an empty range and the other failures in the table on this page. Exit 2 means --quiet was used without --output or --changelog, or an argument was not recognized.

Why pre-push?

pre-push runs after the commits exist, so the notes include them. The pre-commit stage runs before the new commit object is written, so the notes stop at the previous commit. Tagging does not run a separate hook. After git tag, HEAD is that tag, and relnote starts the range at the previous tag. Pushing the tag runs the pre-push hook.

What does the hook read?

The scripts on this page run relnote with no arguments, so the range ends at HEAD. Git passes the refs being pushed on the hook's standard input. relnote does not read that list. A push of another branch, or a remote delete, still evaluates HEAD.

Why pass_filenames: false?

pre-commit appends staged filenames unless pass_filenames is false. relnote has no filename arguments. python3 -m relnote README exits 2 and the error says unrecognized arguments: README. always_run: true runs the hook when no files match.

Does an empty range fail the GitHub Action too?

The CLI exits 1 and prints relnote: no commits in range SINCE..UNTIL. The GitHub Action treats that line as success and sets has-changes to false, unless fail-on-empty is true. A hook runs the CLI.

Can I set rev to the v0.3.7 tag?

No. pre-commit clones the rev you pin and reads .pre-commit-hooks.yaml there. The v0.3.7 tag does not contain that file. Pin rev to v0.3.8. A branch name such as main is a moving target; pre-commit warns and does not keep updating it.