Sed-replace CRLF files
[cabal.git] / CONTRIBUTING.md
blobdeb9b51cdf11a0f1e28ced45b503de656c5ca479
1 # Contributing to Cabal
3 Building Cabal for hacking
4 --------------------------
6 If you use the latest version of cabal published on Hackage, it is sufficient to run:
8 ```
9 cabal build cabal
10 ```
12 If not, you aren't able to build the testsuite, so you need to disable the default `cabal.project` that implies configuring the testsuite, e.g., with:
14 ```
15 cabal build --project-file=cabal.project.release cabal
16 ```
18 > **Note**
19 > If you're using Nix, you might find it convenient to work within a shell that has all the `Cabal` development dependencies:
20 > ```
21 > $ nix-shell -p cabal-install ghc ghcid haskellPackages.fourmolu_0_12_0_0 pkgconfig zlib.dev
22 > ```
23 > A Nix flake developer shell with these dependencies is also available, supported solely by the community, through the command `nix develop github:yvan-sraka/cabal.nix`.
25 The location of your build products will vary depending on which version of
26 cabal-install you use to build; see the documentation section
27 [Where are my build products?](http://cabal.readthedocs.io/en/latest/nix-local-build.html#where-are-my-build-products)
28 to find the binary (or just run `find -type f -executable -name cabal`).
30 Here are some other useful variations on the commands:
32 ```
33 cabal build Cabal # build library only
34 cabal build Cabal-tests:unit-tests # build Cabal's unit test suite
35 cabal build cabal-tests # etc...
36 ```
38 Running tests
39 -------------
41 **Using GitHub Actions.**
42 If you are not in a hurry, the most convenient way to run tests on Cabal
43 is to make a branch on GitHub and then open a pull request; our
44 continuous integration service on GitHub Actions builds and
45 tests your code.  Title your PR with WIP so we know that it does not need
46 code review.
48 Some tips for using GitHub Actions effectively:
50 * GitHub Actions builds take a long time.  Use them when you are pretty
51   sure everything is OK; otherwise, try to run relevant tests locally
52   first.
54 * If you are only changing documentation in the `docs/` subdirectory,
55   or if you change `README.md` or `CONTRIBUTING.md`, then we only run a
56   small subset of the CI jobs. You can therefore open small PRs with
57   improvements to the documentation without feeling guilty about wasted
58   resources!
60 * Watch over your jobs on the [GitHub Actions website](http://github.org/haskell/cabal/actions).
61   If you know a build of yours is going to fail (because one job has
62   already failed), be nice to others and cancel the rest of the jobs,
63   so that other commits on the build queue can be processed.
65 **How to debug a failing CI test.**
66 One of the annoying things about running tests on CI is when they
67 fail, there is often no easy way to further troubleshoot the broken
68 build.  Here are some guidelines for debugging continuous integration
69 failures:
71 1. Can you tell what the problem is by looking at the logs?  The
72    `cabal-testsuite` tests run with `-v` logging by default, which
73    is dumped to the log upon failure; you may be able to figure out
74    what the problem is directly this way.
76 2. Can you reproduce the problem by running the test locally?
77    See the next section for how to run the various test suites
78    on your local machine.
80 3. Is the test failing only for a specific version of GHC, or
81    a specific operating system?  If so, try reproducing the
82    problem on the specific configuration.
84 4. Is the test failing on a GitHub Actions per-GHC build.
85    In this case, if you click on "Branch", you can get access to
86    the precise binaries that were built by GitHub Actions that are being
87    tested.  If you have an Ubuntu system, you can download
88    the binaries and run them directly.
90 If none of these let you reproduce, there might be some race condition
91 or continuous integration breakage; please file a bug.
93 **Running tests locally.**
94 To run tests locally with `cabal`, you will need to know the
95 name of the test suite you want.  Cabal and cabal-install have
96 several.  Also, you'll want to read [Where are my build products?](http://cabal.readthedocs.io/en/latest/nix-local-build.html#where-are-my-build-products)
98 The most important test suite is `cabal-testsuite`: most user-visible
99 changes to Cabal should come with a test in this framework.  See
100 [cabal-testsuite/README.md](cabal-testsuite/README.md) for more
101 information about how to run tests and write new ones.  Quick
102 start: use `cabal-tests` to run `Cabal` tests, and `cabal-tests
103 --with-cabal=/path/to/cabal` to run `cabal-install` tests
104 (don't forget `--with-cabal`! Your cabal-install tests won't
105 run without it).
107 There are also other test suites:
109 * `Cabal-tests:unit-tests` are small, quick-running unit tests
110   on small pieces of functionality in Cabal.  If you are working
111   on some utility functions in the Cabal library you should run this
112   test suite.
114 * `cabal-install:unit-tests` are small, quick-running unit tests on
115   small pieces of functionality in cabal-install.  If you are working
116   on some utility functions in cabal-install you should run this test
117   suite.
119 * `cabal-install:long-tests` are QuickCheck tests on
120   cabal-install's dependency solver, VCS, and file monitoring code.
121   If you are working on the solver you should run this test suite.
123 * `cabal-install:integration-tests2` are integration tests on some
124   top-level API functions inside the `cabal-install` source code.
126 For these test executables, `-p` which applies a regex filter to the test
127 names. When running `cabal-install` test suites, one need only use `cabal test` or
128 `cabal run <test-target>` in order to test locally.
130 QA Notes
131 --------
133 Manual Quality Assurance (QA) is performed to ensure that the changes impacting
134 the command-line interface, whether adding or modifying a behaviour,
135 are tested before being released. This allows us to catch UX regressions and put
136 a human perspective into testing.
138 Contributions that touch `cabal-install` are expected to include notes for the QA team.
139 They are a description of an expected result upon calling `cabal-install` with certain parameters,
140 and should be written in the body of the ticket or PR under their own heading, like this:
142 For instance:
144 > \#\# QA Notes
146 > Calling `cabal haddock-project` should produce documentation for the whole cabal project with the following defaults enabled:
147 > * Documentation lives in ./haddocks
148 > * The file `./haddocks/index.html` should exist
150 Manual QA is not expected to find every possible bug, but to really challenge the assumptions of the contributor, and to verify that their own testing
151 of their patch is not influenced by their setup or implicit knowledge of the system.
154 Code Style
155 ---------------
157 We use automated formatting with Fourmolu to enforce a unified style across the code bases. It is checked in the CI process.
158 After installing Fourmolu 0.12, there are some makefile targets to help formatting
159 the code base.
162 * `make style` - Format the `Cabal`, `Cabal-syntax` and `cabal-install` directories.
163 * `make style-modified` - Format files modified in the current tree.
164 * `make style-commit COMMIT=<ref>` - Format files modified between HEAD and the given reference.
168 Other Conventions
169 -----------------
171 * Format your commit messages [in the standard way](https://chris.beams.io/posts/git-commit/#seven-rules).
173 * A lot of Cabal does not have top-level comments.  We are trying to
174   fix this.  If you add new top-level definitions, please Haddock them;
175   and if you spend some time understanding what a function does, help
176   us out and add a comment.  We'll try to remind you during code review.
178 * If you do something tricky or non-obvious, add a comment.
180 * For local imports (Cabal module importing Cabal module), import lists
181   are NOT required (although you may use them at your discretion.)  For
182   third-party and standard library imports, please use either qualified imports
183   or explicit import lists.
185 * You can use basically any GHC extension supported by a GHC in our
186   support window, except Template Haskell, which would cause
187   bootstrapping problems in the GHC compilation process.
189 * Our GHC support window is five years for the Cabal library and three
190   years for cabal-install: that is, the Cabal library must be
191   buildable out-of-the-box with the dependencies that shipped with GHC
192   for at least five years.  GitHub Actions checks this, so most
193   developers submit a PR to see if their code works on all these
194   versions of GHC.  `cabal-install` must also be buildable on all
195   supported GHCs, although it does not have to be buildable
196   out-of-the-box. Instead, the `cabal-install/bootstrap.sh` script
197   must be able to download and install all of the dependencies (this
198   is also checked by CI). Also, self-upgrade to the latest version
199   (i.e. `cabal install cabal-install`) must work with all versions of
200   `cabal-install` released during the last three years.
202 * `Cabal` has its own Prelude, in `Distribution.Compat.Prelude`,
203   that provides a compatibility layer and exports some commonly
204   used additional functions. Use it in all new modules.
206 * As far as possible, please do not use CPP. If you must use it,
207   try to put it in a `Compat` module, and minimize the amount of code
208   that is enclosed by CPP.  For example, prefer:
209   ```
210   f :: Int -> Int
211   #ifdef mingw32_HOST_OS
212   f = (+1)
213   #else
214   f = (+2)
215   #endif
216   ```
218   over:
219   ```
220   #ifdef mingw32_HOST_OS
221   f :: Int -> Int
222   f = (+1)
223   #else
224   f :: Int -> Int
225   f = (+2)
226   #endif
227   ```
229 GitHub Ticket Conventions
230 -------------------
232 Each major `Cabal`/`cabal-install` release (e.g. 3.4, 3.6, etc.) has a
233 corresponding GitHub Project and milestone. A ticket is included in a release's
234 project if the release managers are tentatively planning on including a fix for
235 the ticket in the release, i.e. if they are actively seeking someone to work on
236 the ticket.
238 By contrast, a ticket is milestoned to a given release if we are open to
239 accepting a fix in that release, i.e. we would very much appreciate someone
240 working on it, but are not committing to actively sourcing someone to work on
243 GitHub Pull Request Conventions
244 -------------------
246 Every (non-backport) pull request has to go through a review and get 2
247 approvals. After this is done, the author of the pull request is expected to add
248 any final touches they deem important and put the `merge me` label on the pull
249 request. If the author lacks permissions to apply labels, they are welcome to
250 explicitly signal the merge intent on the discussion thread of the pull request,
251 at which point others (e.g., reviewers) apply the label. Merge buttons are
252 reserved for exceptional situations, e.g., CI fixes being iterated on or
253 backports/patches that need to be expedited for a release.
255 Currently there is a 2 day buffer for potential extra feedback between the last
256 update of a pull request (e.g. a commit, a rebase, an addition of the `merge me`
257 label) and the moment the Mergify bot picks up the pull request for a merge.
259 If your pull request consists of several commits, consider using `squash+merge
260 me` instead of `merge me`: the Mergify bot will squash all the commits into one
261 and concatenate the commit messages of the commits before merging.
263 There is also a `merge+no rebase` label. Use this very sparingly, as not rebasing
264 severely complicates Git history. It is intended for special circumstances, as when
265 the PR branch cannot or should not be modified. If you have any questions about it,
266 please ask us.
268 Changelog
269 ---------
271 When opening a pull request with a user-visible change, you should write one changelog entry
272 (or more in case of multiple independent changes) — the information will end up in
273 our release notes.
275 Changelogs for the next release are stored in the `changelog.d` directory.
276 The files follow a simple key-value format similar to the one for `.cabal` files.
277 Free-form text fields (`synopsis` and `description`) allow Markdown markup — please,
278 use markup to make our release notes more readable.
280 Here's an example:
282 ```cabal
283 synopsis: Add feature xyz
284 packages: cabal-install
285 prs: #0000
286 issues: #0000 #0000
287 significance: significant
289 description: {
291 - Detail number 1
292 - Detail number 2
297 Only the `synopsis` field is actually required, but you should also set the others where applicable.
299 | Field          | Description                                                                                                        |
300 | -----          | -----------                                                                                                        |
301 | `synopsis`     | Brief description of the change. Often just the pr title.                                                          |
302 | `description`  | Longer description, with a list of sub-changes. Not needed for small/atomic changes.                               |
303 | `packages`     | Packages affected by the change (`cabal-install`, `Cabal`...). Omit if it's an overarching or non-package change.  |
304 | `prs`          | Space-separated hash-prefixed pull request numbers containing the change (usually just one).                       |
305 | `issues`       | Space-separated hash-prefixed issue numbers that the change fixes/closes/affects.                                  |
306 | `significance` | Set to `significant` if the change is significant, that is if it warrants being put near the top of the changelog. |
308 You can find a large number of real-world examples of changelog files
309 [here](https://github.com/haskell/cabal/tree/bc83de27569fda22dbe1e10be1a921bebf4d3430/changelog.d).
311 At release time, the entries will be merged with
312 [this tool](https://github.com/fgaz/changelog-d).
314 In addition, if you're changing the `.cabal` file format specification you should
315 add an entry in `doc/file-format-changelog.rst`.
317 Communicating
318 -------------
320 There are a few main venues of communication:
322 * Most developers subscribe to receive messages from [all issues](https://github.com/haskell/cabal/issues); issues can be used to [open discussion](https://github.com/haskell/cabal/issues?q=is%3Aissue+is%3Aopen+custom+label%3A%22type%3A+discussion%22).  If you know someone who should hear about a message, CC them explicitly using the @username GitHub syntax.
324 * For more organizational concerns, the [mailing
325   list](http://www.haskell.org/mailman/listinfo/cabal-devel) is used.
327 * Many developers idle on `#hackage` on [`irc.libera.chat`](https://libera.chat). The `#ghc` channel is also a decently good bet.
328   * You can join the channel using a web client, even anonymously: https://web.libera.chat/#hackage
329   * Alternatively you can join it using [matrix](https://matrix.org/): https://matrix.to/#/#hackage:libera.chat
331 Releases
332 --------
334 Notes for how to make a release are at the
335 wiki page ["Making a release"](https://github.com/haskell/cabal/wiki/Making-a-release).
336 Currently, [@emilypi](https://github.com/emilypi), [@fgaz](https://github.com/fgaz) and [@Mikolaj](https://github.com/Mikolaj) have access to
337 `haskell.org/cabal`, and [@Mikolaj](https://github.com/Mikolaj) is the point of contact for getting
338 permissions.
340 API Documentation
341 -----------------
343 Auto-generated API documentation for the `master` branch of Cabal is automatically uploaded here: http://haskell.github.io/cabal-website/doc/html/Cabal/.
345 ## Issue triage [![Open Source Helpers](https://www.codetriage.com/haskell/cabal/badges/users.svg)](https://www.codetriage.com/haskell/cabal)
347 You can contribute by triaging issues which may include reproducing bug reports or asking for vital information, such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to cabal on CodeTriage](https://www.codetriage.com/haskell/cabal).
349 Hackage Revisions
350 -----------------
352 We are reactive rather than proactive with revising bounds on our dependencies
353 for code already released on Hackage. If you would benefit from a version bump,
354 please, open a ticket and get familiar with
355 [our revision policy](https://github.com/haskell/cabal/issues/9531#issuecomment-1866930240).
357 The burden of proof that the bump is harmless remains with you, but we have a CI
358 setup to show that our main pipeline ("Validate") is fine with the bump. To use
359 it, someone with enough permissions needs to go on the
360 [Validate workflow page](https://github.com/haskell/cabal/actions/workflows/validate.yml)
361 and dispatch it manually by clicking "Run workflow".
363 Running workflow manually as discussed above requires you to supply two inputs:
365 > allow-newer line
366 > constraints line
368 Going via an example, imagine that Cabal only allows `tar` or version less then
369 or equal to 0.6, and you want to bump it to 0.6. Then, to show that Validate
370 succeeds with `tar` 0.6, you should input 
372 - `tar` to the "allow-newer line"
373 - `tar ==0.6` to the "constraints line"
375 Hopefully, running the Validate pipeline with these inputs succeeds and you
376 supply the link to the run in the ticket about bumping the bound and making a revision.
378 If interested in technical details, refer to the parts of `validate.yml` that
379 mention `hackage-revisions`.