Skip to content

Commit

Permalink
Update tag.yml (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher authored Aug 31, 2024
1 parent 81da721 commit c78a33d
Showing 1 changed file with 3 additions and 70 deletions.
73 changes: 3 additions & 70 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,80 +64,13 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
pip install openai requests
pip install requests
- name: Publish new release
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN || secrets.GITHUB_TOKEN }}
CURRENT_TAG: ${{ github.event.inputs.tag_name }}
shell: python
run: |
import openai
import os
import requests
import json
import subprocess
# Retrieve environment variables
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
CURRENT_TAG = os.getenv('CURRENT_TAG')
# Check for required environment variables
if not all([OPENAI_API_KEY, GITHUB_TOKEN, CURRENT_TAG]):
raise ValueError("One or more required environment variables are missing.")
repo = os.getenv('GITHUB_REPOSITORY')
headers = {"Authorization": f"token {GITHUB_TOKEN}", "Accept": "application/vnd.github.v3.diff"}
# Get the previous tag
tags = subprocess.run(['git', 'tag', '--sort=-creatordate'], check=True, text=True, capture_output=True).stdout.split()
previous_tag = next((tag for tag in tags if tag != CURRENT_TAG), None)
if previous_tag:
# Get the diff between the tags
url = f"https://api.github.com/repos/{repo}/compare/{previous_tag}...{CURRENT_TAG}"
response = requests.get(url, headers=headers)
diff = response.text if response.status_code == 200 else f"Failed to get diff: {response.content}"
else:
diff = "This is the first release."
# Get summary
messages = [
{
"role": "system",
"content": "You are an Ultralytics AI assistant skilled in software development and technical communication. Your task is to summarize GitHub releases in a way that is detailed, accurate, and understandable to both expert developers and non-expert users. Focus on highlighting the key changes and their impact in simple and intuitive terms."
},
{
"role": "user",
"content": f"Summarize the updates made in the '{CURRENT_TAG}' tag, focusing on major changes, their purpose, and potential impact. Keep the summary clear and suitable for a broad audience. Add emojis to enliven the summary. Reply directly with a summary along these example guidelines, though feel free to adjust as appropriate:\n\n"
f"## 🌟 Summary (single-line synopsis)\n"
f"## 📊 Key Changes (bullet points highlighting any major changes)\n"
f"## 🎯 Purpose & Impact (bullet points explaining any benefits and potential impact to users)\n"
f"\n\nHere's the release diff:\n\n{diff[:300000]}",
}
]
client = openai.OpenAI(api_key=OPENAI_API_KEY)
completion = client.chat.completions.create(model="gpt-4-1106-preview", messages=messages)
summary = completion.choices[0].message.content.strip()
# Get the latest commit message
commit_message = subprocess.run(['git', 'log', '-1', '--pretty=%B'], check=True, text=True, capture_output=True).stdout.split("\n")[0].strip()
# Prepare release data
release = {
'tag_name': CURRENT_TAG,
'name': f"{CURRENT_TAG} - {commit_message}",
'body': summary,
'draft': False,
'prerelease': False
}
# Create the release on GitHub
release_url = f"https://api.github.com/repos/{repo}/releases"
release_response = requests.post(release_url, headers=headers, data=json.dumps(release))
if release_response.status_code == 201:
print(f'Successfully created release {CURRENT_TAG}')
else:
print(f'Failed to create release {CURRENT_TAG}: {release_response.content}')
curl -s "https://raw.githubusercontent.com/ultralytics/actions/main/utils/summarize_release.py" | python -
shell: bash

0 comments on commit c78a33d

Please sign in to comment.