Skip to content

Commit 2f2c060

Browse files
authored
Merge pull request #61 from RooVetGit/chores/changeset-releases
Changeset AI Releases and code guardrails
2 parents 70639ec + 558ee78 commit 2f2c060

17 files changed

+1942
-125
lines changed

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "restricted",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.github/pull_request_template.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!-- **Note:** Consider creating PRs as a DRAFT. For early feedback and self-review. -->
2+
## Description
3+
4+
## Type of change
5+
<!-- Please ignore options that are not relevant -->
6+
- [ ] Bug fix (non-breaking change which fixes an issue)
7+
- [ ] New feature
8+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
9+
- [ ] This change requires a documentation update
10+
11+
## How Has This Been Tested?
12+
<!-- Please describe the tests that you ran to verify your changes -->
13+
14+
## Checklist:
15+
<!-- Go over all the following points, and put an `x` in all the boxes that apply -->
16+
- [ ] My code follows the patterns of this project
17+
- [ ] I have performed a self-review of my own code
18+
- [ ] I have commented my code, particularly in hard-to-understand areas
19+
- [ ] I have made corresponding changes to the documentation
20+
21+
## Additional context
22+
<!-- Add any other context or screenshots about the pull request here -->
23+
24+
## Related Issues
25+
<!-- List any related issues here. Use the GitHub issue linking syntax: #issue-number -->
26+
27+
## Reviewers
28+
<!-- @mention specific team members or individuals who should review this PR -->
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""
2+
This script updates a specific version's release notes section in CHANGELOG.md with new content.
3+
4+
The script:
5+
1. Takes a version number, changelog path, and new content as input from environment variables
6+
2. Finds the section in the changelog for the specified version
7+
3. Replaces the content between the current version header and the next version header
8+
(or end of file if it's the latest version) with the new content
9+
4. Writes the updated changelog back to the file
10+
11+
Environment Variables:
12+
CHANGELOG_PATH: Path to the changelog file (defaults to 'CHANGELOG.md')
13+
VERSION: The version number to update notes for
14+
PREV_VERSION: The previous version number (optional)
15+
NEW_CONTENT: The new content to insert for this version
16+
"""
17+
18+
#!/usr/bin/env python3
19+
20+
import os
21+
22+
CHANGELOG_PATH = os.environ.get("CHANGELOG_PATH", "CHANGELOG.md")
23+
VERSION = os.environ['VERSION']
24+
PREV_VERSION = os.environ.get("PREV_VERSION", "")
25+
NEW_CONTENT = os.environ['NEW_CONTENT']
26+
27+
def overwrite_changelog_section(content: str):
28+
"""Replace a specific version section in the changelog content.
29+
30+
Args:
31+
content: The full changelog content as a string
32+
33+
Returns:
34+
The updated changelog content with the new section
35+
36+
Example:
37+
>>> content = "## 1.2.0\\nOld changes\\n## 1.1.0\\nOld changes"
38+
>>> NEW_CONTENT = "New changes"
39+
>>> overwrite_changelog_section(content)
40+
'## 1.2.0\\nNew changes\\n## 1.1.0\\nOld changes'
41+
"""
42+
# Find the section for the specified version
43+
version_pattern = f"## {VERSION}\n"
44+
print(f"latest version: {VERSION}")
45+
notes_start_index = content.find(version_pattern) + len(version_pattern)
46+
print(f"prev_version: {PREV_VERSION}")
47+
prev_version_pattern = f"## {PREV_VERSION}\n"
48+
notes_end_index = content.find(prev_version_pattern, notes_start_index) if PREV_VERSION and prev_version_pattern in content else len(content)
49+
return content[:notes_start_index] + f"{NEW_CONTENT}\n" + content[notes_end_index:]
50+
51+
with open(CHANGELOG_PATH, 'r') as f:
52+
content = f.read()
53+
54+
new_changelog = overwrite_changelog_section(content)
55+
56+
print(new_changelog)
57+
58+
# Write back to CHANGELOG.md
59+
with open(CHANGELOG_PATH, 'w') as f:
60+
f.write(new_changelog)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
This script extracts the release notes section for a specific version from CHANGELOG.md.
3+
4+
The script:
5+
1. Takes a version number and changelog path as input from environment variables
6+
2. Finds the section in the changelog for the specified version
7+
3. Extracts the content between the current version header and the next version header
8+
(or end of file if it's the latest version)
9+
4. Outputs the extracted release notes to GITHUB_OUTPUT for use in creating GitHub releases
10+
11+
Environment Variables:
12+
GITHUB_OUTPUT: Path to GitHub Actions output file
13+
CHANGELOG_PATH: Path to the changelog file (defaults to 'CHANGELOG.md')
14+
VERSION: The version number to extract notes for
15+
"""
16+
17+
#!/usr/bin/env python3
18+
19+
import sys
20+
import os
21+
import subprocess
22+
23+
GITHUB_OUTPUT = os.getenv("GITHUB_OUTPUT")
24+
CHANGELOG_PATH = os.environ.get("CHANGELOG_PATH", "CHANGELOG.md")
25+
VERSION = os.environ['VERSION']
26+
27+
def parse_changelog_section(content: str):
28+
"""Parse a specific version section from the changelog content.
29+
30+
Args:
31+
content: The full changelog content as a string
32+
33+
Returns:
34+
The formatted content for this version, or None if version not found
35+
36+
Example:
37+
>>> content = "## 1.2.0\\nChanges\\n## 1.1.0\\nOld changes"
38+
>>> parse_changelog_section(content)
39+
'Changes\\n'
40+
"""
41+
# Find the section for the specified version
42+
version_pattern = f"## {VERSION}\n"
43+
print(f"latest version: {VERSION}")
44+
notes_start_index = content.find(version_pattern) + len(version_pattern)
45+
prev_version = subprocess.getoutput("git show origin/main:package.json | grep '\"version\":' | cut -d'\"' -f4")
46+
print(f"prev_version: {prev_version}")
47+
prev_version_pattern = f"## {prev_version}\n"
48+
notes_end_index = content.find(prev_version_pattern, notes_start_index) if prev_version_pattern in content else len(content)
49+
50+
return content[notes_start_index:notes_end_index]
51+
52+
with open(CHANGELOG_PATH, 'r') as f:
53+
content = f.read()
54+
55+
formatted_content = parse_changelog_section(content)
56+
if not formatted_content:
57+
print(f"Version {VERSION} not found in changelog", file=sys.stderr)
58+
sys.exit(1)
59+
60+
print(formatted_content)
61+
62+
# Write the extracted release notes to GITHUB_OUTPUT
63+
with open(GITHUB_OUTPUT, "a") as gha_output:
64+
gha_output.write(f"release-notes<<EOF\n{formatted_content}\nEOF")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
This script generates a base prompt for OpenAI to create release notes.
3+
"""
4+
5+
#!/usr/bin/env python3
6+
7+
import os
8+
from datetime import datetime;
9+
from pytz import timezone
10+
11+
GITHUB_OUTPUT = os.getenv("GITHUB_OUTPUT")
12+
13+
TODAY = datetime.now(timezone('US/Eastern')).isoformat(sep=' ', timespec='seconds')
14+
15+
BASE_PROMPT = f"""Based on the following 'PR Information', please generate concise and informative release notes to be read by developers.
16+
Format the release notes with markdown, and always use this structure: a descriptive and very short title (no more than 8 words) with heading level 2, a paragraph with a summary of changes (no header), and if applicable, sections for '🚀 New Features & Improvements', '🐛 Bugs Fixed' and '🔧 Other Updates', with heading level 3, skip respectively the sections if not applicable.
17+
Finally include the following markdown comment with the PR merged date: <!-- PR_DATE: {TODAY} -->.
18+
Avoid being repetitive and focus on the most important changes and their impact, discard any mention of version bumps/updates, changeset files, environment variables or syntax updates.
19+
PR Information:"""
20+
21+
# Write the prompt to GITHUB_OUTPUT
22+
with open(GITHUB_OUTPUT, "a") as outputs_file:
23+
outputs_file.write(f"BASE_PROMPT<<EOF\n{BASE_PROMPT}\nEOF")

0 commit comments

Comments
 (0)