Skip to content

Commit 7e05dc0

Browse files
authored
Merge pull request #77 from RooVetGit/chores/release-fixes
Release fixes
2 parents d034653 + 21f83f6 commit 7e05dc0

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import os
2+
import re
3+
import subprocess
4+
5+
def run_git_command(command):
6+
result = subprocess.getoutput(command)
7+
print(f"Git Command: {command}")
8+
print(f"Git Output: {result}")
9+
return result
10+
11+
def parse_merge_commit(line):
12+
# Parse merge commit messages like:
13+
# "355dc82 Merge pull request #71 from RooVetGit/better-error-handling"
14+
pattern = r"([a-f0-9]+)\s+Merge pull request #(\d+) from (.+)"
15+
match = re.match(pattern, line)
16+
if match:
17+
sha, pr_number, branch = match.groups()
18+
return {
19+
'sha': sha,
20+
'pr_number': pr_number,
21+
'branch': branch
22+
}
23+
return None
24+
25+
def get_version_refs():
26+
# Get the merge commits with full message
27+
command = 'git log --merges --pretty=oneline -n 3'
28+
result = run_git_command(command)
29+
30+
if result:
31+
commits = result.split('\n')
32+
if len(commits) >= 3:
33+
# Parse HEAD~1 (PR to generate notes for)
34+
head_info = parse_merge_commit(commits[1])
35+
# Parse HEAD~2 (previous PR to compare against)
36+
base_info = parse_merge_commit(commits[2])
37+
38+
if head_info and base_info:
39+
# Set output for GitHub Actions
40+
with open(os.environ['GITHUB_OUTPUT'], 'a') as gha_outputs:
41+
gha_outputs.write(f"head_ref={head_info['sha']}\n")
42+
gha_outputs.write(f"base_ref={base_info['sha']}")
43+
44+
print(f"Head ref (PR #{head_info['pr_number']}): {head_info['sha']}")
45+
print(f"Base ref (PR #{base_info['pr_number']}): {base_info['sha']}")
46+
return head_info, base_info
47+
48+
print("Could not find or parse sufficient merge history")
49+
return None, None
50+
51+
if __name__ == "__main__":
52+
head_info, base_info = get_version_refs()

.github/workflows/changeset-ai-releases.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313

1414
env:
1515
REPO_PATH: ${{ github.repository }}
16-
GIT_REF: ${{ github.head_ref }}
16+
GIT_REF: ${{ github.event.pull_request.head.sha }}
1717

1818
jobs:
1919
# Job 1: Create version bump PR when changesets are merged to main
@@ -101,6 +101,11 @@ jobs:
101101
id: ai_prompt
102102
run: python .github/scripts/release-notes-prompt.py
103103

104+
# Get previous version refs, GITHUB_OUTPUT: 'BASE_REF' and 'HEAD_REF'
105+
- name: Get Previous Version Refs
106+
id: version_refs
107+
run: python .github/scripts/get_prev_version_refs.py
108+
104109
# Generate release notes using OpenAI if not already edited, GITHUB_OUTPUT: 'RELEASE_NOTES' and 'OPENAI_PROMPT'
105110
- name: AI Release Notes
106111
if: ${{ !contains(github.event.pull_request.labels.*.name, 'openai-edited') }}
@@ -111,7 +116,8 @@ jobs:
111116
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
112117
model_name: gpt-4o-mini
113118
repo_path: ${{ env.REPO_PATH }}
114-
git_ref: ${{ env.GIT_REF }}
119+
base_ref: ${{ steps.version_refs.outputs.base_ref }}
120+
head_ref: ${{ steps.version_refs.outputs.head_ref }}
115121
custom_prompt: ${{ steps.ai_prompt.outputs.BASE_PROMPT }}
116122

117123
# Update CHANGELOG.md with AI-generated notes

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ node_modules
99
roo-cline-*.vsix
1010

1111
# Local prompts
12-
prompts
12+
prompts
13+
.clinerules

0 commit comments

Comments
 (0)