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

[Internal] Fix tagging workflow to identify last release properly #4437

Merged
merged 8 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .release_metadata.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"timestamp": "2025-01-16 13:55:53"
"timestamp": "2025-01-27 14:59:20"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put a timezone to avoid ambiguity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

}
14 changes: 7 additions & 7 deletions tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import subprocess
import time
import json
from datetime import datetime
from datetime import datetime, timezone

NEXT_CHANGELOG_FILE_NAME = "NEXT_CHANGELOG.md"
CHANGELOG_FILE_NAME = "CHANGELOG.md"
Expand Down Expand Up @@ -127,7 +127,7 @@ def clean_next_changelog(package_path: str) -> None:
content = file.read()

# Remove content between ### sections
cleaned_content = re.sub(r'(### [^\n]+\n)\n*([^#]+)', r'\1\n', content)
cleaned_content = re.sub(r'(### [^\n]+\n).*?(?=(###|$))', r'\1\n', content)
# Ensure there is exactly one empty line before each section
cleaned_content = re.sub(r'(\n*)(###[^\n]+)', r'\n\n\2', cleaned_content)
# Find the version number
Expand Down Expand Up @@ -160,19 +160,19 @@ def get_previous_tag_info(package: Package) -> Optional[TagInfo]:
changelog = f.read()

# Extract the latest release section using regex
match = re.search(r"## Release v[\d\.]+.*?(?=\n## (\[Release\] )?Release v|\Z)", changelog, re.S)
match = re.search(r"## (\[Release\] )?Release v[\d\.]+.*?(?=\n## (\[Release\] )?Release v|\Z)", changelog, re.S)

# E.g., for new packages.
if not match:
return None

latest_release = match.group(0)
version_match = re.search(r'## Release v(\d+\.\d+\.\d+)', latest_release)
version_match = re.search(r'## (\[Release\] )?Release v(\d+\.\d+\.\d+)', latest_release)

if not version_match:
raise Exception("Version not found in the changelog")

return TagInfo(package=package, version=version_match.group(1), content=latest_release)
return TagInfo(package=package, version=version_match.group(2), content=latest_release)


def get_next_tag_info(package: Package) -> Optional[TagInfo]:
Expand Down Expand Up @@ -304,13 +304,13 @@ def push_changes() -> None:

# Create the release metadata file
file_name = os.path.join(os.getcwd(), ".release_metadata.json")
metadata = {"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
metadata = {"timestamp": datetime.now(tz=timezone.UTC).strftime("%Y-%m-%d %H:%M:%S%Z")}
with open(file_name, "w") as f:
json.dump(metadata, f, indent=4)

# Commit the changes
subprocess.check_output(['git', 'add', '--all']) # Stage all changes
subprocess.check_output(['git', 'commit', '-m', '"Release"']) # Commit with message "Release"
subprocess.check_output(['git', 'commit', '-m', 'Release']) # Commit with message "Release"

# Push the changes
subprocess.check_output(['git', 'push']) # Step 3: Push the commit to the remote
Expand Down
Loading