Skip to content

Commit

Permalink
Merge pull request #3652 from emissary-ingress/flynn/dev/allow-untracked
Browse files Browse the repository at this point in the history
Support starting a release with untracked files
  • Loading branch information
kflynn authored Aug 2, 2021
2 parents e448c45 + 8208c96 commit 007f394
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 13 deletions.
3 changes: 2 additions & 1 deletion releng/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
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 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

# These are some regular expressions to validate and parse
# X.Y.Z[-rc.N] versions.
Expand Down
45 changes: 41 additions & 4 deletions releng/lib/gitutil.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
from .uiutil import run
from .uiutil import run_txtcapture as run_capture
from typing import Optional, Union

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")
Expand All @@ -26,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:
Expand Down
19 changes: 12 additions & 7 deletions releng/start-sanity-check
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@ 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 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


DEFAULT_REPO = '[email protected]: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')
Expand Down Expand Up @@ -53,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'
Expand Down Expand Up @@ -125,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)
Expand All @@ -133,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))
2 changes: 1 addition & 1 deletion releng/start-update-version
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 007f394

Please sign in to comment.