2011-09-13 12:20:23 -04:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
# The ASF licenses this file to You 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.
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2013-01-16 16:18:41 -05:00
|
|
|
# Usage: python3.2 -u buildAndPushRelease.py [-sign gpgKey(eg: 6E68DA61)] [-prepare] [-push userName] [-pushLocal dirName] [-smoke tmpDir] /path/to/checkout version(eg: 3.4.0) rcNum(eg: 0)
|
2011-09-13 12:20:23 -04:00
|
|
|
#
|
2013-01-16 16:18:41 -05:00
|
|
|
# EG: python3.2 -u buildAndPushRelease.py -prepare -push -sign 6E68DA61 mikemccand /lucene/34x 3.4.0 0
|
2011-09-13 12:20:23 -04:00
|
|
|
|
2012-04-08 14:22:14 -04:00
|
|
|
# NOTE: if you specify -sign, you have to type in your gpg password at
|
|
|
|
# some point while this runs; it's VERY confusing because the output
|
|
|
|
# is directed to /tmp/release.log, so, you have to tail that and when
|
|
|
|
# GPG wants your password, type it! Also sometimes you have to type
|
|
|
|
# it twice in a row!
|
2011-09-13 12:20:23 -04:00
|
|
|
|
|
|
|
LOG = '/tmp/release.log'
|
|
|
|
|
|
|
|
def log(msg):
|
2013-01-16 16:18:41 -05:00
|
|
|
f = open(LOG, mode='ab')
|
|
|
|
f.write(msg.encode('utf-8'))
|
2011-09-13 12:20:23 -04:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
def run(command):
|
|
|
|
log('\n\n%s: RUN: %s\n' % (datetime.datetime.now(), command))
|
|
|
|
if os.system('%s >> %s 2>&1' % (command, LOG)):
|
|
|
|
msg = ' FAILED: %s [see log %s]' % (command, LOG)
|
2013-01-16 16:18:41 -05:00
|
|
|
print(msg)
|
2011-09-13 12:20:23 -04:00
|
|
|
raise RuntimeError(msg)
|
|
|
|
|
|
|
|
def scrubCheckout():
|
|
|
|
# removes any files not checked into svn
|
|
|
|
|
|
|
|
unversionedRex = re.compile('^ ?[\?ID] *[1-9 ]*[a-zA-Z]* +(.*)')
|
|
|
|
|
|
|
|
for l in os.popen('svn status --no-ignore -v').readlines():
|
|
|
|
match = unversionedRex.match(l)
|
|
|
|
if match:
|
|
|
|
s = match.group(1)
|
|
|
|
if os.path.exists(s):
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' delete %s' % s)
|
2011-09-13 12:20:23 -04:00
|
|
|
if os.path.isdir(s) and not os.path.islink(s):
|
|
|
|
shutil.rmtree(s)
|
|
|
|
else:
|
|
|
|
os.remove(s)
|
|
|
|
|
|
|
|
def getSVNRev():
|
|
|
|
rev = os.popen('svnversion').read().strip()
|
|
|
|
try:
|
|
|
|
int(rev)
|
|
|
|
except (TypeError, ValueError):
|
|
|
|
raise RuntimeError('svn version is not clean: %s' % rev)
|
|
|
|
return rev
|
|
|
|
|
|
|
|
|
2012-04-08 14:22:14 -04:00
|
|
|
def prepare(root, version, gpgKeyID, doTest):
|
2013-01-16 16:18:41 -05:00
|
|
|
print()
|
|
|
|
print('Prepare release...')
|
2011-09-13 12:20:23 -04:00
|
|
|
if os.path.exists(LOG):
|
|
|
|
os.remove(LOG)
|
|
|
|
|
|
|
|
os.chdir(root)
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' svn up...')
|
2011-09-13 12:20:23 -04:00
|
|
|
run('svn up')
|
|
|
|
|
|
|
|
rev = getSVNRev()
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' svn rev: %s' % rev)
|
2011-09-13 12:20:23 -04:00
|
|
|
log('\nSVN rev: %s\n' % rev)
|
|
|
|
|
2012-04-08 14:22:14 -04:00
|
|
|
if doTest:
|
|
|
|
# Don't run tests if we are gonna smoke test after the release...
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' ant clean test')
|
2012-04-08 14:22:14 -04:00
|
|
|
run('ant clean test')
|
2011-09-13 12:20:23 -04:00
|
|
|
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' clean checkout')
|
2011-09-13 12:20:23 -04:00
|
|
|
scrubCheckout()
|
2013-01-16 16:18:41 -05:00
|
|
|
open('rev.txt', mode='wb').write(rev.encode('UTF-8'))
|
2011-09-13 12:20:23 -04:00
|
|
|
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' lucene prepare-release')
|
2011-09-13 12:20:23 -04:00
|
|
|
os.chdir('lucene')
|
2012-04-08 14:22:14 -04:00
|
|
|
cmd = 'ant -Dversion=%s -Dspecversion=%s' % (version, version)
|
|
|
|
if gpgKeyID is not None:
|
|
|
|
cmd += ' -Dgpg.key=%s prepare-release' % gpgKeyID
|
|
|
|
else:
|
|
|
|
cmd += ' prepare-release-no-sign'
|
|
|
|
run(cmd)
|
|
|
|
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' solr prepare-release')
|
2011-09-13 12:20:23 -04:00
|
|
|
os.chdir('../solr')
|
2012-04-08 14:22:14 -04:00
|
|
|
cmd = 'ant -Dversion=%s -Dspecversion=%s' % (version, version)
|
|
|
|
if gpgKeyID is not None:
|
|
|
|
cmd += ' -Dgpg.key=%s prepare-release' % gpgKeyID
|
|
|
|
else:
|
|
|
|
cmd += ' prepare-release-no-sign'
|
|
|
|
run(cmd)
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' done!')
|
|
|
|
print()
|
2011-09-13 12:20:23 -04:00
|
|
|
return rev
|
|
|
|
|
|
|
|
def push(version, root, rev, rcNum, username):
|
2013-01-16 16:18:41 -05:00
|
|
|
print('Push...')
|
2011-09-13 12:20:23 -04:00
|
|
|
dir = 'lucene-solr-%s-RC%d-rev%s' % (version, rcNum, rev)
|
2013-01-16 16:18:41 -05:00
|
|
|
s = os.popen('ssh %s@people.apache.org "ls -ld public_html/staging_area/%s" 2>&1' % (username, dir)).read().decode('UTF-8')
|
|
|
|
if 'no such file or directory' not in s.lower():
|
|
|
|
print(' Remove old dir...')
|
2011-09-13 12:20:23 -04:00
|
|
|
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))
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' Lucene')
|
2011-09-13 12:20:23 -04:00
|
|
|
os.chdir('%s/lucene/dist' % root)
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' zip...')
|
2011-09-13 12:20:23 -04:00
|
|
|
if os.path.exists('lucene.tar.bz2'):
|
|
|
|
os.remove('lucene.tar.bz2')
|
|
|
|
run('tar cjf lucene.tar.bz2 *')
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' copy...')
|
2011-09-13 12:20:23 -04:00
|
|
|
run('scp lucene.tar.bz2 %s@people.apache.org:public_html/staging_area/%s/lucene' % (username, dir))
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' unzip...')
|
2011-09-13 12:20:23 -04:00
|
|
|
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')
|
|
|
|
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' Solr')
|
2011-09-13 12:20:23 -04:00
|
|
|
os.chdir('%s/solr/package' % root)
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' zip...')
|
2011-09-13 12:20:23 -04:00
|
|
|
if os.path.exists('solr.tar.bz2'):
|
|
|
|
os.remove('solr.tar.bz2')
|
|
|
|
run('tar cjf solr.tar.bz2 *')
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' copy...')
|
2011-09-13 12:20:23 -04:00
|
|
|
run('scp solr.tar.bz2 %s@people.apache.org:public_html/staging_area/%s/solr' % (username, dir))
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' unzip...')
|
2011-09-13 12:20:23 -04:00
|
|
|
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')
|
|
|
|
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' chmod...')
|
2011-09-13 12:20:23 -04:00
|
|
|
run('ssh %s@people.apache.org "chmod -R a+rX-w public_html/staging_area/%s"' % (username, dir))
|
|
|
|
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' done!')
|
2012-04-08 14:22:14 -04:00
|
|
|
url = 'https://people.apache.org/~%s/staging_area/%s' % (username, dir)
|
|
|
|
return url
|
|
|
|
|
|
|
|
def pushLocal(version, root, rev, rcNum, localDir):
|
2013-01-16 16:18:41 -05:00
|
|
|
print('Push local [%s]...' % localDir)
|
2012-04-08 14:22:14 -04:00
|
|
|
os.makedirs(localDir)
|
|
|
|
|
|
|
|
dir = 'lucene-solr-%s-RC%d-rev%s' % (version, rcNum, rev)
|
|
|
|
os.makedirs('%s/%s/lucene' % (localDir, dir))
|
|
|
|
os.makedirs('%s/%s/solr' % (localDir, dir))
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' Lucene')
|
2012-04-08 14:22:14 -04:00
|
|
|
os.chdir('%s/lucene/dist' % root)
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' zip...')
|
2012-04-08 14:22:14 -04:00
|
|
|
if os.path.exists('lucene.tar.bz2'):
|
|
|
|
os.remove('lucene.tar.bz2')
|
|
|
|
run('tar cjf lucene.tar.bz2 *')
|
|
|
|
|
|
|
|
os.chdir('%s/%s/lucene' % (localDir, dir))
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' unzip...')
|
2012-04-08 14:22:14 -04:00
|
|
|
run('tar xjf "%s/lucene/dist/lucene.tar.bz2"' % root)
|
|
|
|
os.remove('%s/lucene/dist/lucene.tar.bz2' % root)
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' copy changes...')
|
2012-04-08 14:22:14 -04:00
|
|
|
run('cp -r "%s/lucene/build/docs/changes" changes-%s' % (root, version))
|
2011-09-13 12:20:23 -04:00
|
|
|
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' Solr')
|
2012-04-08 14:22:14 -04:00
|
|
|
os.chdir('%s/solr/package' % root)
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' zip...')
|
2012-04-08 14:22:14 -04:00
|
|
|
if os.path.exists('solr.tar.bz2'):
|
|
|
|
os.remove('solr.tar.bz2')
|
|
|
|
run('tar cjf solr.tar.bz2 *')
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' unzip...')
|
2012-04-08 14:22:14 -04:00
|
|
|
os.chdir('%s/%s/solr' % (localDir, dir))
|
|
|
|
run('tar xjf "%s/solr/package/solr.tar.bz2"' % root)
|
|
|
|
os.remove('%s/solr/package/solr.tar.bz2' % root)
|
|
|
|
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' KEYS')
|
2012-04-08 14:22:14 -04:00
|
|
|
run('wget http://people.apache.org/keys/group/lucene.asc')
|
|
|
|
os.rename('lucene.asc', 'KEYS')
|
|
|
|
run('chmod a+r-w KEYS')
|
|
|
|
run('cp KEYS ../lucene')
|
|
|
|
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' chmod...')
|
2012-04-08 14:22:14 -04:00
|
|
|
os.chdir('..')
|
|
|
|
run('chmod -R a+rX-w .')
|
|
|
|
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' done!')
|
2012-04-08 14:22:14 -04:00
|
|
|
return 'file://%s/%s' % (os.path.abspath(localDir), dir)
|
2011-09-13 12:20:23 -04:00
|
|
|
|
|
|
|
def main():
|
|
|
|
doPrepare = '-prepare' in sys.argv
|
|
|
|
if doPrepare:
|
|
|
|
sys.argv.remove('-prepare')
|
2012-04-08 14:22:14 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
idx = sys.argv.index('-push')
|
|
|
|
except ValueError:
|
|
|
|
doPushRemote = False
|
|
|
|
else:
|
|
|
|
doPushRemote = True
|
|
|
|
username = sys.argv[idx+1]
|
|
|
|
del sys.argv[idx:idx+2]
|
|
|
|
|
|
|
|
try:
|
|
|
|
idx = sys.argv.index('-smoke')
|
|
|
|
except ValueError:
|
|
|
|
smokeTmpDir = None
|
|
|
|
else:
|
|
|
|
smokeTmpDir = sys.argv[idx+1]
|
|
|
|
del sys.argv[idx:idx+2]
|
|
|
|
if os.path.exists(smokeTmpDir):
|
2013-01-16 16:18:41 -05:00
|
|
|
print()
|
|
|
|
print('ERROR: smoke tmpDir "%s" exists; please remove first' % smokeTmpDir)
|
|
|
|
print()
|
2012-04-08 14:22:14 -04:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
idx = sys.argv.index('-pushLocal')
|
|
|
|
except ValueError:
|
|
|
|
doPushLocal = False
|
|
|
|
else:
|
|
|
|
doPushLocal = True
|
|
|
|
localStagingDir = sys.argv[idx+1]
|
|
|
|
del sys.argv[idx:idx+2]
|
|
|
|
if os.path.exists(localStagingDir):
|
2013-01-16 16:18:41 -05:00
|
|
|
print()
|
|
|
|
print('ERROR: pushLocal dir "%s" exists; please remove first' % localStagingDir)
|
|
|
|
print()
|
2012-04-08 14:22:14 -04:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if doPushRemote and doPushLocal:
|
2013-01-16 16:18:41 -05:00
|
|
|
print()
|
|
|
|
print('ERROR: specify at most one of -push or -pushLocal (got both)')
|
|
|
|
print()
|
2012-04-08 14:22:14 -04:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
idx = sys.argv.index('-sign')
|
|
|
|
except ValueError:
|
|
|
|
gpgKeyID = None
|
|
|
|
else:
|
|
|
|
gpgKeyID = sys.argv[idx+1]
|
|
|
|
del sys.argv[idx:idx+2]
|
2013-01-16 16:18:41 -05:00
|
|
|
|
2012-03-23 10:20:35 -04:00
|
|
|
root = os.path.abspath(sys.argv[1])
|
2011-09-13 12:20:23 -04:00
|
|
|
version = sys.argv[2]
|
2012-04-08 14:22:14 -04:00
|
|
|
rcNum = int(sys.argv[3])
|
2011-09-13 12:20:23 -04:00
|
|
|
|
|
|
|
if doPrepare:
|
2012-04-08 14:22:14 -04:00
|
|
|
rev = prepare(root, version, gpgKeyID, smokeTmpDir is None)
|
2011-09-13 12:20:23 -04:00
|
|
|
else:
|
|
|
|
os.chdir(root)
|
2013-01-16 16:18:41 -05:00
|
|
|
rev = open('rev.txt', encoding='UTF-8').read()
|
2011-09-13 12:20:23 -04:00
|
|
|
|
2012-04-08 14:22:14 -04:00
|
|
|
if doPushRemote:
|
|
|
|
url = push(version, root, rev, rcNum, username)
|
|
|
|
elif doPushLocal:
|
|
|
|
url = pushLocal(version, root, rev, rcNum, localStagingDir)
|
|
|
|
else:
|
2013-01-16 16:18:41 -05:00
|
|
|
url = None
|
2012-04-08 14:22:14 -04:00
|
|
|
|
|
|
|
if url is not None:
|
2013-01-16 16:18:41 -05:00
|
|
|
print(' URL: %s' % url)
|
2012-04-08 14:22:14 -04:00
|
|
|
|
|
|
|
if smokeTmpDir is not None:
|
|
|
|
import smokeTestRelease
|
|
|
|
smokeTestRelease.DEBUG = False
|
|
|
|
smokeTestRelease.smokeTest(url, version, smokeTmpDir, gpgKeyID is not None)
|
2013-01-16 16:18:41 -05:00
|
|
|
|
2011-09-13 12:20:23 -04:00
|
|
|
if __name__ == '__main__':
|
2013-01-16 16:18:41 -05:00
|
|
|
try:
|
|
|
|
main()
|
|
|
|
except:
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|