mirror of
https://gh.wpcy.net/https://github.com/WeblateOrg/weblate.git
synced 2026-04-27 19:34:10 +08:00
82 lines
2 KiB
Python
Executable file
82 lines
2 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import os
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
import requests
|
|
from ruamel.yaml import YAML
|
|
|
|
if len(sys.argv) != 2:
|
|
print("Usage: ./scripts/set-version VERSION")
|
|
sys.exit(1)
|
|
|
|
version = sys.argv[1]
|
|
|
|
|
|
def replace_file(name, search, replace):
|
|
with open(name) as handle:
|
|
content = handle.read()
|
|
|
|
content = re.sub(search, replace, content, flags=re.MULTILINE)
|
|
with open(name, "w") as handle:
|
|
handle.write(content)
|
|
|
|
|
|
def prepend_file(name, content):
|
|
with open(name) as handle:
|
|
content += handle.read()
|
|
|
|
with open(name, "w") as handle:
|
|
handle.write(content)
|
|
|
|
|
|
yaml = YAML()
|
|
with open(os.path.expanduser("~/.config/hub")) as handle:
|
|
config = yaml.load(handle.read())
|
|
|
|
# Get/create milestone
|
|
milestones_api = "https://api.github.com/repos/WeblateOrg/weblate/milestones"
|
|
api_auth = f"token {config['github.com'][0]['oauth_token']}"
|
|
headers = {"Authorization": api_auth, "Accept": "application/vnd.github.v3+json"}
|
|
response = requests.get(milestones_api, headers=headers)
|
|
milestone_url = None
|
|
for milestone in response.json():
|
|
if milestone["title"] == version:
|
|
milestone_url = milestone["html_url"]
|
|
|
|
if milestone_url is None:
|
|
response = requests.post(milestones_api, headers=headers, json={"title": version})
|
|
milestone_url = response.json()["html_url"]
|
|
|
|
# Set version in the files
|
|
replace_file("weblate/utils/version.py", "^VERSION =.*", f'VERSION = "{version}-dev"')
|
|
replace_file("docs/conf.py", "release =.*", f'release = "{version}"')
|
|
replace_file("setup.py", "version=.*", f'version="{version}",')
|
|
|
|
# Update changelog
|
|
title = f"Weblate {version}"
|
|
underline = "-" * len(title)
|
|
header = f"""{title}
|
|
{underline}
|
|
|
|
Not yet released.
|
|
|
|
`All changes in detail <{milestone_url}?closed=1>`__.
|
|
|
|
"""
|
|
prepend_file("docs/changes.rst", header)
|
|
|
|
subprocess.check_call(
|
|
[
|
|
"git",
|
|
"commit",
|
|
"-m",
|
|
f"Setting version to {version}",
|
|
"weblate/utils/version.py",
|
|
"docs/conf.py",
|
|
"docs/changes.rst",
|
|
"setup.py",
|
|
]
|
|
)
|