Skip to content

Commit 8b07fe1

Browse files
committed
Tooling: Add pre-commit with config and docs
Add pre-commit configuration with documentation describing it use. Remove old _redirect files. Update min hugo version in theme.toml.
1 parent ad54961 commit 8b07fe1

File tree

7 files changed

+116
-14
lines changed

7 files changed

+116
-14
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ resources/*
2525

2626
.hugo_build.lock
2727
public/*
28-
exampleSite/public
28+
exampleSite/public
29+
30+
# Python
31+
.venv

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: lint-commit
5+
name: Lint commit message to ensure it will pass the commit linting on CI
6+
entry: scripts/lint-commit.sh
7+
stages: [ commit-msg ]
8+
language: system

CONTRIBUTING.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ Follow our [Getting Started Guide](https://github.com/nginxinc/nginx-hugo-theme/
2020

2121
## Contributing
2222

23+
### Pre-commit setup
24+
We use [pre-commit](https://pre-commit.com/#install) for local pre-commit hooks.
25+
To get setup:
26+
- Install [pre-commit ](https://pre-commit.com/#install)
27+
- Install the hooks `pre-commit install`
28+
2329
### Report a Bug
2430

2531
To report a bug, open an issue on GitHub with the label `bug` using the available bug report issue template. Please ensure the bug has not already been reported. **If the bug is a potential security vulnerability, please report it using our [security policy](https://github.com/nginxinc/nginx-hugo-theme/blob/main/SECURITY.md).**
@@ -35,14 +41,28 @@ To suggest a feature or enhancement, please create an issue on GitHub with the l
3541

3642
Note: if you'd like to implement a new feature, please consider creating a [feature request issue](https://github.com/nginxinc/nginx-hugo-theme/blob/main/.github/feature_request_template.md) first to start a discussion about the feature.
3743

38-
3944
## Git Guidelines
4045

4146
- Keep a clean, concise and meaningful git commit history on your branch (within reason), rebasing locally and squashing before submitting a PR.
42-
- If possible and/or relevant, use the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) format when writing a commit message, so that changelogs can be automatically generated
43-
- Follow the guidelines of writing a good commit message as described here <https://chris.beams.io/posts/git-commit/> and summarised in the next few points:
44-
- In the subject line, use the present tense ("Add feature" not "Added feature").
45-
- In the subject line, use the imperative mood ("Move cursor to..." not "Moves cursor to...").
46-
- Limit the subject line to 72 characters or less.
47-
- Reference issues and pull requests liberally after the subject line.
48-
- Add more detailed description in the body of the git message (`git commit -a` to give you more space and time in your text editor to write a good message instead of `git commit -am`).
47+
- Split your changes into separate, atomic commits (i.e. A commit per feature or fix, where the build, tests and the system are all functioning).
48+
- Make sure your commits are rebased on the `main` branch.
49+
- Wrap your commit messages at 72 characters.
50+
- The first line of the commit message is the subject line, and must have the format "Category: Brief description of what's being changed".
51+
- The category should reflect the part of the Hugo theme you're working on, such as `Layouts`, `Styles`, `Templates`, `Assets`, `Config`, or `Docs`.
52+
- **Examples:**
53+
- `Layouts: Fix navigation menu rendering issue`
54+
- `Styles: Update typography for post headings`
55+
- `Templates: Add archive page template`
56+
- `Assets: Optimize images and minify JS files`
57+
- `Config: Fix site URL for production builds`
58+
59+
- Avoid generic categories like "`Theme`" or "`Misc`" unless the change truly applies across the entire project and can't be narrowed down further.
60+
61+
- You may combine categories with `+` if multiple areas are affected.
62+
- Example: `Layouts+Styles: Add dark mode toggle styles and layout`
63+
- Write the commit message subject line in the imperative mood ("Foo: Change the way dates work", not "Foo: Changed the way dates work").
64+
- Write your commit messages in proper English, with care and punctuation.
65+
- Amend your existing commits when adding changes after a review, where relevant.
66+
- Mark each review comment as "resolved" after pushing a fix with the requested changes.
67+
- Add your personal copyright line to files when making substantive changes. (Optional but encouraged!)
68+
- Check the spelling of your code, comments and commit messages.

_redirects_product

Lines changed: 0 additions & 2 deletions
This file was deleted.

_redirects_web-docs

Lines changed: 0 additions & 2 deletions
This file was deleted.

scripts/lint-commit.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env bash
2+
3+
# From https://github.com/SerenityOS/serenity/blob/master/Meta/lint-commit.sh
4+
5+
# the file containing the commit message is passed as the first argument
6+
commit_file="$1"
7+
commit_message=$(cat "$commit_file")
8+
9+
error() {
10+
echo -e "\033[0;31m$1:\033[0m"
11+
echo "$commit_message"
12+
exit 1
13+
}
14+
15+
# fail if the commit message contains windows style line breaks (carriage returns)
16+
if grep -q -U $'\x0D' "$commit_file"; then
17+
error "Commit message contains CRLF line breaks (only unix-style LF linebreaks are allowed)"
18+
fi
19+
20+
line_number=0
21+
while read -r line; do
22+
# break on git cut line, used by git commit --verbose
23+
if [[ "$line" == "# ------------------------ >8 ------------------------" ]]; then
24+
break
25+
fi
26+
27+
# ignore comment lines
28+
[[ "$line" =~ ^#.* ]] && continue
29+
# ignore overlong 'fixup!' commit descriptions
30+
[[ "$line" =~ ^fixup!\ .* ]] && continue
31+
32+
((line_number += 1))
33+
line_length=${#line}
34+
35+
if [[ $line_number -eq 1 ]]; then
36+
merge_commit_pattern="^Merge branch"
37+
if (echo "$line" | grep -E -q "$merge_commit_pattern"); then
38+
error "Commit is a git merge commit, use the rebase command instead"
39+
fi
40+
41+
category_pattern='^(Revert "|\S+: )'
42+
if (echo "$line" | grep -E -v -q "$category_pattern"); then
43+
error "Missing category in commit title (if this is a fix up of a previous commit, it should be squashed)"
44+
fi
45+
46+
revert_pattern='^Revert "'
47+
if [[ $line_length -gt 72 ]] && (echo "$line" | grep -E -v -q "$revert_pattern"); then
48+
error "Commit title is too long (maximum allowed is 72 characters)"
49+
fi
50+
51+
title_case_pattern="^\S.*?: [A-Z0-9]"
52+
if (echo "$line" | grep -E -v -q "$title_case_pattern"); then
53+
error "First word of commit after the subsystem is not capitalized"
54+
fi
55+
56+
if [[ "$line" =~ \.$ ]]; then
57+
error "Commit title ends in a period"
58+
fi
59+
elif [[ $line_number -eq 2 ]]; then
60+
if [[ $line_length -ne 0 ]]; then
61+
error "Empty line between commit title and body is missing"
62+
fi
63+
else
64+
url_pattern="([a-z]+:\/\/)?(([a-zA-Z0-9_]|-)+\.)+[a-z]{2,}(:\d+)?([a-zA-Z_0-9@:%\+.~\?&\/=]|-)+"
65+
if [[ $line_length -gt 72 ]] && (echo "$line" | grep -E -v -q "$url_pattern"); then
66+
error "Commit message lines are too long (maximum allowed is 72 characters)"
67+
fi
68+
69+
if [[ "$line" == "Signed-off-by: "* ]]; then
70+
error "Commit body contains a Signed-off-by tag"
71+
fi
72+
fi
73+
74+
done <"$commit_file"
75+
exit 0

theme.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ licenselink = "https://github.com/nginxinc/nginx-hugo-theme/blob/main/LICENSE"
77
description = "Hugo theme for F5 NGINX documentation"
88
homepage = "https://docs.nginx.com/"
99

10-
min_version = "0.128.0"
10+
min_version = "0.134.0"
1111

1212
[author]
1313
name = "F5, Inc."

0 commit comments

Comments
 (0)