From c78a33d039b7c0ab7a27b10abf53b39c990ed705 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 1 Sep 2024 00:32:47 +0200 Subject: [PATCH] Update tag.yml (#103) --- .github/workflows/tag.yml | 73 ++------------------------------------- 1 file changed, 3 insertions(+), 70 deletions(-) diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 051f8d9ecc..6b2c198da5 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -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