2020-02-20 20:13:51 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright (C) 2020 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
"""Helper tool for signing repo release tags correctly.
|
|
|
|
|
2020-02-29 06:49:56 +00:00
|
|
|
This is intended to be run only by the official Repo release managers, but it
|
|
|
|
could be run by people maintaining their own fork of the project.
|
|
|
|
|
2020-07-08 19:02:39 +00:00
|
|
|
NB: Check docs/release-process.md for production freeze information.
|
2020-02-20 20:13:51 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import util
|
|
|
|
|
|
|
|
|
|
|
|
# We currently sign with the old DSA key as it's been around the longest.
|
|
|
|
# We should transition to RSA by Jun 2020, and ECC by Jun 2021.
|
|
|
|
KEYID = util.KEYID_DSA
|
|
|
|
|
|
|
|
# Regular expression to validate tag names.
|
2023-03-11 06:46:20 +00:00
|
|
|
RE_VALID_TAG = r"^v([0-9]+[.])+[0-9]+$"
|
2020-02-20 20:13:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def sign(opts):
|
2023-03-11 06:46:20 +00:00
|
|
|
"""Tag the commit & sign it!"""
|
|
|
|
# We use ! at the end of the key so that gpg uses this specific key.
|
|
|
|
# Otherwise it uses the key as a lookup into the overall key and uses the
|
|
|
|
# default signing key. i.e. It will see that KEYID_RSA is a subkey of
|
|
|
|
# another key, and use the primary key to sign instead of the subkey.
|
|
|
|
cmd = [
|
|
|
|
"git",
|
|
|
|
"tag",
|
|
|
|
"-s",
|
|
|
|
opts.tag,
|
|
|
|
"-u",
|
|
|
|
f"{opts.key}!",
|
|
|
|
"-m",
|
|
|
|
f"repo {opts.tag}",
|
|
|
|
opts.commit,
|
|
|
|
]
|
|
|
|
|
|
|
|
key = "GNUPGHOME"
|
|
|
|
print("+", f'export {key}="{opts.gpgdir}"')
|
|
|
|
oldvalue = os.getenv(key)
|
|
|
|
os.putenv(key, opts.gpgdir)
|
|
|
|
util.run(opts, cmd)
|
|
|
|
if oldvalue is None:
|
|
|
|
os.unsetenv(key)
|
|
|
|
else:
|
|
|
|
os.putenv(key, oldvalue)
|
2020-02-20 20:13:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def check(opts):
|
2023-03-11 06:46:20 +00:00
|
|
|
"""Check the signature."""
|
|
|
|
util.run(opts, ["git", "tag", "--verify", opts.tag])
|
2020-02-20 20:13:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def postmsg(opts):
|
2023-03-11 06:46:20 +00:00
|
|
|
"""Helpful info to show at the end for release manager."""
|
|
|
|
cmd = ["git", "rev-parse", "remotes/origin/stable"]
|
|
|
|
ret = util.run(opts, cmd, encoding="utf-8", stdout=subprocess.PIPE)
|
|
|
|
current_release = ret.stdout.strip()
|
|
|
|
|
|
|
|
cmd = [
|
|
|
|
"git",
|
|
|
|
"log",
|
|
|
|
"--format=%h (%aN) %s",
|
|
|
|
"--no-merges",
|
|
|
|
f"remotes/origin/stable..{opts.tag}",
|
|
|
|
]
|
|
|
|
ret = util.run(opts, cmd, encoding="utf-8", stdout=subprocess.PIPE)
|
|
|
|
shortlog = ret.stdout.strip()
|
|
|
|
|
|
|
|
print(
|
|
|
|
f"""
|
2020-02-20 20:13:51 +00:00
|
|
|
Here's the short log since the last release.
|
|
|
|
{shortlog}
|
|
|
|
|
|
|
|
To push release to the public:
|
|
|
|
git push origin {opts.commit}:stable {opts.tag} -n
|
|
|
|
NB: People will start upgrading to this version immediately.
|
|
|
|
|
|
|
|
To roll back a release:
|
|
|
|
git push origin --force {current_release}:stable -n
|
2023-03-11 06:46:20 +00:00
|
|
|
"""
|
|
|
|
)
|
2020-02-20 20:13:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_parser():
|
2023-03-11 06:46:20 +00:00
|
|
|
"""Get a CLI parser."""
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description=__doc__,
|
|
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-n",
|
|
|
|
"--dry-run",
|
|
|
|
dest="dryrun",
|
|
|
|
action="store_true",
|
|
|
|
help="show everything that would be done",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--gpgdir",
|
|
|
|
default=os.path.join(util.HOMEDIR, ".gnupg", "repo"),
|
|
|
|
help="path to dedicated gpg dir with release keys "
|
|
|
|
"(default: ~/.gnupg/repo/)",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-f", "--force", action="store_true", help="force signing of any tag"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--keyid", dest="key", help="alternative signing key to use"
|
|
|
|
)
|
|
|
|
parser.add_argument("tag", help='the tag to create (e.g. "v2.0")')
|
|
|
|
parser.add_argument(
|
|
|
|
"commit", default="HEAD", nargs="?", help="the commit to tag"
|
|
|
|
)
|
|
|
|
return parser
|
2020-02-20 20:13:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main(argv):
|
2023-03-11 06:46:20 +00:00
|
|
|
"""The main func!"""
|
|
|
|
parser = get_parser()
|
|
|
|
opts = parser.parse_args(argv)
|
2020-02-20 20:13:51 +00:00
|
|
|
|
2023-03-11 06:46:20 +00:00
|
|
|
if not os.path.exists(opts.gpgdir):
|
|
|
|
parser.error(f"--gpgdir does not exist: {opts.gpgdir}")
|
2020-02-20 20:13:51 +00:00
|
|
|
|
2023-03-11 06:46:20 +00:00
|
|
|
if not opts.force and not re.match(RE_VALID_TAG, opts.tag):
|
|
|
|
parser.error(
|
|
|
|
f'tag "{opts.tag}" does not match regex "{RE_VALID_TAG}"; '
|
|
|
|
"use --force to sign anyways"
|
|
|
|
)
|
2020-02-20 20:13:51 +00:00
|
|
|
|
2023-03-11 06:46:20 +00:00
|
|
|
if opts.key:
|
|
|
|
print(f"Using custom key to sign: {opts.key}")
|
|
|
|
else:
|
|
|
|
print("Using official Repo release key to sign")
|
|
|
|
opts.key = KEYID
|
|
|
|
util.import_release_key(opts)
|
2020-02-20 20:13:51 +00:00
|
|
|
|
2023-03-11 06:46:20 +00:00
|
|
|
sign(opts)
|
|
|
|
check(opts)
|
|
|
|
postmsg(opts)
|
2020-02-20 20:13:51 +00:00
|
|
|
|
2023-03-11 06:46:20 +00:00
|
|
|
return 0
|
2020-02-20 20:13:51 +00:00
|
|
|
|
|
|
|
|
2023-03-11 06:46:20 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main(sys.argv[1:]))
|