Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a task to create the GitHub release #30322

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tasks/libs/ciproviders/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
52 changes: 52 additions & 0 deletions tasks/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
kacper-murzyn marked this conversation as resolved.
Show resolved Hide resolved

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}")
1 change: 1 addition & 0 deletions tasks/requirements_release_tasks.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
atlassian-python-api==3.41.3
yattag==1.15.2
reno==3.5.0
pandoc==2.4
Loading