Skip to content

Commit 329c269

Browse files
authored
Update Changeset Workflow (RooCodeInc#2531)
* Update Changeset Workflow * Remove RELEASE related content
1 parent a9617a1 commit 329c269

File tree

4 files changed

+123
-180
lines changed

4 files changed

+123
-180
lines changed

.changeset/.mighty-tools-remain.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

.github/scripts/overwrite_changeset_changelog.py

Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#!/usr/bin/env python3
2323

2424
import os
25-
import sys
2625

2726
CHANGELOG_PATH = os.environ.get("CHANGELOG_PATH", "CHANGELOG.md")
2827
VERSION = os.environ['VERSION']
@@ -32,72 +31,49 @@
3231
def overwrite_changelog_section(changelog_text: str, new_content: str):
3332
# Find the section for the specified version
3433
version_pattern = f"## {VERSION}\n"
35-
bracketed_version_pattern = f"## [{VERSION}]\n"
34+
unformmatted_prev_version_pattern = f"## {PREV_VERSION}\n"
3635
prev_version_pattern = f"## [{PREV_VERSION}]\n"
3736
print(f"latest version: {VERSION}")
3837
print(f"prev_version: {PREV_VERSION}")
3938

40-
# Try both unbracketed and bracketed version patterns
41-
version_index = changelog_text.find(version_pattern)
42-
if version_index == -1:
43-
version_index = changelog_text.find(bracketed_version_pattern)
44-
if version_index == -1:
45-
# If version not found, add it at the top (after the first line)
46-
first_newline = changelog_text.find('\n')
47-
if first_newline == -1:
48-
# If no newline found, just prepend
49-
return f"## [{VERSION}]\n\n{changelog_text}"
50-
return f"{changelog_text[:first_newline + 1]}## [{VERSION}]\n\n{changelog_text[first_newline + 1:]}"
51-
else:
52-
# Using bracketed version
53-
version_pattern = bracketed_version_pattern
54-
55-
notes_start_index = version_index + len(version_pattern)
56-
notes_end_index = changelog_text.find(prev_version_pattern, notes_start_index) if PREV_VERSION and prev_version_pattern in changelog_text else len(changelog_text)
39+
notes_start_index = changelog_text.find(version_pattern) + len(version_pattern)
40+
notes_end_index = changelog_text.find(prev_version_pattern, notes_start_index) if PREV_VERSION and (prev_version_pattern in changelog_text or unformmatted_prev_version_pattern in changelog_text) else len(changelog_text)
5741

5842
if new_content:
5943
return changelog_text[:notes_start_index] + f"{new_content}\n" + changelog_text[notes_end_index:]
6044
else:
6145
changeset_lines = changelog_text[notes_start_index:notes_end_index].split("\n")
62-
# Ensure we have at least 2 lines before removing them
63-
if len(changeset_lines) < 2:
64-
print("Warning: Changeset content has fewer than 2 lines")
65-
parsed_lines = "\n".join(changeset_lines)
66-
else:
67-
# Remove the first two lines from the regular changeset format, ex: \n### Patch Changes
68-
parsed_lines = "\n".join(changeset_lines[2:])
69-
updated_changelog = changelog_text[:notes_start_index] + parsed_lines + changelog_text[notes_end_index:]
70-
# Ensure version number is bracketed
71-
updated_changelog = updated_changelog.replace(f"## {VERSION}", f"## [{VERSION}]")
72-
return updated_changelog
46+
filtered_lines = []
47+
for line in changeset_lines:
48+
# If the previous line is a changeset format
49+
if len(filtered_lines) > 1 and filtered_lines[-1].startswith("### "):
50+
# Remove the last two lines from the filted_lines
51+
filtered_lines.pop()
52+
filtered_lines.pop()
53+
else:
54+
filtered_lines.append(line.strip())
7355

74-
try:
75-
print(f"Reading changelog from: {CHANGELOG_PATH}")
76-
with open(CHANGELOG_PATH, 'r') as f:
77-
changelog_content = f.read()
56+
# Prepend a new line to the first line of filtered_lines
57+
if filtered_lines:
58+
filtered_lines[0] = "\n" + filtered_lines[0]
7859

79-
print(f"Changelog content length: {len(changelog_content)} characters")
80-
print("First 200 characters of changelog:")
81-
print(changelog_content[:200])
82-
print("----------------------------------------------------------------------------------")
60+
# Print filted_lines wiht a "\n" at the end of each line
61+
for line in filtered_lines:
62+
print(line.strip())
63+
64+
parsed_lines = "\n".join(line for line in filtered_lines)
65+
updated_changelog = changelog_text[:notes_start_index] + parsed_lines + changelog_text[notes_end_index:]
66+
return updated_changelog
8367

84-
new_changelog = overwrite_changelog_section(changelog_content, NEW_CONTENT)
85-
86-
print("New changelog content:")
87-
print("----------------------------------------------------------------------------------")
88-
print(new_changelog)
89-
print("----------------------------------------------------------------------------------")
90-
91-
print(f"Writing updated changelog back to: {CHANGELOG_PATH}")
92-
with open(CHANGELOG_PATH, 'w') as f:
93-
f.write(new_changelog)
68+
with open(CHANGELOG_PATH, 'r') as f:
69+
changelog_content = f.read()
9470

95-
print(f"{CHANGELOG_PATH} updated successfully!")
71+
new_changelog = overwrite_changelog_section(changelog_content, NEW_CONTENT)
72+
# print("----------------------------------------------------------------------------------")
73+
# print(new_changelog)
74+
# print("----------------------------------------------------------------------------------")
75+
# Write back to CHANGELOG.md
76+
with open(CHANGELOG_PATH, 'w') as f:
77+
f.write(new_changelog)
9678

97-
except FileNotFoundError:
98-
print(f"Error: Changelog file not found at {CHANGELOG_PATH}")
99-
sys.exit(1)
100-
except Exception as e:
101-
print(f"Error updating changelog: {str(e)}")
102-
print(f"Current working directory: {os.getcwd()}")
103-
sys.exit(1)
79+
print(f"{CHANGELOG_PATH} updated successfully!")
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Changeset Converter
2+
run-name: Changeset Conversion
3+
4+
on:
5+
pull_request:
6+
types: [closed]
7+
8+
env:
9+
REPO_PATH: ${{ github.repository }}
10+
GIT_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || 'main' }}
11+
NODE_VERSION: 20.18.1
12+
13+
jobs:
14+
# Job 1: Create version bump PR when changesets are merged to main
15+
changeset-pr-version-bump:
16+
if: >
17+
github.event_name == 'pull_request' &&
18+
github.event.pull_request.merged == true &&
19+
github.event.pull_request.base.ref == 'main' &&
20+
github.actor != 'github-actions'
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: write
24+
pull-requests: write
25+
steps:
26+
- name: Git Checkout
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
ref: ${{ env.GIT_REF }}
31+
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: ${{ env.NODE_VERSION }}
36+
cache: "npm"
37+
38+
- name: Install Dependencies
39+
run: npm install changeset
40+
41+
# Check if there are any new changesets to process
42+
- name: Check for changesets
43+
id: check-changesets
44+
run: |
45+
NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ')
46+
echo "Changesets diff with previous version: $NEW_CHANGESETS"
47+
echo "new_changesets=$NEW_CHANGESETS" >> $GITHUB_OUTPUT
48+
49+
# Create version bump PR using changesets/action if there are new changesets
50+
- name: Create Changeset Pull Request
51+
if: steps.check-changesets.outputs.new_changesets != '0'
52+
uses: changesets/action@v1
53+
with:
54+
commit: "changeset version bump"
55+
title: "Changeset version bump"
56+
version: npm run version-packages # This performs the changeset version bump
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
60+
# Get current and previous versions to edit changelog entry
61+
- name: Get version
62+
id: get_version
63+
run: |
64+
VERSION=$(git show HEAD:package.json | jq -r '.version')
65+
echo "version=$VERSION" >> $GITHUB_OUTPUT
66+
PREV_VERSION=$(git show origin/main:package.json | jq -r '.version')
67+
echo "prev_version=$PREV_VERSION" >> $GITHUB_OUTPUT
68+
echo "version=$VERSION"
69+
echo "prev_version=$PREV_VERSION"
70+
71+
# Update CHANGELOG.md with proper format
72+
- name: Update Changelog Format
73+
env:
74+
VERSION: ${{ steps.get_version.outputs.version }}
75+
PREV_VERSION: ${{ steps.get_version.outputs.prev_version }}
76+
run: python .github/scripts/overwrite_changeset_changelog.py
77+
78+
# Commit and push changelog updates
79+
- name: Push Changelog updates to Pull Request
80+
run: |
81+
git config user.name "github-actions"
82+
git config user.email [email protected]
83+
echo "Running git add and commit..."
84+
git add CHANGELOG.md
85+
git commit -m "Updating CHANGELOG.md format"
86+
git status
87+
echo "--------------------------------------------------------------------------------"
88+
echo "Pushing to remote..."
89+
echo "--------------------------------------------------------------------------------"
90+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
91+
git push origin $CURRENT_BRANCH

.github/workflows/check-changeset.yml

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)