From e537f29b04602a41a2813a1b30fa933ebadbf7d6 Mon Sep 17 00:00:00 2001 From: Flynn Date: Mon, 2 Aug 2021 12:23:37 -0400 Subject: [PATCH 1/4] Reorder imports. Signed-off-by: Flynn --- releng/lib/__init__.py | 2 +- releng/lib/gitutil.py | 6 ++++-- releng/start-sanity-check | 9 ++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/releng/lib/__init__.py b/releng/lib/__init__.py index 2a09a43739..f6921d4fbc 100644 --- a/releng/lib/__init__.py +++ b/releng/lib/__init__.py @@ -6,8 +6,8 @@ from os import getenv from .gitutil import git_check_clean as git_check_clean # Stop mypy complaining about implicit reexport -from .uiutil import run_txtcapture from .gitutil import git_add as git_add # Stop mypy complaining about implicit reexport +from .uiutil import run_txtcapture # These are some regular expressions to validate and parse # X.Y.Z[-rc.N] versions. diff --git a/releng/lib/gitutil.py b/releng/lib/gitutil.py index b740188b2b..263999e5ab 100644 --- a/releng/lib/gitutil.py +++ b/releng/lib/gitutil.py @@ -1,8 +1,10 @@ -from .uiutil import run -from .uiutil import run_txtcapture as run_capture +from typing import Optional, Union + import http.client import json +from .uiutil import run +from .uiutil import run_txtcapture as run_capture def has_open_pr(gh_repo: str, base: str, branchname: str) -> bool: conn = http.client.HTTPSConnection("api.github.com") diff --git a/releng/start-sanity-check b/releng/start-sanity-check index 9311e9eaf0..42c84b8f4d 100755 --- a/releng/start-sanity-check +++ b/releng/start-sanity-check @@ -4,12 +4,15 @@ cut an RC from; that you're in the right repo, that you're on the right branch, that all of the subtrees are up-to-date... """ -import os.path -from os import getenv +from typing import Generator + import sys import time + +import os.path + +from os import getenv from contextlib import contextmanager -from typing import Generator from lib import assert_eq, git_check_clean, vX, vY, re_ga from lib.uiutil import Checker, CheckResult, run From 884aef43d0d3ad31336f9db932281252596c028f Mon Sep 17 00:00:00 2001 From: Flynn Date: Mon, 2 Aug 2021 12:24:11 -0400 Subject: [PATCH 2/4] Add parse_bool Signed-off-by: Flynn --- releng/lib/__init__.py | 1 + releng/lib/gitutil.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/releng/lib/__init__.py b/releng/lib/__init__.py index f6921d4fbc..d066c5bc42 100644 --- a/releng/lib/__init__.py +++ b/releng/lib/__init__.py @@ -6,6 +6,7 @@ from os import getenv from .gitutil import git_check_clean as git_check_clean # Stop mypy complaining about implicit reexport +from .gitutil import parse_bool as parse_bool # Stop mypy complaining about implicit reexport from .gitutil import git_add as git_add # Stop mypy complaining about implicit reexport from .uiutil import run_txtcapture diff --git a/releng/lib/gitutil.py b/releng/lib/gitutil.py index 263999e5ab..b16de7e8da 100644 --- a/releng/lib/gitutil.py +++ b/releng/lib/gitutil.py @@ -3,9 +3,37 @@ import http.client import json +from distutils.util import strtobool + from .uiutil import run from .uiutil import run_txtcapture as run_capture + +# parse_bool is lifted from python/ambassador/utils.py -- it's just too useful. +def parse_bool(s: Optional[Union[str, bool]]) -> bool: + """ + Parse a boolean value from a string. T, True, Y, y, 1 return True; + other things return False. + """ + + # If `s` is already a bool, return its value. + # + # This allows a caller to not know or care whether their value is already + # a boolean, or if it is a string that needs to be parsed below. + if isinstance(s, bool): + return s + + # If we didn't get anything at all, return False. + if not s: + return False + + # OK, we got _something_, so try strtobool. + try: + return strtobool(s) + except ValueError: + return False + + def has_open_pr(gh_repo: str, base: str, branchname: str) -> bool: conn = http.client.HTTPSConnection("api.github.com") conn.request("GET", f"/repos/{gh_repo}/pulls?base={base}", headers={"User-Agent":"python"}) From 5fe0ee7df06990c40394de65787317420e0a9277 Mon Sep 17 00:00:00 2001 From: Flynn Date: Mon, 2 Aug 2021 12:25:21 -0400 Subject: [PATCH 3/4] Support ALLOW_UNTRACKED environment variable when starting a new version. Signed-off-by: Flynn --- releng/lib/gitutil.py | 11 +++++++++-- releng/start-sanity-check | 10 ++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/releng/lib/gitutil.py b/releng/lib/gitutil.py index b16de7e8da..46a59bae7f 100644 --- a/releng/lib/gitutil.py +++ b/releng/lib/gitutil.py @@ -56,13 +56,20 @@ def git_add(filename: str) -> None: run(['git', 'add', '--', filename]) -def git_check_clean(allow_staged: bool = False) -> None: +def git_check_clean(allow_staged: bool = False, allow_untracked: bool = False) -> None: """ Use `git status --porcelain` to check if the working tree is dirty. If allow_staged is True, allow staged files, but no unstaged changes. + If allow_untracked is True, allow untracked files. """ - out = run_capture(['git', 'status', '--porcelain']) + cmdvec = [ 'git', 'status', '--porcelain' ] + + if allow_untracked: + cmdvec += [ "--untracked-files=no" ] + + out = run_capture(cmdvec) + if out: # Can we allow staged changes? if not allow_staged: diff --git a/releng/start-sanity-check b/releng/start-sanity-check index 42c84b8f4d..29a1eecb99 100755 --- a/releng/start-sanity-check +++ b/releng/start-sanity-check @@ -14,7 +14,7 @@ import os.path from os import getenv from contextlib import contextmanager -from lib import assert_eq, git_check_clean, vX, vY, re_ga +from lib import assert_eq, git_check_clean, parse_bool, vX, vY, re_ga from lib.uiutil import Checker, CheckResult, run from lib.uiutil import run_txtcapture as run_capture @@ -22,7 +22,7 @@ from lib.uiutil import run_txtcapture as run_capture DEFAULT_REPO = 'git@github.com:emissary-ingress/emissary' -def main(next_ver: str, quiet: bool = False) -> int: +def main(next_ver: str, quiet: bool = False, allow_untracked: bool = False) -> int: print(f'Starting work on "v{next_ver}"...') print() remote_repo = getenv('AMBASSADOR_RELEASE_REPO_OVERRIDE') @@ -56,7 +56,7 @@ def main(next_ver: str, quiet: bool = False) -> int: raise Exception(f"Not in {toplevel}") with check("You're in a clean checkout"): - git_check_clean() + git_check_clean(allow_untracked=allow_untracked) # Cache the name of our remote... remote_name = f'{remote_repo}.git' if is_private else 'origin' @@ -128,6 +128,8 @@ if __name__ == '__main__': args = sys.argv[1:] quiet = False + allow_untracked = parse_bool(getenv("ALLOW_UNTRACKED", "false")) + if args and (args[0] == '--quiet'): quiet = True args.pop(0) @@ -136,4 +138,4 @@ if __name__ == '__main__': sys.stderr.write(f"Usage: {os.path.basename(sys.argv[0])} X.Y.Z\n") sys.exit(2) - sys.exit(main(next_ver=args[0], quiet=quiet)) + sys.exit(main(next_ver=args[0], quiet=quiet, allow_untracked=allow_untracked)) From 8208c96fb788f5a4db2e7cc230ead128cd651f5e Mon Sep 17 00:00:00 2001 From: Flynn Date: Mon, 2 Aug 2021 12:28:08 -0400 Subject: [PATCH 4/4] Update reviewers when starting a new release. Signed-off-by: Flynn --- releng/start-update-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releng/start-update-version b/releng/start-update-version index 6840484acd..04e0c9f903 100755 --- a/releng/start-update-version +++ b/releng/start-update-version @@ -92,7 +92,7 @@ def main(next_ver: str, today: datetime.date, quiet: bool=False, commit: bool = "--base", orig_branch, "--title", f"[v{next_ver}] Prep work for next scheduled release", "--body", f"Updates for next version {next_ver}", - "--reviewer", "kflynn,rhs,esmet,acookin"]) + "--reviewer", "emissary-ingress/emissary-maintainers"]) if checker.ok: print(f'Update complete. Merge PR back to target branch ASAP')