a8trejo vor 1 Jahr
Ursprung
Commit
5eafdbcc57

+ 57 - 0
.github/scripts/get_prev_version_refs.py

@@ -0,0 +1,57 @@
+import os
+import re
+import subprocess
+
+def run_git_command(command):
+    try:
+        result = subprocess.getoutput(command)
+        print(f"Git Command: {command}")
+        print(f"Git Output: {result}")
+        return result
+    except subprocess.CalledProcessError as e:
+        print(f"Error running command: {e}")
+        print(f"stderr: {e.stderr}")
+        return None
+
+def parse_merge_commit(line):
+    # Parse merge commit messages like:
+    # "355dc82 Merge pull request #71 from RooVetGit/better-error-handling"
+    pattern = r"([a-f0-9]+)\s+Merge pull request #(\d+) from (.+)"
+    match = re.match(pattern, line)
+    if match:
+        sha, pr_number, branch = match.groups()
+        return {
+            'sha': sha,
+            'pr_number': pr_number,
+            'branch': branch
+        }
+    return None
+
+def get_version_refs():
+    # Get the merge commits with full message
+    command = 'git log --merges --pretty=oneline -n 3'
+    result = run_git_command(command)
+    
+    if result:
+        commits = result.split('\n')
+        if len(commits) >= 3:
+            # Parse HEAD~1 (PR to generate notes for)
+            head_info = parse_merge_commit(commits[1])
+            # Parse HEAD~2 (previous PR to compare against)
+            base_info = parse_merge_commit(commits[2])
+            
+            if head_info and base_info:
+                # Set output for GitHub Actions
+                with open(os.environ['GITHUB_OUTPUT'], 'a') as gha_outputs:
+                    gha_outputs.write(f"head_ref={head_info['sha']}\n")
+                    gha_outputs.write(f"base_ref={base_info['sha']}")
+                
+                print(f"Head ref (PR #{head_info['pr_number']}): {head_info['sha']}")
+                print(f"Base ref (PR #{base_info['pr_number']}): {base_info['sha']}")
+                return head_info, base_info
+    
+    print("Could not find or parse sufficient merge history")
+    return None, None
+
+if __name__ == "__main__":
+    head_info, base_info = get_version_refs()

+ 8 - 2
.github/workflows/changeset-ai-releases.yml

@@ -13,7 +13,7 @@ on:
 
 env:
   REPO_PATH: ${{ github.repository }}
-  GIT_REF: ${{ github.head_ref }}
+  GIT_REF: ${{ github.event.pull_request.head.sha }}
 
 jobs:
   # Job 1: Create version bump PR when changesets are merged to main
@@ -101,6 +101,11 @@ jobs:
         id: ai_prompt
         run: python .github/scripts/release-notes-prompt.py
 
+      # Get previous version refs, GITHUB_OUTPUT: 'BASE_REF' and 'HEAD_REF'
+      - name: Get Previous Version Refs
+        id: version_refs
+        run: python .github/scripts/get_prev_version_refs.py
+
       # Generate release notes using OpenAI if not already edited, GITHUB_OUTPUT: 'RELEASE_NOTES' and 'OPENAI_PROMPT'
       - name: AI Release Notes
         if: ${{ !contains(github.event.pull_request.labels.*.name, 'openai-edited') }}
@@ -111,7 +116,8 @@ jobs:
           OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
           model_name: gpt-4o-mini
           repo_path: ${{ env.REPO_PATH }}
-          git_ref: ${{ env.GIT_REF }}
+          base_ref: ${{ steps.version_refs.outputs.base_ref }}
+          head_ref: ${{ steps.version_refs.outputs.head_ref }}
           custom_prompt: ${{ steps.ai_prompt.outputs.BASE_PROMPT }}
 
       # Update CHANGELOG.md with AI-generated notes

+ 2 - 1
.gitignore

@@ -9,4 +9,5 @@ node_modules
 roo-cline-*.vsix
 
 # Local prompts
-prompts
+prompts
+.clinerules