Skip to main content

Build a sphinx changelog from GitHub Releases

Project description

Sphinx Github Changelog: Build a sphinx changelog from GitHub Releases

Deployed to PyPI Deployed to PyPI GitHub Repository Continuous Integration Documentation Coverage MIT License Contributor Covenant

Sphinx-github-changelog is a Sphinx plugin that builds a changelog section based on a repository’s GitHub Releases content.

How ? (the short version)

In your Sphinx documentation conf.py:

extensions = [
    ...,  # your other extensions
    "sphinx_github_changelog",
]

In your documentation:

.. changelog::
    :changelog-url: https://your-project.readthedocs.io/en/stable/#changelog
    :github: https://github.com/you/your-project/releases/
    :pypi: https://pypi.org/project/your-project/

or more minimally (but not necessarily recommended):

.. changelog::

See the end result for this project on ReadTheDocs.

Why ?

On the way to continuous delivery, it’s important to be able to release easily. One of the criteria for easy releases is that the release doesn’t require a commit and a Pull Request. Release Pull Requests usually include 2 parts:

  • Changing the version

  • Updating the changelog (if you keep a changelog, let’s assume you do)

Commitless releases need a way to store the version and the changelog, as close as possible to the code, but actually not in the code.

Setting aside the “version” question, sphinx-github-changelog aims at providing a good way of managing the “changelog” part:

The best solution we’ve found so far for the changelog is to store it in the body of GitHub Releases. That’s very practical for maintainers, but it may not be the first place people will look for it. As far as we’ve seen, people expect the changelog to be:

  • in the repo, in CHANGELOG.rst,

  • in the built documentation.

Having the changelog in CHANGELOG.rst causes a few problems:

  • Either each PR adds its single line of changelog, but:

    • you’ll most probably run into countless merge conflicts,

    • the changelog won’t tell you which contribution was part of which release

    This reduces the interest for the whole thing.

  • Or your changelog is edited at release time. Maybe you’re using towncrier for fragment-based changelog, but you’re not doing commitless releases anymore. You could imagine that the release commit is done by your CI, but this can quickly become annoying, especially if you require Pull Requests.

But there is another way. Instead of providing the changelog, the CHANGELOG.rst file can hold a link to the changelog. This makes things much easier. sphinx-github-changelog encourages you to do that.

Reference documentation

Automatic Configuration

The extension can automatically detect the GitHub repository URL from your git remotes in this order:

  1. upstream remote

  2. origin remote

The GraphQL API and GitHub root URL are derived from this URL.

If for any reason, you’d rather provide the repository explicitly (e.g. the doc repo doesn’t match the repo you’re releasing from, or anything else), you can define the :github: attribute to the directive. See directive for details.

Authentication

The extension uses the GitHub GraphQL API to retrieve the changelog. This requires authentication using a GitHub API token.

Tokens can be read from (in this order):

  • sphinx_github_changelog_token in conf.py (please do NOT commit your secrets)

  • SPHINX_GITHUB_CHANGELOG_TOKEN environment variable

  • GITHUB_TOKEN environment variable

  • Your git configuration, using git’s credential system

  • The gh command, using the auth token command

When using GitHub Actions, you can pass a token explicitly as an environment variable:

- name: Build documentation
  run: make html
  env:
    SPHINX_GITHUB_CHANGELOG_TOKEN: ${{ github.token }}

If you’re not in one of the cases above (e.g. for ReadTheDocs, at least for the time being), you’ll need a personal access token. If the repository is public, the token doesn’t need any special access (you can uncheck everything). For private and internal repositories, the token must have repo scope (classic tokens) or contents: read access (fine-grained tokens).

Pass the token as the SPHINX_GITHUB_CHANGELOG_TOKEN (or GITHUB_TOKEN) environment variable. You can also set the token as sphinx_github_changelog_token in conf.py, but you should never commit secrets such as this.

Extension options (conf.py)

  • sphinx_github_changelog_token (optional): GitHub API token, if needed, see above (please do NOT commit your secrets).

The following options are useful in some cases, though most of the time, the corresponding values will be detected automatically from the :github: parameter passed to the directive:

  • sphinx_github_changelog_root_repo (optional): Root URL to the repository.

  • sphinx_github_changelog_graphql_url (optional): URL to GraphQL API.

Directive

.. changelog::
    :changelog-url: https://your-project.readthedocs.io/en/stable/changelog.html
    :github: https://github.com/you/your-project/releases/
    :pypi: https://pypi.org/project/your-project/

Attributes

  • github (optional): URL to the releases page of the repository. If not provided, auto-detected from your git remote, as described above.

  • changelog-url (optional): URL to the built version of your changelog. sphinx-github-changelog will display a link to your built changelog if the GitHub token is not provided (hopefully, this does not happen in your built documentation)

  • pypi (optional): URL to the PyPI page of the repository. This allows the changelog to display links to each PyPI release.

You’ll notice that each parameter here is not requested in the simplest form but as very specific URLs from which the program extracts the needed information. This is done on purpose. If people browse the unbuilt version of your documentation (e.g. on GitHub or PyPI directly), they’ll still be presented with links to the pages that contain the information they will need, instead of unhelping directives.

Check out the built version!

This Readme is also built as a Sphinx documentation, and it includes the changelog. Interested to see how it looks? Check it out on our ReadTheDocs space.

If you encounter a bug, or want to get in touch, you’re always welcome to open a ticket.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_github_changelog-2.1.1.tar.gz (70.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinx_github_changelog-2.1.1-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_github_changelog-2.1.1.tar.gz.

File metadata

  • Download URL: sphinx_github_changelog-2.1.1.tar.gz
  • Upload date:
  • Size: 70.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for sphinx_github_changelog-2.1.1.tar.gz
Algorithm Hash digest
SHA256 793936727b908248d2bdf6c0e072bd101f76d916f0f733b4fe778d4c645125db
MD5 b3cd347a195f2cd30158d03e2c08c7f0
BLAKE2b-256 e6bf061825f35c6e4aff26e636397f4810396d4ee95b91299008ba76ca51289b

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_github_changelog-2.1.1.tar.gz:

Publisher: ci.yml on ewjoachim/sphinx-github-changelog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sphinx_github_changelog-2.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_github_changelog-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 14dfbc878802dcb8bf719b146460090424e2f75c875e46085b125f3302704e2b
MD5 64b739afd52db1986fbc50133c825749
BLAKE2b-256 c722803386ded0b1f6fa5e26c8784b0ed14cb3d76cef748aee06708e1220ae0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_github_changelog-2.1.1-py3-none-any.whl:

Publisher: ci.yml on ewjoachim/sphinx-github-changelog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page