Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 42786d8

Browse files
author
David Robertson
authored
Create dependabot changelogs at release time (#15481)
* Ditch dependabot changelog workflow * Summarise dependabot commits in release script * Changelog * Update scripts-dev/release.py
1 parent 626bd75 commit 42786d8

File tree

4 files changed

+57
-57
lines changed

4 files changed

+57
-57
lines changed

.github/workflows/dependabot_changelog.yml

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

changelog.d/15481.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Create dependabot changelogs at release time.

docs/development/dependencies.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,17 @@ doesn't require poetry. (It's what we use in CI too). However, you could try
260260

261261
## ...handle a Dependabot pull request?
262262

263-
Synapse uses Dependabot to keep the `poetry.lock` file up-to-date. When it
264-
creates a pull request a GitHub Action will run to automatically create a changelog
265-
file. Ensure that:
263+
Synapse uses Dependabot to keep the `poetry.lock` and `Cargo.lock` file
264+
up-to-date with the latest releases of our dependencies. The changelog check is
265+
omitted for Dependabot PRs; the release script will include them in the
266+
changelog.
267+
268+
When reviewing a dependabot PR, ensure that:
266269

267270
* the lockfile changes look reasonable;
268271
* the upstream changelog file (linked in the description) doesn't include any
269272
breaking changes;
270-
* continuous integration passes (due to permissions, the GitHub Actions run on
271-
the changelog commit will fail, look at the initial commit of the pull request);
273+
* continuous integration passes.
272274

273275
In particular, any updates to the type hints (usually packages which start with `types-`)
274276
should be safe to merge if linting passes.

scripts-dev/release.py

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import urllib.request
2828
from os import path
2929
from tempfile import TemporaryDirectory
30-
from typing import Any, List, Optional
30+
from typing import Any, List, Match, Optional, Union
3131

3232
import attr
3333
import click
@@ -233,7 +233,7 @@ def _prepare() -> None:
233233
subprocess.check_output(["poetry", "version", new_version])
234234

235235
# Generate changelogs.
236-
generate_and_write_changelog(current_version, new_version)
236+
generate_and_write_changelog(synapse_repo, current_version, new_version)
237237

238238
# Generate debian changelogs
239239
if parsed_new_version.pre is not None:
@@ -814,7 +814,7 @@ class VersionSection:
814814

815815

816816
def generate_and_write_changelog(
817-
current_version: version.Version, new_version: str
817+
repo: Repo, current_version: version.Version, new_version: str
818818
) -> None:
819819
# We do this by getting a draft so that we can edit it before writing to the
820820
# changelog.
@@ -827,6 +827,10 @@ def generate_and_write_changelog(
827827
new_changes = new_changes.replace(
828828
"No significant changes.", f"No significant changes since {current_version}."
829829
)
830+
new_changes += build_dependabot_changelog(
831+
repo,
832+
current_version,
833+
)
830834

831835
# Prepend changes to changelog
832836
with open("CHANGES.md", "r+") as f:
@@ -841,5 +845,47 @@ def generate_and_write_changelog(
841845
os.remove(filename)
842846

843847

848+
def build_dependabot_changelog(repo: Repo, current_version: version.Version) -> str:
849+
"""Summarise dependabot commits between `current_version` and `release_branch`.
850+
851+
Returns an empty string if there have been no such commits; otherwise outputs a
852+
third-level markdown header followed by an unordered list."""
853+
last_release_commit = repo.tag("v" + str(current_version)).commit
854+
rev_spec = f"{last_release_commit.hexsha}.."
855+
commits = list(git.objects.Commit.iter_items(repo, rev_spec))
856+
messages = []
857+
for commit in reversed(commits):
858+
if commit.author.name == "dependabot[bot]":
859+
message: Union[str, bytes] = commit.message
860+
if isinstance(message, bytes):
861+
message = message.decode("utf-8")
862+
messages.append(message.split("\n", maxsplit=1)[0])
863+
864+
if not messages:
865+
print(f"No dependabot commits in range {rev_spec}", file=sys.stderr)
866+
return ""
867+
868+
messages.sort()
869+
870+
def replacer(match: Match[str]) -> str:
871+
desc = match.group(1)
872+
number = match.group(2)
873+
return f"* {desc}. ([\\#{number}](https://github.com/matrix-org/synapse/issues/{number}))"
874+
875+
for i, message in enumerate(messages):
876+
messages[i] = re.sub(r"(.*) \(#(\d+)\)$", replacer, message)
877+
messages.insert(0, "### Updates to locked dependencies\n")
878+
return "\n".join(messages)
879+
880+
881+
@cli.command()
882+
@click.argument("since")
883+
def test_dependabot_changelog(since: str) -> None:
884+
"""Test building the dependabot changelog.
885+
886+
Summarises all dependabot commits between the SINCE tag and the current git HEAD."""
887+
print(build_dependabot_changelog(git.Repo("."), version.Version(since)))
888+
889+
844890
if __name__ == "__main__":
845891
cli()

0 commit comments

Comments
 (0)