-
Notifications
You must be signed in to change notification settings - Fork 27
/
make_github_release.py
50 lines (40 loc) · 1.52 KB
/
make_github_release.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import requests
from write_appcast import get_latest_git_tag
version = get_latest_git_tag()
if version is None:
raise Exception("No git tag found")
repo_owner = "christofmuc"
repo_name = "KnobKraft-orm"
access_token = os.getenv('GITHUB_TOKEN')
# Markdown-formatted release notes
with open(os.path.join("release_notes", f"{version}.md"), 'r') as file:
release_notes = file.read()
# Create a release payload with the release notes
release_payload = {
"tag_name": version,
"name": f"{version}",
"body": release_notes,
"draft": False,
"prerelease": False
}
# Create the release via GitHub API
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/releases"
headers = {
"Authorization": f"Bearer {access_token}",
"Accept": "application/vnd.github.v3+json"
}
# Get existing releases
url_existing_releases = f"https://api.github.com/repos/{repo_owner}/{repo_name}/releases"
existing_releases = requests.get(url_existing_releases, headers=headers).json()
# Check if the release for this version already exists
existing_release = next((release for release in existing_releases if release['tag_name'] == version), None)
if not existing_release:
print("Creating a new release...")
response = requests.post(url, json=release_payload, headers=headers)
if response.status_code == 201:
print("Release created successfully.")
else:
print("Failed to create the release. Response status:", response.status_code)
else:
print("Found release {version}, skipping creation!")