diff --git a/tasks/libs/ciproviders/github_api.py b/tasks/libs/ciproviders/github_api.py index 73a54248cfd73..17860e68f08c6 100644 --- a/tasks/libs/ciproviders/github_api.py +++ b/tasks/libs/ciproviders/github_api.py @@ -370,6 +370,14 @@ def create_label(self, name, color, description=""): """ return self._repository.create_label(name, color, description) + def create_release(self, tag, message, draft=True): + return self._repository.create_git_release( + tag=tag, + name=tag, + message=message, + draft=draft, + ) + def get_github_teams(users): for user in users: diff --git a/tasks/release.py b/tasks/release.py index 57ed76ba1671f..bb7a232834f0b 100644 --- a/tasks/release.py +++ b/tasks/release.py @@ -1049,3 +1049,55 @@ def create_qa_cards(ctx, tag): return setup_ddqa(ctx) ctx.run(f"ddqa --auto create {version.previous_rc_version()} {tag} {get_labels(version)}") + + +@task +def create_github_release(_ctx, version, draft=True): + """ + Create a GitHub release for the given tag. + """ + import pandoc + + sections = ( + ("Agent", "CHANGELOG.rst"), + ("Datadog Cluster Agent", "CHANGELOG-DCA.rst"), + ) + + notes = [] + + for section, filename in sections: + text = pandoc.write(pandoc.read(file=filename), format="markdown_strict", options=["--wrap=none"]) + + header_found = False + lines = [] + + # Extract the section for the given version + for line in text.splitlines(): + # Move to the right section + if line.startswith("## " + version): + header_found = True + continue + + if header_found: + # Next version found, stop + if line.startswith("## "): + break + lines.append(line) + + # if we found the header, add the section to the final release note + if header_found: + notes.append(f"# {section}") + notes.extend(lines) + + if not notes: + print(f"No release notes found for {version}") + raise Exit(code=1) + + github = GithubAPI() + release = github.create_release( + version, + "\n".join(notes), + draft=draft, + ) + + print(f"Link to the release note: {release.html_url}") diff --git a/tasks/requirements_release_tasks.txt b/tasks/requirements_release_tasks.txt index 684ee2cb6cbfa..f4159a5204ad5 100644 --- a/tasks/requirements_release_tasks.txt +++ b/tasks/requirements_release_tasks.txt @@ -1,3 +1,4 @@ atlassian-python-api==3.41.3 yattag==1.15.2 reno==3.5.0 +pandoc==2.4