2020-03-05 01:48:50 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# Purpose: Prepare an Application-Services release
|
|
|
|
# Dependencies: yaml
|
2023-04-25 02:37:36 +03:00
|
|
|
# Usage: ./automation/prepare-release.py
|
2020-03-05 01:48:50 +03:00
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
import webbrowser
|
|
|
|
|
2023-04-25 02:37:36 +03:00
|
|
|
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
|
2023-07-13 19:22:55 +03:00
|
|
|
VERSION_FILE = "version.txt"
|
2020-03-05 01:48:50 +03:00
|
|
|
CHANGELOG_FILE = "CHANGELOG.md"
|
|
|
|
|
2023-04-25 02:37:36 +03:00
|
|
|
# 1. Figure out which remote to push to
|
|
|
|
moz_remote = get_moz_remote()
|
2020-03-05 01:48:50 +03:00
|
|
|
|
2023-04-25 02:37:36 +03:00
|
|
|
# 2. Figure out the current version
|
2023-07-13 19:22:55 +03:00
|
|
|
with open(VERSION_FILE, "r") as stream:
|
|
|
|
cur_version = stream.read().strip()
|
2023-04-25 02:37:36 +03:00
|
|
|
|
|
|
|
major_version_number = int(cur_version.split('.')[0])
|
2023-06-07 16:34:51 +03:00
|
|
|
next_version_number = major_version_number + 1
|
2023-04-25 02:37:36 +03:00
|
|
|
release_version = f"{major_version_number}.0"
|
|
|
|
refs = RefNames(major_version_number, 0)
|
2020-03-05 01:48:50 +03:00
|
|
|
|
2023-04-25 02:37:36 +03:00
|
|
|
# 3. Create a new branch based on the branch we want to release from.
|
2020-03-05 01:48:50 +03:00
|
|
|
|
2023-04-25 02:37:36 +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
|
|
|
|
2023-04-25 02:37:36 +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
|
|
|
|
2023-04-25 02:37:36 +03:00
|
|
|
# 4. Create a PR to update the release branch
|
2020-03-05 01:48:50 +03:00
|
|
|
|
2023-04-25 02:37:36 +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
|
|
|
|
2023-07-13 19:22:55 +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
|
|
|
|
2023-07-13 19:22:55 +03:00
|
|
|
with open(VERSION_FILE, "w") as stream:
|
|
|
|
stream.write(new_version)
|
2020-03-05 01:48:50 +03:00
|
|
|
|
2023-04-25 02:37:36 +03:00
|
|
|
step_msg(f"updating {CHANGELOG_FILE}")
|
2020-03-05 01:48:50 +03:00
|
|
|
with open(CHANGELOG_FILE, "r") as stream:
|
2023-04-25 02:37:36 +03:00
|
|
|
changelog = stream.read().splitlines()
|
2020-03-05 01:48:50 +03:00
|
|
|
|
2023-04-25 02:37:36 +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")
|
|
|
|
|
2023-04-25 02:37:36 +03:00
|
|
|
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:
|
2023-07-13 19:22:55 +03:00
|
|
|
fatal_err("Can't find `[Full Changelog](In progress)` line in CHANGELOG.md")
|
2021-05-25 19:08:22 +03:00
|
|
|
|
2023-04-25 02:37:36 +03:00
|
|
|
changelog[0] = f"# v{major_version_number}.0 (_{today_date}_)"
|
|
|
|
with open(CHANGELOG_FILE, "w") as stream:
|
|
|
|
stream.write("\n".join(changelog))
|
2023-05-08 17:09:03 +03:00
|
|
|
stream.write("\n")
|
2021-05-25 19:08:22 +03:00
|
|
|
|
2023-07-13 19:22:55 +03:00
|
|
|
step_msg("Creating a commit with the changes")
|
2023-04-25 02:37:36 +03:00
|
|
|
run_cmd_checked(["git", "add", CHANGELOG_FILE])
|
2023-07-13 19:22:55 +03:00
|
|
|
run_cmd_checked(["git", "add", VERSION_FILE])
|
2023-04-25 02:37:36 +03:00
|
|
|
run_cmd_checked(["git", "commit", "-m", f"Cut release v{release_version}"])
|
2021-05-25 19:08:22 +03:00
|
|
|
|
2023-04-25 02:37:36 +03:00
|
|
|
step_msg(f"Pushing {refs.release_pr}")
|
2021-05-25 19:08:22 +03:00
|
|
|
|
2023-04-25 02:37:36 +03:00
|
|
|
# 5. Create a PR to update main
|
2021-05-25 19:08:22 +03:00
|
|
|
|
2023-04-25 02:37:36 +03:00
|
|
|
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
|
|
|
|
2023-07-13 19:22:55 +03:00
|
|
|
step_msg(f"Bumping version in {VERSION_FILE}")
|
|
|
|
new_version = f"{next_version_number}.0a1"
|
2023-05-08 19:20:40 +03:00
|
|
|
|
2023-07-13 19:22:55 +03:00
|
|
|
with open(VERSION_FILE, "w") as stream:
|
|
|
|
stream.write(new_version)
|
2023-05-08 19:20:40 +03:00
|
|
|
|
2023-04-25 02:37:36 +03:00
|
|
|
step_msg(f"UPDATING {CHANGELOG_FILE}")
|
|
|
|
changelog[0:0] = [
|
2023-06-07 16:34:51 +03:00
|
|
|
f"# v{next_version_number}.0 (In progress)",
|
2023-04-25 02:37:36 +03:00
|
|
|
"",
|
|
|
|
"[Full Changelog](In progress)",
|
|
|
|
""
|
|
|
|
]
|
2020-03-05 01:48:50 +03:00
|
|
|
with open(CHANGELOG_FILE, "w") as stream:
|
2023-04-25 02:37:36 +03:00
|
|
|
stream.write("\n".join(changelog))
|
2023-05-08 17:09:03 +03:00
|
|
|
stream.write("\n")
|
2020-03-05 01:48:50 +03:00
|
|
|
|
2023-07-13 19:22:55 +03:00
|
|
|
step_msg("Creating a commit with the changes")
|
2023-04-25 02:37:36 +03:00
|
|
|
run_cmd_checked(["git", "add", CHANGELOG_FILE])
|
2023-06-07 16:34:51 +03:00
|
|
|
run_cmd_checked(["git", "commit", "-m", f"Start release v{next_version_number}"])
|
2020-03-05 01:48:50 +03:00
|
|
|
|
2023-04-25 02:37:36 +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)
|
2023-04-25 02:37:36 +03:00
|
|
|
|
|
|
|
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])
|