Skip to content

Commit

Permalink
Merge pull request #11504 from marcusburghardt/release_helper_updates
Browse files Browse the repository at this point in the history
release_helper script updates
  • Loading branch information
Mab879 authored Feb 13, 2024
2 parents a7722d2 + 8117c9d commit 339ca9e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
8 changes: 6 additions & 2 deletions docs/release_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ While any task can be performed manually, it is highly recommended to use the `r
The script interacts with the GitHub API, so an [API token](https://github.com/settings/tokens) is required for most tasks.
Instructions for generating a GitHub API token can be found directly in the [GitHub documentation](https://docs.github.com/), but some hints are also provided by the script.

In short, these are the minimal scopes to enable in the API Token (classic):
- repo
- repo:status
- repo_deployment
- public_repo

The `release_helper.py` script can also be used to check the current status of the project regarding releases:

```bash
Expand Down Expand Up @@ -36,8 +42,6 @@ This script was created targeting automation of boring tasks and reduction of hu

There is still space for improvement and any contribution is welcome. Here are some ideas to start contributing:
* Include an option to automate the process of updating the **stable** branch
* Improve the messages to include the name of maintainer
* Thanks [Matthew](https://github.com/ComplianceAsCode/content/pull/10076#discussion_r1165956665) for this idea.
* Introduce a checklist of steps during the release
* Something similar to **stats** but related to the steps in process.
* Some steps depend on other steps and may be concluded after some days. It would be great to know precisely in which step of the process we are.
Expand Down
34 changes: 27 additions & 7 deletions utils/release_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def create_ini_file_template(creds_file):
with open(new_creds_file, mode='w', encoding='utf-8') as file:
file.write(
'[DEFAULT]\n'
'github_token = <generate your token in https://github.com/settings/tokens>\n')
'github_token = <generate your token in https://github.com/settings/tokens>\n'
'# Include these scopes: "repo:status", "repo_deployment" and "public_repo"')
print(f'Great! {new_creds_file} was created! Edit it to include your personal token.')
except Exception as e:
print(f'Error: {e}')
Expand Down Expand Up @@ -240,10 +241,15 @@ def create_repo_milestone(repo, name) -> None:
latest_release = get_latest_release(repo)
estimated_release_date = get_next_release_date(latest_release.published_at)
if get_confirmation(f'Are you sure about creating the "{name}" milestone?'):
future_release_date = get_next_release_date(estimated_release_date)
future_stabilization_date = get_next_stabilization_date(future_release_date)
formatted_date_stabilization = get_date_for_message(future_stabilization_date)
milestone_description = (
f'Milestone for the release {name}'
f'Stabilization phase starts on {formatted_date_stabilization}')
try:
repo.create_milestone(
title=name, description=f'Milestone for the release {name}',
due_on=estimated_release_date)
title=name, description=milestone_description, due_on=estimated_release_date)
except Exception as e:
print(f'Error: {e}')
exit(1)
Expand Down Expand Up @@ -333,8 +339,8 @@ def get_next_stabilization_date(release_date) -> datetime:


def get_next_release_date(latest_release_date) -> datetime:
two_months_ahead = latest_release_date + timedelta(days=60)
return get_friday_that_follows(two_months_ahead)
three_months_ahead = latest_release_date + timedelta(days=90)
return get_friday_that_follows(three_months_ahead)


def is_next_release_in_progress(repo) -> bool:
Expand Down Expand Up @@ -362,6 +368,13 @@ def get_date_for_message(date) -> datetime:
return date.strftime("%B %d, %Y")


def get_git_config_username() -> str:
user_name = subprocess.run(
['git', 'config', 'user.name'],
capture_output=True, text=True, cwd=get_repo_root_path())
return user_name.stdout


def get_release_highlights(release) -> str:
highlights = []
for line in release.body.split('\r\n'):
Expand All @@ -387,6 +400,8 @@ def get_release_start_message(repo) -> str:
future_stabilization_date = get_next_stabilization_date(future_release_date)
future_date_stabilization = get_date_for_message(future_stabilization_date)

message_author = get_git_config_username()

template = f'''
Subject: stabilization of v{next_release_version}
Expand All @@ -403,7 +418,9 @@ def get_release_start_message(repo) -> str:
The next version, {future_version}, is scheduled to be released on {future_date},
with the stabilization phase starting on {future_date_stabilization}.
Regards,'''
Regards,
{message_author}'''
return template


Expand All @@ -414,6 +431,7 @@ def get_release_end_message(repo) -> str:
last_commit = get_contributors_last_commit()
new_contributors = get_new_contributors(last_commit)
released_version = get_latest_version(repo)
message_author = get_git_config_username()

for asset in latest_release.get_assets():
if asset.content_type == 'application/x-bzip2':
Expand Down Expand Up @@ -453,7 +471,9 @@ def get_release_end_message(repo) -> str:
Thank you to everyone who contributed!
Regards,'''
Regards,
{message_author}'''
return template


Expand Down

0 comments on commit 339ca9e

Please sign in to comment.