build_release.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. # Licensed to Elasticsearch under one or more contributor
  2. # license agreements. See the NOTICE file distributed with
  3. # this work for additional information regarding copyright
  4. # ownership. Elasticsearch licenses this file to you under
  5. # the Apache License, Version 2.0 (the "License"); you may
  6. # not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on
  13. # an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  14. # either express or implied. See the License for the specific
  15. # language governing permissions and limitations under the License.
  16. import re
  17. import tempfile
  18. import shutil
  19. import os
  20. import datetime
  21. import json
  22. import time
  23. import sys
  24. import argparse
  25. import hmac
  26. import urllib
  27. import fnmatch
  28. import socket
  29. import urllib.request
  30. from http.client import HTTPConnection
  31. """
  32. This tool builds a release from the a given elasticsearch branch.
  33. In order to execute it go in the top level directory and run:
  34. $ python3 dev_tools/build_release.py --branch 0.90 --publish --remote origin
  35. By default this script runs in 'dry' mode which essentially simulates a release. If the
  36. '--publish' option is set the actual release is done. The script takes over almost all
  37. steps necessary for a release from a high level point of view it does the following things:
  38. - run prerequisit checks ie. check for Java 1.6 being presend or S3 credentials available as env variables
  39. - detect the version to release from the specified branch (--branch) or the current branch
  40. - creates a release branch & updates pom.xml and Version.java to point to a release version rather than a snapshot
  41. - builds the artifacts and runs smoke-tests on the build zip & tar.gz files
  42. - commits the new version and merges the release branch into the source branch
  43. - creates a tag and pushes the commit to the specified origin (--remote)
  44. - publishes the releases to sonar-type and S3
  45. Once it's done it will print all the remaining steps.
  46. Prerequisites:
  47. - Python 3k for script execution
  48. - Boto for S3 Upload ($ apt-get install python-boto)
  49. - RPM for RPM building ($ apt-get install rpm)
  50. - S3 keys exported via ENV Variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  51. """
  52. env = os.environ
  53. PLUGINS = [('bigdesk', 'lukas-vlcek/bigdesk'),
  54. ('paramedic', 'karmi/elasticsearch-paramedic'),
  55. ('segmentspy', 'polyfractal/elasticsearch-segmentspy'),
  56. ('inquisitor', 'polyfractal/elasticsearch-inquisitor'),
  57. ('head', 'mobz/elasticsearch-head')]
  58. LOG = env.get('ES_RELEASE_LOG', '/tmp/elasticsearch_release.log')
  59. def log(msg):
  60. log_plain('\n%s' % msg)
  61. def log_plain(msg):
  62. f = open(LOG, mode='ab')
  63. f.write(msg.encode('utf-8'))
  64. f.close()
  65. def run(command, quiet=False):
  66. log('%s: RUN: %s\n' % (datetime.datetime.now(), command))
  67. if os.system('%s >> %s 2>&1' % (command, LOG)):
  68. msg = ' FAILED: %s [see log %s]' % (command, LOG)
  69. if not quiet:
  70. print(msg)
  71. raise RuntimeError(msg)
  72. try:
  73. JAVA_HOME = env['JAVA_HOME']
  74. except KeyError:
  75. raise RuntimeError("""
  76. Please set JAVA_HOME in the env before running release tool
  77. On OSX use: export JAVA_HOME=`/usr/libexec/java_home -v '1.6*'`""")
  78. try:
  79. JAVA_HOME = env['JAVA6_HOME']
  80. except KeyError:
  81. pass #no JAVA6_HOME - we rely on JAVA_HOME
  82. try:
  83. MVN='mvn'
  84. # make sure mvn3 is used if mvn3 is available
  85. # some systems use maven 2 as default
  86. run('mvn3 --version', quiet=True)
  87. MVN='mvn3'
  88. except RuntimeError:
  89. pass
  90. def java_exe():
  91. path = JAVA_HOME
  92. return 'export JAVA_HOME="%s" PATH="%s/bin:$PATH" JAVACMD="%s/bin/java"' % (path, path, path)
  93. def verify_java_version(version):
  94. s = os.popen('%s; java -version 2>&1' % java_exe()).read()
  95. if s.find(' version "%s.' % version) == -1:
  96. raise RuntimeError('got wrong version for java %s:\n%s' % (version, s))
  97. # Verifies the java version. We guarantee that we run with Java 1.6
  98. # If 1.6 is not available fail the build!
  99. def verify_mvn_java_version(version, mvn):
  100. s = os.popen('%s; %s --version 2>&1' % (java_exe(), mvn)).read()
  101. if s.find('Java version: %s' % version) == -1:
  102. raise RuntimeError('got wrong java version for %s %s:\n%s' % (mvn, version, s))
  103. # Returns the hash of the current git HEAD revision
  104. def get_head_hash():
  105. return os.popen(' git rev-parse --verify HEAD 2>&1').read().strip()
  106. # Returns the hash of the given tag revision
  107. def get_tag_hash(tag):
  108. return os.popen('git show-ref --tags %s --hash 2>&1' % (tag)).read().strip()
  109. # Returns the name of the current branch
  110. def get_current_branch():
  111. return os.popen('git rev-parse --abbrev-ref HEAD 2>&1').read().strip()
  112. verify_java_version('1.6') # we require to build with 1.6
  113. verify_mvn_java_version('1.6', MVN)
  114. # Utility that returns the name of the release branch for a given version
  115. def release_branch(version):
  116. return 'release_branch_%s' % version
  117. # runs get fetch on the given remote
  118. def fetch(remote):
  119. run('git fetch %s' % remote)
  120. # Creates a new release branch from the given source branch
  121. # and rebases the source branch from the remote before creating
  122. # the release branch. Note: This fails if the source branch
  123. # doesn't exist on the provided remote.
  124. def create_release_branch(remote, src_branch, release):
  125. run('git checkout %s' % src_branch)
  126. run('git pull --rebase %s %s' % (remote, src_branch))
  127. run('git checkout -b %s' % (release_branch(release)))
  128. # Reads the given file and applies the
  129. # callback to it. If the callback changed
  130. # a line the given file is replaced with
  131. # the modified input.
  132. def process_file(file_path, line_callback):
  133. fh, abs_path = tempfile.mkstemp()
  134. modified = False
  135. with open(abs_path,'w', encoding='utf-8') as new_file:
  136. with open(file_path, encoding='utf-8') as old_file:
  137. for line in old_file:
  138. new_line = line_callback(line)
  139. modified = modified or (new_line != line)
  140. new_file.write(new_line)
  141. os.close(fh)
  142. if modified:
  143. #Remove original file
  144. os.remove(file_path)
  145. #Move new file
  146. shutil.move(abs_path, file_path)
  147. return True
  148. else:
  149. # nothing to do - just remove the tmp file
  150. os.remove(abs_path)
  151. return False
  152. # Walks the given directory path (defaults to 'docs')
  153. # and replaces all 'coming[$version]' tags with
  154. # 'added[$version]'. This method only accesses asciidoc files.
  155. def update_reference_docs(release_version, path='docs'):
  156. pattern = 'coming[%s' % (release_version)
  157. replacement = 'added[%s' % (release_version)
  158. pending_files = []
  159. def callback(line):
  160. return line.replace(pattern, replacement)
  161. for root, _, file_names in os.walk(path):
  162. for file_name in fnmatch.filter(file_names, '*.asciidoc'):
  163. full_path = os.path.join(root, file_name)
  164. if process_file(full_path, callback):
  165. pending_files.append(os.path.join(root, file_name))
  166. return pending_files
  167. # Moves the pom.xml file from a snapshot to a release
  168. def remove_maven_snapshot(pom, release):
  169. pattern = '<version>%s-SNAPSHOT</version>' % (release)
  170. replacement = '<version>%s</version>' % (release)
  171. def callback(line):
  172. return line.replace(pattern, replacement)
  173. process_file(pom, callback)
  174. # Moves the Version.java file from a snapshot to a release
  175. def remove_version_snapshot(version_file, release):
  176. # 1.0.0.Beta1 -> 1_0_0_Beat1
  177. release = release.replace('.', '_')
  178. pattern = 'new Version(V_%s_ID, true' % (release)
  179. replacement = 'new Version(V_%s_ID, false' % (release)
  180. def callback(line):
  181. return line.replace(pattern, replacement)
  182. process_file(version_file, callback)
  183. # Stages the given files for the next git commit
  184. def add_pending_files(*files):
  185. for file in files:
  186. run('git add %s' % (file))
  187. # Executes a git commit with 'release [version]' as the commit message
  188. def commit_release(release):
  189. run('git commit -m "release [%s]"' % release)
  190. def tag_release(release):
  191. run('git tag -a v%s -m "Tag release version %s"' % (release, release))
  192. def run_mvn(*cmd):
  193. for c in cmd:
  194. run('%s; %s %s' % (java_exe(), MVN, c))
  195. def build_release(run_tests=False, dry_run=True, cpus=1):
  196. target = 'deploy'
  197. if dry_run:
  198. target = 'package'
  199. if run_tests:
  200. run_mvn('clean',
  201. 'test -Dtests.jvms=%s -Des.node.mode=local' % (cpus),
  202. 'test -Dtests.jvms=%s -Des.node.mode=network' % (cpus))
  203. run_mvn('clean %s -DskipTests' %(target))
  204. success = False
  205. try:
  206. run_mvn('-DskipTests rpm:rpm')
  207. success = True
  208. finally:
  209. if not success:
  210. print("""
  211. RPM Bulding failed make sure "rpm" tools are installed.
  212. Use on of the following commands to install:
  213. $ brew install rpm # on OSX
  214. $ apt-get install rpm # on Ubuntu et.al
  215. """)
  216. def wait_for_node_startup(host='127.0.0.1', port=9200,timeout=15):
  217. for _ in range(timeout):
  218. conn = HTTPConnection(host, port, timeout)
  219. try:
  220. log('Waiting until node becomes available for 1 second')
  221. time.sleep(1)
  222. log('Check if node is available')
  223. conn.request('GET', '')
  224. res = conn.getresponse()
  225. if res.status == 200:
  226. return True
  227. except socket.error as e:
  228. log("Failed while waiting for node - Exception: [%s]" % e)
  229. #that is ok it might not be there yet
  230. finally:
  231. conn.close()
  232. return False
  233. # Checks the pom.xml for the release version.
  234. # This method fails if the pom file has no SNAPSHOT version set ie.
  235. # if the version is already on a release version we fail.
  236. # Returns the next version string ie. 0.90.7
  237. def find_release_version(src_branch):
  238. run('git checkout %s' % src_branch)
  239. with open('pom.xml', encoding='utf-8') as file:
  240. for line in file:
  241. match = re.search(r'<version>(.+)-SNAPSHOT</version>', line)
  242. if match:
  243. return match.group(1)
  244. raise RuntimeError('Could not find release version in branch %s' % src_branch)
  245. def artifact_names(release, path = ''):
  246. return [os.path.join(path, 'elasticsearch-%s.%s' % (release, t)) for t in ['deb', 'tar.gz', 'zip']]
  247. def get_artifacts(release):
  248. common_artifacts = artifact_names(release, 'target/releases/')
  249. for f in common_artifacts:
  250. if not os.path.isfile(f):
  251. raise RuntimeError('Could not find required artifact at %s' % f)
  252. rpm = os.path.join('target/rpm/elasticsearch/RPMS/noarch/', 'elasticsearch-%s-1.noarch.rpm' % release)
  253. if os.path.isfile(rpm):
  254. log('RPM [%s] contains: ' % rpm)
  255. run('rpm -pqli %s' % rpm)
  256. # this is an oddness of RPM that is attches -1 so we have to rename it
  257. renamed_rpm = os.path.join('target/rpm/elasticsearch/RPMS/noarch/', 'elasticsearch-%s.noarch.rpm' % release)
  258. shutil.move(rpm, renamed_rpm)
  259. common_artifacts.append(renamed_rpm)
  260. else:
  261. raise RuntimeError('Could not find required artifact at %s' % rpm)
  262. return common_artifacts
  263. # Generates sha1 checsums for all files
  264. # and returns the checksum files as well
  265. # as the given files in a list
  266. def generate_checksums(files):
  267. res = []
  268. for release_file in files:
  269. directory = os.path.dirname(release_file)
  270. file = os.path.basename(release_file)
  271. checksum_file = '%s.sha1.txt' % file
  272. if os.system('cd %s; shasum %s > %s' % (directory, file, checksum_file)):
  273. raise RuntimeError('Failed to generate checksum for file %s' % release_file)
  274. res = res + [os.path.join(directory, checksum_file), release_file]
  275. return res
  276. def download_and_verify(release, files, plugins=None, base_url='https://download.elasticsearch.org/elasticsearch/elasticsearch'):
  277. print('Downloading and verifying release %s from %s' % (release, base_url))
  278. tmp_dir = tempfile.mkdtemp()
  279. try:
  280. downloaded_files = []
  281. for file in files:
  282. name = os.path.basename(file)
  283. url = '%s/%s' % (base_url, name)
  284. abs_file_path = os.path.join(tmp_dir, name)
  285. print(' Downloading %s' % (url))
  286. downloaded_files.append(abs_file_path)
  287. urllib.request.urlretrieve(url, abs_file_path)
  288. url = ''.join([url, '.sha1.txt'])
  289. checksum_file = os.path.join(tmp_dir, ''.join([abs_file_path, '.sha1.txt']))
  290. urllib.request.urlretrieve(url, checksum_file)
  291. print(' Verifying checksum %s' % (checksum_file))
  292. run('cd %s && sha1sum -c %s' % (tmp_dir, os.path.basename(checksum_file)))
  293. smoke_test_release(release, downloaded_files, get_tag_hash('v%s' % release), plugins)
  294. print(' SUCCESS')
  295. finally:
  296. shutil.rmtree(tmp_dir)
  297. def smoke_test_release(release, files, expected_hash, plugins):
  298. for release_file in files:
  299. if not os.path.isfile(release_file):
  300. raise RuntimeError('Smoketest failed missing file %s' % (release_file))
  301. tmp_dir = tempfile.mkdtemp()
  302. if release_file.endswith('tar.gz'):
  303. run('tar -xzf %s -C %s' % (release_file, tmp_dir))
  304. elif release_file.endswith('zip'):
  305. run('unzip %s -d %s' % (release_file, tmp_dir))
  306. else:
  307. log('Skip SmokeTest for [%s]' % release_file)
  308. continue # nothing to do here
  309. es_run_path = os.path.join(tmp_dir, 'elasticsearch-%s' % (release), 'bin/elasticsearch')
  310. print(' Smoke testing package [%s]' % release_file)
  311. es_plugin_path = os.path.join(tmp_dir, 'elasticsearch-%s' % (release),'bin/plugin')
  312. plugin_names = {}
  313. for name, plugin in plugins:
  314. print(' Install plugin [%s] from [%s]' % (name, plugin))
  315. run('%s %s %s' % (es_plugin_path, '-install', plugin))
  316. plugin_names[name] = True
  317. if release.startswith("0.90."):
  318. background = '' # 0.90.x starts in background automatically
  319. else:
  320. background = '-d'
  321. print(' Starting elasticsearch deamon from [%s]' % os.path.join(tmp_dir, 'elasticsearch-%s' % release))
  322. run('%s; %s -Des.node.name=smoke_tester -Des.cluster.name=prepare_release -Des.discovery.zen.ping.multicast.enabled=false %s'
  323. % (java_exe(), es_run_path, background))
  324. conn = HTTPConnection('127.0.0.1', 9200, 20);
  325. wait_for_node_startup()
  326. try:
  327. try:
  328. conn.request('GET', '')
  329. res = conn.getresponse()
  330. if res.status == 200:
  331. version = json.loads(res.read().decode("utf-8"))['version']
  332. if release != version['number']:
  333. raise RuntimeError('Expected version [%s] but was [%s]' % (release, version['number']))
  334. if version['build_snapshot']:
  335. raise RuntimeError('Expected non snapshot version')
  336. if version['build_hash'].strip() != expected_hash:
  337. raise RuntimeError('HEAD hash does not match expected [%s] but got [%s]' % (expected_hash, version['build_hash']))
  338. print(' Running REST Spec tests against package [%s]' % release_file)
  339. run_mvn('test -Dtests.rest=%s -Dtests.class=*.*RestTests' % ("127.0.0.1:9200"))
  340. print(' Verify if plugins are listed in _nodes')
  341. conn.request('GET', '/_nodes?plugin=true&pretty=true')
  342. res = conn.getresponse()
  343. if res.status == 200:
  344. nodes = json.loads(res.read().decode("utf-8"))['nodes']
  345. for _, node in nodes.items():
  346. node_plugins = node['plugins']
  347. for node_plugin in node_plugins:
  348. if not plugin_names.get(node_plugin['name'], False):
  349. raise RuntimeError('Unexpeced plugin %s' % node_plugin['name'])
  350. del plugin_names[node_plugin['name']]
  351. if plugin_names:
  352. raise RuntimeError('Plugins not loaded %s' % list(plugin_names.keys()))
  353. else:
  354. raise RuntimeError('Expected HTTP 200 but got %s' % res.status)
  355. else:
  356. raise RuntimeError('Expected HTTP 200 but got %s' % res.status)
  357. finally:
  358. conn.request('POST', '/_cluster/nodes/_local/_shutdown')
  359. time.sleep(1) # give the node some time to shut down
  360. if conn.getresponse().status != 200:
  361. raise RuntimeError('Expected HTTP 200 but got %s on node shutdown' % res.status)
  362. finally:
  363. conn.close()
  364. shutil.rmtree(tmp_dir)
  365. def merge_tag_push(remote, src_branch, release_version, dry_run):
  366. run('git checkout %s' % src_branch)
  367. run('git merge %s' % release_branch(release_version))
  368. run('git tag v%s' % release_version)
  369. if not dry_run:
  370. run('git push %s %s' % (remote, src_branch)) # push the commit
  371. run('git push %s v%s' % (remote, release_version)) # push the tag
  372. else:
  373. print(' dryrun [True] -- skipping push to remote %s' % remote)
  374. def publish_artifacts(artifacts, base='elasticsearch/elasticsearch', dry_run=True):
  375. location = os.path.dirname(os.path.realpath(__file__))
  376. for artifact in artifacts:
  377. if dry_run:
  378. print('Skip Uploading %s to Amazon S3' % artifact)
  379. else:
  380. print('Uploading %s to Amazon S3' % artifact)
  381. # requires boto to be installed but it is not available on python3k yet so we use a dedicated tool
  382. run('python %s/upload-s3.py --file %s ' % (location, os.path.abspath(artifact)))
  383. def print_sonartype_notice():
  384. settings = os.path.join(os.path.expanduser('~'), '.m2/settings.xml')
  385. if os.path.isfile(settings):
  386. with open(settings, encoding='utf-8') as settings_file:
  387. for line in settings_file:
  388. if line.strip() == '<id>sonatype-nexus-snapshots</id>':
  389. # moving out - we found the indicator no need to print the warning
  390. return
  391. print("""
  392. NOTE: No sonartype settings detected, make sure you have configured
  393. your sonartype credentials in '~/.m2/settings.xml':
  394. <settings>
  395. ...
  396. <servers>
  397. <server>
  398. <id>sonatype-nexus-snapshots</id>
  399. <username>your-jira-id</username>
  400. <password>your-jira-pwd</password>
  401. </server>
  402. <server>
  403. <id>sonatype-nexus-staging</id>
  404. <username>your-jira-id</username>
  405. <password>your-jira-pwd</password>
  406. </server>
  407. </servers>
  408. ...
  409. </settings>
  410. """)
  411. def check_s3_credentials():
  412. if not env.get('AWS_ACCESS_KEY_ID', None) or not env.get('AWS_SECRET_ACCESS_KEY', None):
  413. raise RuntimeError('Could not find "AWS_ACCESS_KEY_ID" / "AWS_SECRET_ACCESS_KEY" in the env variables please export in order to upload to S3')
  414. VERSION_FILE = 'src/main/java/org/elasticsearch/Version.java'
  415. POM_FILE = 'pom.xml'
  416. # we print a notice if we can not find the relevant infos in the ~/.m2/settings.xml
  417. print_sonartype_notice()
  418. if __name__ == '__main__':
  419. parser = argparse.ArgumentParser(description='Builds and publishes a Elasticsearch Release')
  420. parser.add_argument('--branch', '-b', metavar='master', default=get_current_branch(),
  421. help='The branch to release from. Defaults to the current branch.')
  422. parser.add_argument('--cpus', '-c', metavar='1', default=1,
  423. help='The number of cpus to use for running the test. Default is [1]')
  424. parser.add_argument('--skiptests', '-t', dest='tests', action='store_false',
  425. help='Skips tests before release. Tests are run by default.')
  426. parser.set_defaults(tests=True)
  427. parser.add_argument('--remote', '-r', metavar='origin', default='origin',
  428. help='The remote to push the release commit and tag to. Default is [origin]')
  429. parser.add_argument('--publish', '-d', dest='dryrun', action='store_false',
  430. help='Publishes the release. Disable by default.')
  431. parser.add_argument('--smoke', '-s', dest='smoke', default='',
  432. help='Smoke tests the given release')
  433. parser.set_defaults(dryrun=True)
  434. parser.set_defaults(smoke=None)
  435. args = parser.parse_args()
  436. src_branch = args.branch
  437. remote = args.remote
  438. run_tests = args.tests
  439. dry_run = args.dryrun
  440. cpus = args.cpus
  441. build = not args.smoke
  442. smoke_test_version = args.smoke
  443. if not dry_run:
  444. check_s3_credentials()
  445. print('WARNING: dryrun is set to "false" - this will push and publish the release')
  446. input('Press Enter to continue...')
  447. print(''.join(['-' for _ in range(80)]))
  448. print('Preparing Release from branch [%s] running tests: [%s] dryrun: [%s]' % (src_branch, run_tests, dry_run))
  449. print(' JAVA_HOME is [%s]' % JAVA_HOME)
  450. print(' Running with maven command: [%s] ' % (MVN))
  451. if build:
  452. release_version = find_release_version(src_branch)
  453. if not dry_run:
  454. smoke_test_version = release_version
  455. head_hash = get_head_hash()
  456. run_mvn('clean') # clean the env!
  457. print(' Release version: [%s]' % release_version)
  458. create_release_branch(remote, src_branch, release_version)
  459. print(' Created release branch [%s]' % (release_branch(release_version)))
  460. success = False
  461. try:
  462. pending_files = [POM_FILE, VERSION_FILE]
  463. remove_maven_snapshot(POM_FILE, release_version)
  464. remove_version_snapshot(VERSION_FILE, release_version)
  465. pending_files = pending_files + update_reference_docs(release_version)
  466. print(' Done removing snapshot version')
  467. add_pending_files(*pending_files) # expects var args use * to expand
  468. commit_release(release_version)
  469. print(' Committed release version [%s]' % release_version)
  470. print(''.join(['-' for _ in range(80)]))
  471. print('Building Release candidate')
  472. input('Press Enter to continue...')
  473. if not dry_run:
  474. print(' Running maven builds now and publish to sonartype - run-tests [%s]' % run_tests)
  475. else:
  476. print(' Running maven builds now run-tests [%s]' % run_tests)
  477. build_release(run_tests=run_tests, dry_run=dry_run, cpus=cpus)
  478. artifacts = get_artifacts(release_version)
  479. artifacts_and_checksum = generate_checksums(artifacts)
  480. smoke_test_release(release_version, artifacts, get_head_hash(), PLUGINS)
  481. print(''.join(['-' for _ in range(80)]))
  482. print('Finish Release -- dry_run: %s' % dry_run)
  483. input('Press Enter to continue...')
  484. print(' merge release branch, tag and push to %s %s -- dry_run: %s' % (remote, src_branch, dry_run))
  485. merge_tag_push(remote, src_branch, release_version, dry_run)
  486. print(' publish artifacts to S3 -- dry_run: %s' % dry_run)
  487. publish_artifacts(artifacts_and_checksum, dry_run=dry_run)
  488. pending_msg = """
  489. Release successful pending steps:
  490. * create a version tag on github for version 'v%(version)s'
  491. * check if there are pending issues for this version (https://github.com/elasticsearch/elasticsearch/issues?labels=v%(version)s&page=1&state=open)
  492. * publish the maven artifacts on sonartype: https://oss.sonatype.org/index.html
  493. - here is a guide: https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-8a.ReleaseIt
  494. * check if the release is there https://oss.sonatype.org/content/repositories/releases/org/elasticsearch/elasticsearch/%(version)s
  495. * announce the release on the website / blog post
  496. * tweet about the release
  497. * announce the release in the google group/mailinglist
  498. """
  499. print(pending_msg % { 'version' : release_version} )
  500. success = True
  501. finally:
  502. if not success:
  503. run('git reset --hard HEAD')
  504. run('git checkout %s' % src_branch)
  505. elif dry_run:
  506. run('git reset --hard %s' % head_hash)
  507. run('git tag -d v%s' % release_version)
  508. # we delete this one anyways
  509. run('git branch -D %s' % (release_branch(release_version)))
  510. else:
  511. print("Skipping build - smoketest only against version %s" % smoke_test_version)
  512. run_mvn('clean') # clean the env!
  513. if smoke_test_version:
  514. fetch(remote)
  515. download_and_verify(smoke_test_version, artifact_names(smoke_test_version), plugins=PLUGINS)