Debian Codegraph @

CONTRIBUTING.md

raw
1 # Contributing to Hugo
2
3 We welcome contributions to Hugo of any kind including documentation, themes,
4 organization, tutorials, blog posts, bug reports, issues, feature requests,
5 feature implementations, pull requests, answering questions on the forum,
6 helping to manage issues, etc.
7
8 The Hugo community and maintainers are [very active](https://github.com/gohugoio/hugo/pulse/monthly) and helpful, and the project benefits greatly from this activity. We created a [step by step guide](https://gohugo.io/tutorials/how-to-contribute-to-hugo/) if you're unfamiliar with GitHub or contributing to open source projects in general.
9
10 *Note that this repository only contains the actual source code of Hugo. For **only** documentation-related pull requests / issues please refer to the [hugoDocs](https://github.com/gohugoio/hugoDocs) repository.*
11
12 *Changes to the codebase **and** related documentation, e.g. for a new feature, should still use a single pull request.*
13
14 ## Table of Contents
15
16 * [Asking Support Questions](#asking-support-questions)
17 * [Reporting Issues](#reporting-issues)
18 * [Submitting Patches](#submitting-patches)
19 * [Code Contribution Guidelines](#code-contribution-guidelines)
20 * [AI Assistance Notice](#ai-assistance-notice)
21 * [Git Commit Message Guidelines](#git-commit-message-guidelines)
22 * [Fetching the Sources From GitHub](#fetching-the-sources-from-github)
23 * [Building Hugo with Your Changes](#building-hugo-with-your-changes)
24
25 ## Asking Support Questions
26
27 We have an active [discussion forum](https://discourse.gohugo.io) where users and developers can ask questions.
28 Please don't use the GitHub issue tracker to ask questions.
29
30 ## Reporting Issues
31
32 If you believe you have found a defect in Hugo or its documentation, use
33 the GitHub issue tracker to report
34 the problem to the Hugo maintainers. If you're not sure if it's a bug or not,
35 start by asking in the [discussion forum](https://discourse.gohugo.io).
36 When reporting the issue, please provide the version of Hugo in use (`hugo
37 version`) and your operating system.
38
39 - [Hugo Issues · gohugoio/hugo](https://github.com/gohugoio/hugo/issues)
40 - [Hugo Documentation Issues · gohugoio/hugoDocs](https://github.com/gohugoio/hugoDocs/issues)
41 - [Hugo Website Theme Issues · gohugoio/hugoThemesSite](https://github.com/gohugoio/hugoThemesSite/issues)
42
43 ## Code Contribution
44
45 Hugo has become a fully featured static site generator, so any new functionality must:
46
47 * be useful to many.
48 * fit naturally into _what Hugo does best._
49 * strive not to break existing sites.
50 * close or update an open [Hugo issue](https://github.com/gohugoio/hugo/issues)
51
52 If it is of some complexity, the contributor is expected to maintain and support the new feature in the future (answer questions on the forum, fix any bugs etc.).
53
54 Any non-trivial code change needs to update an open [issue](https://github.com/gohugoio/hugo/issues). A non-trivial code change without an issue reference with one of the labels `bug` or `enhancement` will not be merged.
55
56 Note that we do not accept new features that require [CGO](https://go.dev/wiki/cgo).
57 We have one exception to this rule which is LibSASS.
58
59 **Bug fixes are, of course, always welcome.**
60
61 ## Submitting Patches
62
63 The Hugo project welcomes all contributors and contributions regardless of skill or experience level. If you are interested in helping with the project, we will help you with your contribution.
64
65 ### Code Contribution Guidelines
66
67 Because we want to create the best possible product for our users and the best contribution experience for our developers, we have a set of guidelines which ensure that all contributions are acceptable. The guidelines are not intended as a filter or barrier to participation. If you are unfamiliar with the contribution process, the Hugo team will help you and teach you how to bring your contribution in accordance with the guidelines.
68
69 To make the contribution process as seamless as possible, we ask for the following:
70
71 * Go ahead and fork the project and make your changes. We encourage pull requests to allow for review and discussion of code changes.
72 * When you’re ready to create a pull request, be sure to:
73 * Sign the [CLA](https://cla-assistant.io/gohugoio/hugo).
74 * Have test cases for the new code. If you have questions about how to do this, please ask in your pull request.
75 * If you borrow a test case (e.g. from the issue), that test's author must be added as [co-author](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors) in the commit.
76 * Run `go fmt`.
77 * Add documentation if you are adding new features or changing functionality. The docs site lives in `/docs`.
78 * Squash your commits into a single commit. `git rebase -i`. It’s okay to force update your pull request with `git push -f`.
79 * Ensure that `./check.sh` succeeds. Note that some tests are skipped when running locally, some because they are slow. To run these locally, do `CI_LOCAL=true ./check.sh ./somepackage/...`.
80 * Follow the **Git Commit Message Guidelines** below.
81
82 ## AI Assistance Notice
83
84 If a substantial part of your contribution is autogenerated with AI, **this must be disclosed in the pull request**, along with the extent to which AI assistance was used. AI contributions from non-maintainers needs to have a fairly narrow scope (e.g. a bug fix), as we have limited review capacity.
85
86 An example disclosure:
87
88 > This PR was written primarily by Claude Code.
89
90 Also, When using AI assistance:
91
92 * We expect contributors to manually verify that the state of the pull request is OK (e.g. that the CLI is signed).
93 * We expect contributors to understand the code that is produced and be able to answer critical questions about it
94
95 ### Git Commit Message Guidelines
96
97 This [blog article](https://cbea.ms/git-commit/) is a good resource for learning how to write good commit messages,
98 the most important part being that each commit message should have a title/subject in imperative mood starting with a capital letter and no trailing period:
99 *"js: Return error when option x is not set"*, **NOT** *"returning some error."*
100
101 Most title/subjects should have a lower-cased prefix with a colon and one whitespace. The prefix can be:
102
103 * The name of the package where (most of) the changes are made (e.g. `media: Add text/calendar`)
104 * If the package name is deeply nested/long, try to shorten it from the left side, e.g. `markup/goldmark` is OK, `resources/resource_transformers/js` can be shortened to `js`.
105 * If this commit touches several packages with a common functional topic, use that as a prefix, e.g. `errors: Resolve correct line numbers`)
106 * If this commit touches many packages without a common functional topic, prefix with `all:` (e.g. `all: Reformat Go code`)
107 * If this is a documentation update, prefix with `docs:`.
108 * If nothing of the above applies, just leave the prefix out.
109 * Note that the above excludes nouns seen in other repositories, e.g. "chore:".
110
111 Also, if your commit references one or more GitHub issues, always end your commit message body with *See #1234* or *Fixes #1234*.
112 Replace *1234* with the GitHub issue ID. The last example will close the issue when the commit is merged into *master*.
113
114 An example:
115
116 ```text
117 tpl: Add custom index function
118
119 Add a custom index template function that deviates from the stdlib simply by not
120 returning an "index out of range" error if an array, slice or string index is
121 out of range. Instead, we just return nil values. This should help make the
122 new default function more useful for Hugo users.
123
124 Fixes #1949
125 ```
126
127 ### Fetching the Sources From GitHub
128
129 Since Hugo 0.48, Hugo uses the Go Modules support built into Go 1.11 to build. The easiest is to clone Hugo in a directory outside of `GOPATH`, as in the following example:
130
131 ```bash
132 mkdir $HOME/src
133 cd $HOME/src
134 git clone https://github.com/gohugoio/hugo.git
135 cd hugo
136 go install
137 ```
138
139 For some convenient build and test targets, you also will want to install Mage:
140
141 ```bash
142 go install github.com/magefile/mage
143 ```
144
145 Now, to make a change to Hugo's source:
146
147 1. Create a new branch for your changes (the branch name is arbitrary):
148
149 ```bash
150 git checkout -b iss1234
151 ```
152
153 1. After making your changes, commit them to your new branch:
154
155 ```bash
156 git commit -a -v
157 ```
158
159 1. Fork Hugo in GitHub.
160
161 1. Add your fork as a new remote (the remote name, "fork" in this example, is arbitrary):
162
163 ```bash
164 git remote add fork [email protected]:USERNAME/hugo.git
165 ```
166
167 1. Push the changes to your new remote:
168
169 ```bash
170 git push --set-upstream fork iss1234
171 ```
172
173 1. You're now ready to submit a PR based upon the new branch in your forked repository.
174
175 ### Building Hugo with Your Changes
176
177 Hugo uses [mage](https://github.com/magefile/mage) to sync vendor dependencies, build Hugo, run the test suite and other things. You must run mage from the Hugo directory.
178
179 ```bash
180 cd $HOME/go/src/github.com/gohugoio/hugo
181 ```
182
183 To build Hugo:
184
185 ```bash
186 mage hugo
187 ```
188
189 To install hugo in `$HOME/go/bin`:
190
191 ```bash
192 mage install
193 ```
194
195 To run the tests:
196
197 ```bash
198 mage hugoRace
199 mage -v check
200 ```
201
202 To list all available commands along with descriptions:
203
204 ```bash
205 mage -l
206 ```
207
208 **Note:** From Hugo 0.43 we have added a build tag, `extended` that adds **SCSS support**. This needs a C compiler installed to build. You can enable this when building by:
209
210 ```bash
211 HUGO_BUILD_TAGS=extended mage install
212 ````