diff --git build-support/scripts/release.py build-support/scripts/release.py new file mode 100755 index 0000000..a270cc9 --- /dev/null +++ build-support/scripts/release.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python + +# 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 os +import os.path +import subprocess +import sys + +from optparse import OptionParser + +def get_snapshot_version(): + with open('build.properties') as f: + for line in f.readlines(): + if line.startswith('hcatalog.version='): + return line.strip().split('=')[1] + +def update_poms(release_version): + snapshot_version = get_snapshot_version() + for root, dirs, files in os.walk(os.getcwd()): + for filename in files: + if filename in ['build.properties', 'pom.xml']: + abs_filename = os.path.join(root, filename) + lines = [] + with open(abs_filename) as f: + for line in f: + lines.append(line.replace(snapshot_version, release_version)) + with open(abs_filename, 'w') as f: + f.write(''.join(lines)) + +def main(): + parser = OptionParser(usage=('usage: %prog [options])\n\n' + 'This tool automates HCatalog release-releated tasks, providing ' + 'flexibility around the build and deploy process (useful for ' + 'site-specific customization). For more information, see ' + 'https://cwiki.apache.org/confluence/display/HCATALOG/HowToRelease')) + parser.add_option('--dry-run', + dest='dry_run', + default=False, + action='store_true', + help=('Perform a release dry run, which appends `dryrun` to the version ' + 'and does not publish artifacts to Maven. (default: %default)')) + parser.add_option('--release-version', + dest='release_version', + default=None, + help='HCatalog release version. (default: %default)') + parser.add_option('--forrest-home', + dest='forrest_home', + default='/usr/local/apache-forrest-0.9', + help='Path to the Apache Forrest home. (default: %default)') + parser.add_option('--mvn-deploy-repo-id', + dest='mvn_deploy_repo_id', + default='apache.releases.https', + help=('Maven repo id to publish to. This id must exist in your ' + 'settings.xml, along with your username/password to publish ' + 'artifacts. For more information, see ' + 'http://maven.apache.org/settings.html#Servers (default: %default)')) + parser.add_option('--mvn-deploy-repo-url', + dest='mvn_deploy_repo_url', + default='https://repository.apache.org/service/local/staging/deploy/maven2', + help='Maven repo URL to publish to. (default: %default)') + parser.add_option('--ant-args', + dest='ant_args', + default=None, + help=('Extra args for ant, such as overriding something from ' + '`build.properties`. (default: %default)')) + (options, args) = parser.parse_args() + + if len(sys.argv) == 0: + parser.print_help() + sys.exit(-1) + + if options.release_version is None: + print('Required option --release-version not set!') + parser.print_help() + sys.exit(-1) + + ant_args = [] + if os.environ.has_key('ANT_ARGS'): + ant_args.append(os.environ['ANT_ARGS']) + if options.ant_args is not None: + ant_args.append(options.ant_args) + + if options.dry_run: + options.release_version = '%s-dryrun' % options.release_version + else: + ant_args.extend([ + '-Dmvn.deploy.repo.id=%s' % options.mvn_deploy_repo_id, + '-Dmvn.deploy.repo.url=%s' % options.mvn_deploy_repo_url, + ]) + os.environ['HCAT_MVN_DEPLOY'] = 'true' + + os.environ['FORREST_HOME'] = options.forrest_home + os.environ['ANT_ARGS'] = ' '.join(ant_args) + + update_poms(options.release_version) + + subprocess.Popen(os.path.join(os.path.dirname(__file__), 'test.sh'), + env=os.environ, stdout=sys.stdout, stderr=sys.stderr).communicate() + +if __name__ == '__main__': + main() diff --git build-support/scripts/release.sh build-support/scripts/release.sh deleted file mode 100755 index 2e0ea1a..0000000 --- build-support/scripts/release.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -# 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. - -# HCatalog uses maven for resolving dependencies and publishing artifacts. -# Maven requires project version numbers be hard-coded in pom.xml files, -# rather than being typical variables. Tooling in provided by maven to ease -# managing these version numbers, however, as our build is ant-based -# we cannot use that tooling. This release script is a workaround to -# update pom.xml version numbers to properly build release artifacts. - -if [ "${HCAT_RELEASE_VERSION}" == "" ]; then - echo "Required environment variable HCAT_RELEASE_VERSION not set." - exit -1 -fi - -snapshot_version=$(awk -F= '/hcatalog.version=/ { print $2 }' build.properties) - -find . -name pom.xml -exec sed -i '' "s/${snapshot_version}/${HCAT_RELEASE_VERSION}/" {} \; -sed -i '' "s/${snapshot_version}/${HCAT_RELEASE_VERSION}/" build.properties - -# useful to pass in "-Dtestcase=Foo" to bypass tests when troubleshooting builds -export ANT_ARGS="${ANT_ARGS}" - -./build-support/scripts/test.sh diff --git build-support/scripts/test.sh build-support/scripts/test.sh index 528d2f6..ea15634 100755 --- build-support/scripts/test.sh +++ build-support/scripts/test.sh @@ -55,8 +55,10 @@ run_cmd # Build and run tests with hadoop20. This must happen afterwards so test results # are available for CI to publish. -cmd='ant -Dtest.junit.output.format=xml clean releaseaudit package test' +cmd="ant -Dtest.junit.output.format=xml -Dforrest.home=${FORREST_HOME} clean releaseaudit package test" if [ "${HUDSON_URL}" == "https://builds.apache.org/" ]; then cmd="${cmd} mvn-deploy" +elif [ "${HCAT_MVN_DEPLOY}" == "true" ]; then + cmd="${cmd} mvn-deploy-signed" fi run_cmd