Debian Codegraph @

docs/contributing/release_process.md

raw
1 # Release process
2
3 _Black_ has had a lot of work done into standardizing and automating its release
4 process. This document sets out to explain how everything works and how to release
5 _Black_ using said automation.
6
7 ## Release cadence
8
9 **We aim to release whatever is on `main` every 1-2 months.** This ensures merged
10 improvements and bugfixes are shipped to users reasonably quickly, while not massively
11 fracturing the user-base with too many versions. This also keeps the workload on
12 maintainers consistent and predictable.
13
14 If there's not much new on `main` to justify a release, it's acceptable to skip a
15 month's release. Ideally January releases should not be skipped because as per our
16 [stability policy](labels/stability-policy), the first release in a new calendar year
17 may make changes to the _stable_ style. While the policy applies to the first release
18 (instead of only January releases), confining changes to the stable style to January
19 will keep things predictable (and nicer) for users.
20
21 Unless there is a serious regression or bug that requires immediate patching, **there
22 should not be more than one release per month**. While version numbers are cheap,
23 releases require a maintainer to both commit to do the actual cutting of a release, but
24 also to be able to deal with the potential fallout post-release. Releasing more
25 frequently than monthly nets rapidly diminishing returns.
26
27 ## Cutting a release
28
29 **You must have `write` permissions for the _Black_ repository to cut a release.**
30
31 The 10,000 foot view of the release process is that you prepare a release PR and then
32 publish a [GitHub Release]. This triggers [release automation](#release-workflows) that
33 builds all release artifacts and publishes them to the various platforms we publish to.
34
35 We now have a `scripts/release.py` script to help with cutting the release PRs.
36
37 - `python3 scripts/release.py --help` is your friend.
38 - `release.py` has only been tested in Python 3.12+ (so get with the times :D)
39
40 To cut a release:
41
42 1. Determine the release's version number
43 - **_Black_ follows the [CalVer] versioning standard using the `YY.M.N` format**
44 - So unless there already has been a release during this month, `N` should be `0`
45 - Example: the first release in January, 2026 → `26.1.0`
46 - `release.py` will calculate this and log it to stdout for your copy-paste pleasure
47 1. Double-check that no changelog entries since the last release were put in the wrong
48 section (e.g., run `git diff origin/stable CHANGES.md`)
49 1. File a PR editing `CHANGES.md` and the docs to version the latest changes
50 - Run `python3 scripts/release.py [--debug]` to generate most changes
51 1. If `release.py` fails manually edit; otherwise, yay, skip this step!
52 1. Replace the `## Unreleased` header with the version number
53 1. Remove any empty sections for the current release
54 1. (_optional_) Read through and copy-edit the changelog (eg. by moving entries,
55 fixing typos, or rephrasing entries)
56 1. Update references to the latest version in
57 {doc}`/integrations/source_version_control` and
58 {doc}`/usage_and_configuration/the_basics`
59 - Example PR: [GH-4563]
60 1. Once the release PR is merged, wait until all CI passes
61 - If CI does not pass, **stop** and investigate the failure(s) as generally we'd want
62 to fix failing CI before cutting a release
63 1. [Draft a new GitHub Release][new-release]
64 1. Click `Choose a tag` and type in the version number, then select the
65 `Create new tag: YY.M.N on publish` option that appears
66 1. Verify that the new tag targets the `main` branch
67 1. Make sure the release title is set to the version (`YY.M.N`), as otherwise the
68 default title is the last commit's title
69 1. Copy and paste the _raw changelog Markdown_ for the current release into the
70 description box
71 1. Publish the GitHub Release, triggering [release automation](#release-workflows) that
72 will handle the rest
73 1. Once CI is done add + PR a new empty template for the next release to CHANGES.md
74 _(Template is able to be copy pasted from release.py should we fail)_
75 1. `python3 scripts/release.py --add-changes-template|-a [--debug]`
76 1. Should that fail, please return to copy + paste
77 1. At this point, you're basically done. It's good practice to go and [watch and verify
78 that all the release workflows pass][black-actions], although you will receive a
79 GitHub notification should something fail.
80 - If something fails, don't panic. Please go read the respective workflow's logs and
81 configuration file to reverse-engineer your way to a fix/solution.
82
83 Congratulations! You've successfully cut a new release of _Black_. Go and stand up and
84 take a break, you deserve it.
85
86 ```{important}
87 Once the release artifacts reach PyPI, you may see new issues being filed indicating
88 regressions. While regressions are not great, they don't automatically mean a hotfix
89 release is warranted. Unless the regressions are serious and impact many users, a hotfix
90 release is probably unnecessary.
91
92 In the end, use your best judgement and ask other maintainers for their thoughts.
93 ```
94
95 ## Release workflows
96
97 All of _Black_'s release automation uses [GitHub Actions]. All workflows are therefore
98 configured using YAML files in the `.github/workflows` directory of the _Black_
99 repository.
100
101 They are triggered by the publication of a [GitHub Release].
102
103 Below are descriptions of our release workflows.
104
105 ### build and publish
106
107 This is our main workflow. It builds an [sdist] and [wheels] to upload to PyPI where the
108 vast majority of users will download Black from. It's divided into three job groups:
109
110 #### sdist + pure wheel
111
112 This single job builds the sdist and pure Python wheel (i.e., a wheel that only contains
113 Python code) using [Hatch]. These artifacts are general-purpose and can be used on
114 basically any platform supported by Python.
115
116 #### generate wheels matrix / mypyc wheels (…)
117
118 We use [mypyc] to compile _Black_ into a CPython C extension for significantly improved
119 performance. Wheels built with mypyc are platform and Python version specific.
120 [Supported platforms are documented in the FAQ](labels/mypyc-support).
121
122 These matrix jobs use [cibuildwheel] which handles the complicated task of building C
123 extensions for many environments for us. Since building these wheels is slow, there are
124 multiple mypyc wheels jobs (hence the term "matrix") that build for a specific platform
125 (as noted in the job name in parentheses).
126
127 #### publish-hatch / publish-mypyc
128
129 These jobs upload the built sdist and all wheels to PyPI using [Trusted
130 publishing][trusted-publishing].
131
132 ### publish binaries
133
134 This workflow builds native executables for multiple platforms using [PyInstaller]. This
135 allows people to download the executable for their platform and run _Black_ without a
136 [Python runtime](https://wiki.python.org/moin/PythonImplementations) installed.
137
138 The created binaries are stored on the associated GitHub Release for download over _IPv4
139 only_ (GitHub still does not have IPv6 access 😢).
140
141 ### docker
142
143 This workflow uses the QEMU powered `buildx` feature of Docker to upload an `arm64` and
144 `amd64`/`x86_64` build of the official _Black_ Docker image™.
145
146 - _Currently this workflow uses an API Token associated with @cooperlees account_
147
148 ```{note}
149 This also runs on each push to `main`.
150 ```
151
152 ### post release
153
154 This workflow runs a few miscellaneous jobs related to repository maintenance.
155
156 #### update-stable
157
158 Updates the `stable` branch by force pushing it to the most recent tag. This saves us
159 from remembering to update the branch sometime after cutting the release.
160
161 #### new-changelog
162
163 Opens a new PR to add the "Unreleased" section back to the changelog. The PR is
164 intentionally not auto-merged, in case there's an issue and the release needs to be
165 re-cut.
166
167 [black-actions]: https://github.com/psf/black/actions
168 [calver]: https://calver.org
169 [cibuildwheel]: https://cibuildwheel.readthedocs.io/
170 [gh-4563]: https://github.com/psf/black/pull/4563
171 [github actions]: https://github.com/features/actions
172 [github release]: https://github.com/psf/black/releases
173 [hatch]: https://hatch.pypa.io/latest/
174 [mypyc]: https://mypyc.readthedocs.io/
175 [new-release]: https://github.com/psf/black/releases/new
176 [pyinstaller]: https://www.pyinstaller.org/
177 [sdist]:
178 https://packaging.python.org/en/latest/glossary/#term-source-distribution-or-sdist
179 [trusted-publishing]: https://docs.pypi.org/trusted-publishers/
180 [wheels]: https://packaging.python.org/en/latest/glossary/#term-wheel