build_release.py 25 KB

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