application-services/automation/prepare-release.py

118 строки
3.9 KiB
Python
Исходник Постоянная ссылка Обычный вид История

2020-03-05 01:48:50 +03:00
#!/usr/bin/env python3
# Purpose: Prepare an Application-Services release
# Dependencies: yaml
# Usage: ./automation/prepare-release.py
2020-03-05 01:48:50 +03:00
from datetime import datetime
import webbrowser
from shared import (RefNames, get_moz_remote, step_msg, fatal_err, run_cmd_checked,
ensure_working_tree_clean, check_output)
2020-03-05 01:48:50 +03:00
# Constants
VERSION_FILE = "version.txt"
2020-03-05 01:48:50 +03:00
CHANGELOG_FILE = "CHANGELOG.md"
# 1. Figure out which remote to push to
moz_remote = get_moz_remote()
2020-03-05 01:48:50 +03:00
# 2. Figure out the current version
with open(VERSION_FILE, "r") as stream:
cur_version = stream.read().strip()
major_version_number = int(cur_version.split('.')[0])
next_version_number = major_version_number + 1
release_version = f"{major_version_number}.0"
refs = RefNames(major_version_number, 0)
2020-03-05 01:48:50 +03:00
# 3. Create a new branch based on the branch we want to release from.
2020-03-05 01:48:50 +03:00
if check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip() != refs.main:
fatal_err(f"automation/prepare-release.py must be run from the {refs.main} branch")
ensure_working_tree_clean()
2020-03-05 01:48:50 +03:00
step_msg(f"Creating {refs.release}")
run_cmd_checked(["git", "checkout", "-b", refs.release])
run_cmd_checked(["git", "push", moz_remote, refs.release])
2020-03-05 01:48:50 +03:00
# 4. Create a PR to update the release branch
2020-03-05 01:48:50 +03:00
step_msg(f"checkout {refs.release_pr}")
run_cmd_checked(["git", "checkout", "-b", refs.release_pr])
2020-03-05 01:48:50 +03:00
step_msg(f"Bumping version in {VERSION_FILE}")
new_version = f"{major_version_number}.0"
2020-03-05 01:48:50 +03:00
with open(VERSION_FILE, "w") as stream:
stream.write(new_version)
2020-03-05 01:48:50 +03:00
step_msg(f"updating {CHANGELOG_FILE}")
2020-03-05 01:48:50 +03:00
with open(CHANGELOG_FILE, "r") as stream:
changelog = stream.read().splitlines()
2020-03-05 01:48:50 +03:00
if changelog[0] != f"# v{major_version_number}.0 (In progress)":
fatal_err(f"Unexpected first changelog line: {changelog[0]}")
2020-03-05 01:48:50 +03:00
today_date = datetime.today().strftime("%Y-%m-%d")
for i in range(10):
if changelog[i] == "[Full Changelog](In progress)":
changelog[i] = (
f"[Full Changelog](https://github.com/mozilla/application-services/compare/"
f"{refs.previous_version_tag}...{refs.version_tag})"
)
break
else:
fatal_err("Can't find `[Full Changelog](In progress)` line in CHANGELOG.md")
changelog[0] = f"# v{major_version_number}.0 (_{today_date}_)"
with open(CHANGELOG_FILE, "w") as stream:
stream.write("\n".join(changelog))
stream.write("\n")
step_msg("Creating a commit with the changes")
run_cmd_checked(["git", "add", CHANGELOG_FILE])
run_cmd_checked(["git", "add", VERSION_FILE])
run_cmd_checked(["git", "commit", "-m", f"Cut release v{release_version}"])
step_msg(f"Pushing {refs.release_pr}")
# 5. Create a PR to update main
step_msg(f"checkout {refs.main}")
run_cmd_checked(["git", "checkout", refs.main])
run_cmd_checked(["git", "checkout", "-b", refs.start_release_pr])
2020-03-05 01:48:50 +03:00
step_msg(f"Bumping version in {VERSION_FILE}")
new_version = f"{next_version_number}.0a1"
with open(VERSION_FILE, "w") as stream:
stream.write(new_version)
step_msg(f"UPDATING {CHANGELOG_FILE}")
changelog[0:0] = [
f"# v{next_version_number}.0 (In progress)",
"",
"[Full Changelog](In progress)",
""
]
2020-03-05 01:48:50 +03:00
with open(CHANGELOG_FILE, "w") as stream:
stream.write("\n".join(changelog))
stream.write("\n")
2020-03-05 01:48:50 +03:00
step_msg("Creating a commit with the changes")
run_cmd_checked(["git", "add", CHANGELOG_FILE])
run_cmd_checked(["git", "commit", "-m", f"Start release v{next_version_number}"])
2020-03-05 01:48:50 +03:00
print()
response = input("Great! Would you like to push and open the two pull-requests? ([Y]/N)").lower()
2020-03-05 01:48:50 +03:00
if response != "y" and response != "" and response != "yes":
exit(0)
run_cmd_checked(["git", "push", moz_remote, refs.release_pr])
run_cmd_checked(["git", "push", moz_remote, refs.start_release_pr])
webbrowser.open_new_tab(f"https://github.com/mozilla/application-services/compare/{refs.release}...{refs.release_pr}")
webbrowser.open_new_tab(f"https://github.com/mozilla/application-services/compare/{refs.main}...{refs.start_release_pr}")
run_cmd_checked(["git", "checkout", refs.main])