- Fail if there are unpushed commits in the Git working tree

- Drop obsolete "--push-remote" param
- Drop obsolete "--smoke-test" param
- Update example RM cmdline usage
- Support relative working tree root directory
- Convert "root" positional cmdline arg into an optional "--root" arg defaulting to '.'
- Use sys.executable instead of $PYTHON_EXEC when printing smoke tester cmdline
- Add new fail-fast checks:
   - Check for a functional "git" executable
   - Ensure "ant" version is 1.8.X
   - Ensure working tree is under Git control, and contains 'lucene/', 'solr/' and 'dev-tools/' dirs
This commit is contained in:
Steve Rowe 2016-05-23 15:28:06 -04:00
parent e4e990b993
commit 8cb2773dc7
1 changed files with 26 additions and 59 deletions

View File

@ -61,8 +61,10 @@ def getGitRev():
status = os.popen('git status').read().strip() status = os.popen('git status').read().strip()
if 'nothing to commit, working directory clean' not in status: if 'nothing to commit, working directory clean' not in status:
raise RuntimeError('git clone is dirty:\n\n%s' % status) raise RuntimeError('git clone is dirty:\n\n%s' % status)
unpushedCommits = os.popen('git log origin..').read().strip()
if len(unpushedCommits) > 0:
raise RuntimeError('There are unpushed commits - "git log origin.." output is:\n\n%s' % unpushedCommits)
# TODO: we should also detect unpushed changes here? Something like "git cherry -v origin/branch_5_5"?
print(' git clone is clean') print(' git clone is clean')
return os.popen('git rev-parse HEAD').read().strip() return os.popen('git rev-parse HEAD').read().strip()
@ -115,47 +117,6 @@ def prepare(root, version, gpgKeyID, gpgPassword):
print() print()
return rev return rev
def push(version, root, rev, rcNum, username):
print('Push...')
dir = 'lucene-solr-%s-RC%d-rev%s' % (version, rcNum, rev)
s = os.popen('ssh %s@people.apache.org "ls -ld public_html/staging_area/%s" 2>&1' % (username, dir)).read()
if 'no such file or directory' not in s.lower():
print(' Remove old dir...')
run('ssh %s@people.apache.org "chmod -R u+rwX public_html/staging_area/%s; rm -rf public_html/staging_area/%s"' %
(username, dir, dir))
run('ssh %s@people.apache.org "mkdir -p public_html/staging_area/%s/lucene public_html/staging_area/%s/solr"' % \
(username, dir, dir))
print(' Lucene')
os.chdir('%s/lucene/dist' % root)
print(' zip...')
if os.path.exists('lucene.tar.bz2'):
os.remove('lucene.tar.bz2')
run('tar cjf lucene.tar.bz2 *')
print(' copy...')
run('scp lucene.tar.bz2 %s@people.apache.org:public_html/staging_area/%s/lucene' % (username, dir))
print(' unzip...')
run('ssh %s@people.apache.org "cd public_html/staging_area/%s/lucene; tar xjf lucene.tar.bz2; rm -f lucene.tar.bz2"' % (username, dir))
os.remove('lucene.tar.bz2')
print(' Solr')
os.chdir('%s/solr/package' % root)
print(' zip...')
if os.path.exists('solr.tar.bz2'):
os.remove('solr.tar.bz2')
run('tar cjf solr.tar.bz2 *')
print(' copy...')
run('scp solr.tar.bz2 %s@people.apache.org:public_html/staging_area/%s/solr' % (username, dir))
print(' unzip...')
run('ssh %s@people.apache.org "cd public_html/staging_area/%s/solr; tar xjf solr.tar.bz2; rm -f solr.tar.bz2"' % (username, dir))
os.remove('solr.tar.bz2')
print(' chmod...')
run('ssh %s@people.apache.org "chmod -R a+rX-w public_html/staging_area/%s"' % (username, dir))
print(' done!')
url = 'http://people.apache.org/~%s/staging_area/%s' % (username, dir)
return url
def pushLocal(version, root, rev, rcNum, localDir): def pushLocal(version, root, rev, rcNum, localDir):
print('Push local [%s]...' % localDir) print('Push local [%s]...' % localDir)
os.makedirs(localDir) os.makedirs(localDir)
@ -206,29 +167,23 @@ def read_version(path):
def parse_config(): def parse_config():
epilogue = textwrap.dedent(''' epilogue = textwrap.dedent('''
Example usage for a Release Manager: Example usage for a Release Manager:
python3.2 -u buildAndPushRelease.py --push-remote mikemccand --sign 6E68DA61 --rc-num 1 /path/to/lucene_solr_4_7 python3 -u dev-tools/scripts/buildAndPushRelease.py --push-local /tmp/releases/6.0.1 --sign 6E68DA61 --rc-num 1
''') ''')
description = 'Utility to build, push, and test a release.' description = 'Utility to build, push, and test a release.'
parser = argparse.ArgumentParser(description=description, epilog=epilogue, parser = argparse.ArgumentParser(description=description, epilog=epilogue,
formatter_class=argparse.RawDescriptionHelpFormatter) formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('--no-prepare', dest='prepare', default=True, action='store_false', parser.add_argument('--no-prepare', dest='prepare', default=True, action='store_false',
help='Use the already built release in the provided checkout') help='Use the already built release in the provided checkout')
parser.add_argument('--push-remote', metavar='USERNAME',
help='Push the release to people.apache.org for the given user')
parser.add_argument('--push-local', metavar='PATH', parser.add_argument('--push-local', metavar='PATH',
help='Push the release to the local path') help='Push the release to the local path')
parser.add_argument('--sign', metavar='KEYID', parser.add_argument('--sign', metavar='KEYID',
help='Sign the release with the given gpg key') help='Sign the release with the given gpg key')
parser.add_argument('--rc-num', metavar='NUM', type=int, default=1, parser.add_argument('--rc-num', metavar='NUM', type=int, default=1,
help='Release Candidate number, required') help='Release Candidate number, required')
parser.add_argument('--smoke-test', metavar='PATH', parser.add_argument('--root', metavar='WORKING_TREE_PATH', default='.',
help='Run the smoker tester on the release in the given directory') help='Root of Git working tree for lucene-solr')
parser.add_argument('root', metavar='checkout_path',
help='Root of SVN checkout for lucene-solr')
config = parser.parse_args() config = parser.parse_args()
if config.push_remote is not None and config.push_local is not None:
parser.error('Cannot specify --push-remote and --push-local together')
if not config.prepare and config.sign: if not config.prepare and config.sign:
parser.error('Cannot sign already built release') parser.error('Cannot sign already built release')
if config.push_local is not None and os.path.exists(config.push_local): if config.push_local is not None and os.path.exists(config.push_local):
@ -236,8 +191,13 @@ def parse_config():
if config.rc_num <= 0: if config.rc_num <= 0:
parser.error('Release Candidate number must be a positive integer') parser.error('Release Candidate number must be a positive integer')
if not os.path.isdir(config.root): if not os.path.isdir(config.root):
# TODO: add additional git check to ensure dir is a real lucene-solr checkout parser.error('Root path "%s" is not a directory' % config.root)
parser.error('Root path is not a valid lucene-solr checkout') cwd = os.getcwd()
os.chdir(config.root)
config.root = os.getcwd() # Absolutize root dir
if os.system('git rev-parse') or 3 != len([d for d in ('dev-tools','lucene','solr') if os.isdir(d)]):
parser.error('Root path "%s" is not a valid lucene-solr checkout' % config.root)
os.chdir(cwd)
config.version = read_version(config.root) config.version = read_version(config.root)
print('Building version: %s' % config.version) print('Building version: %s' % config.version)
@ -251,8 +211,17 @@ def parse_config():
config.gpg_password = None config.gpg_password = None
return config return config
def check_cmdline_tools(): # Fail fast if there are cmdline tool problems
if os.system('git --version'):
raise RuntimeError('"git --version" returned a non-zero exit code.')
antVersion = os.popen('ant -version').read().strip()
if not antVersion.startswith('Apache Ant(TM) version 1.8'):
raise RuntimeError('ant version is not 1.8.X: "%s"' % antVersion)
def main(): def main():
check_cmdline_tools()
c = parse_config() c = parse_config()
if c.prepare: if c.prepare:
@ -261,19 +230,17 @@ def main():
os.chdir(root) os.chdir(root)
rev = open('rev.txt', encoding='UTF-8').read() rev = open('rev.txt', encoding='UTF-8').read()
if c.push_remote: if c.push_local:
url = push(c.version, c.root, rev, c.rc_num, c.push_remote)
elif c.push_local:
url = pushLocal(c.version, c.root, rev, c.rc_num, c.push_local) url = pushLocal(c.version, c.root, rev, c.rc_num, c.push_local)
else: else:
url = None url = None
if url is not None: if url is not None:
print(' URL: %s' % url) print(' URL: %s' % url)
print('Next set the PYTHON_EXEC env var and you can run the smoker tester:') print('Next run the smoker tester:')
p = re.compile("(.*)\/") p = re.compile(".*/")
m = p.match(sys.argv[0]) m = p.match(sys.argv[0])
print(' $PYTHON_EXEC %ssmokeTestRelease.py %s' % (m.group(), url)) print('%s -u %(s)smokeTestRelease.py %s' % (sys.executable, m.group(), url))
if __name__ == '__main__': if __name__ == '__main__':
try: try: