--- /dev/null
+# @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
+##############################################################################
+# Copyright (c) 2017 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Thanh Ha - Initial implementation
+##############################################################################
+"""CLI main for lftools."""
+import click
+from lftools.cli.version import version
+
+
+@click.group()
+@click.pass_context
+@click.version_option()
+def cli(ctx):
+ """CLI entry point for lftools."""
+ pass
+
+
+cli.add_command(version)
+
+
+if __name__ == '__main__':
+ cli(obj={})
# Contributors:
# Thanh Ha - Initial implementation
##############################################################################
-"""CLI main for lftools."""
+"""Wrapper for version bash script."""
+import os
import subprocess
+import sys
import click
@click.group()
@click.pass_context
-@click.version_option()
-def cli(ctx):
- """CLI entry point for lftools."""
- pass
-
-
-###############################################################################
-# Shell
-###############################################################################
-
-@click.command()
-@click.argument('command', type=click.Choice(['bump', 'release']))
-@click.argument('release-tag')
-@click.pass_context
-def version(ctx, command, release_tag):
+def version(ctx):
"""Version bump script for Maven based projects.
Uses *release-tag* to bump versions for Maven projects.
- :arg str command: Version subcommand to call (bump|release)
- :arg str release-tag: When used for the 'release' command it is the
- tag to use to bump all the versions to. When used for the 'bump'
- command it is the tag to determine if a version should be bumped by
- x.1.z.
-
In general, versions should be: <major>.<minor>.<micro>[-<human-readable-tag>]
* Human readable tag should not have any dots in it
#. take all x.y.z-SNAPSHOT to x.y.z-Helium
#. take all x.y.z-Helium versions to x.y.(z+1)-SNAPSHOT and
#. take all x.y.z-SNAPSHOT versions to x.(y+1).0-SNAPSHOT
+
+ Commands:
+
+ .. autofunction:: lftools.cli.version.bump
+ .. autofunction:: lftools.cli.version.release
+ .. autofunction:: lftools.cli.version.patch
"""
- subprocess.call(['version', command, release_tag])
+ pass
+@click.command()
+@click.argument('release-tag')
+@click.pass_context
+def bump(ctx, release_tag):
+ """Version bump pom files in a Maven project by x.(y+1).z.
+
+ :arg str release-tag: When used for the 'bump' command it is the tag to
+ determine if a version should be bumped by x.(y+1).z (SNAPSHOT) or by
+ x.y.(z+1) (release-tag).
+ """
+ subprocess.call(['version', 'bump', release_tag])
+
+
+@click.command()
+@click.argument('release-tag')
+@click.pass_context
+def release(ctx, release_tag):
+ """Version bump pom files in a Maven project by x.y.(z+1).
+
+ :arg str release-tag: When used for the 'release' command it is the
+ tag to use to bump all the versions to.
+ """
+ subprocess.call(['version', 'release', release_tag])
+
+
+@click.command()
+@click.argument('release-tag')
+@click.argument('patch-dir')
+@click.option('--project', default='OpenDaylight')
+@click.pass_context
+def patch(ctx, release_tag, patch_dir, project):
+ """Patch a project with git.bundles and then version bump by x.y.(z+1).
+
+ :arg str release-tag: When used for the 'release' command it is the
+ tag to use to bump all the versions to. When used for the 'bump'
+ command it is the tag to determine if a version should be bumped by
+ x.1.z.
+ :arg str patch-dir: Path to where the taglist.log and git.bundles are
+ stored in the file system.
+ """
+ if not os.path.isdir(patch_dir):
+ print("{} is not a valid directory.".format(patch_dir))
+ sys.exit(404)
+ subprocess.call(['version', 'patch', release_tag, patch_dir, project])
-cli.add_command(version)
-if __name__ == '__main__':
- cli(obj={})
+version.add_command(bump)
+version.add_command(patch)
+version.add_command(release)
setup(
name='lftools',
- version='0.0.6',
+ version='0.0.7',
author='Thanh Ha',
author_email='thanh.ha@linuxfoundation.org',
url='',
lftools=lftools.cli:cli
''',
scripts=[
- 'shell/patch-odl-release',
'shell/version',
],
)
+++ /dev/null
-#!/bin/bash
-
-# @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
-##############################################################################
-# Copyright (c) 2015 The Linux Foundation and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-# Thanh Ha - Initial implementation
-##############################################################################
-
-# The purpose of this patch is to:
-#
-# 1) Apply autorelease patches for a ODL Release
-# 2) Create version bump commit for post-release dev cycle
-
-USAGE="USAGE: patch-odl-release <path-to-patches> <tag>\n\
-\n\
-path-to-patches - The path to the directory containing ODL Release patches\n\
-tag - example: Lithium-SR1"
-
-if [ -z "$2" ]
-then
- echo -e "$USAGE"
- exit 1
-fi
-
-PATCH_DIR=$1
-RELEASE_TAG=$2
-STABLE_BRANCH="stable/$( cut -d '-' -f1 <<< "${RELEASE_TAG,,}")"
-
-project="${PWD##*/}"
-scriptdir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
-
-# Validate that we're patching at the same commit level as when autorelease
-# built the release. Basically ensuring that no new patches snuck into the
-# project during code freeze.
-EXPECTED_HASH=$(grep "^${project} " "$PATCH_DIR/taglist.log" | awk '{ print $2 }')
-if [ "$EXPECTED_HASH" == "" ]; then
- parent_dir="$(dirname "$(pwd)")"
- project="${parent_dir##*/}/$project"
- EXPECTED_HASH=$(grep "^${project} " "$PATCH_DIR/taglist.log" | awk '{ print $2 }')
-fi
-
-git checkout "$EXPECTED_HASH"
-CURRENT_HASH=$(git rev-parse HEAD)
-
-echo "Current Hash: $CURRENT_HASH"
-echo "Expected Hash: $EXPECTED_HASH"
-if [ "$CURRENT_HASH" != "$EXPECTED_HASH" ]
-then
- echo "ERROR: Current project hash does not match expected hash"
- exit 1
-fi
-
-
-#######################
-# Start apply patches #
-#######################
-git fetch "${PATCH_DIR}/${project/\//-}.bundle"
-git merge FETCH_HEAD
-git tag -asm "OpenDaylight $RELEASE_TAG release" "release/${RELEASE_TAG,,}"
-find . -name pom.xml -print0 | xargs -0 grep SNAPSHOT
-
-git checkout "${STABLE_BRANCH}"
-# Release and then Bump so that the version.sh script creates the right patches
-"$scriptdir/version.sh" release "$RELEASE_TAG"
-"$scriptdir/version.sh" bump "$RELEASE_TAG"
-git commit -asm "Bumping versions by 0.0.1 for next dev cycle"
-find . -name pom.xml -print0 | xargs -0 grep "$RELEASE_TAG"
-
-echo "Tagging and version bumping complete"
version_release
exit 0
;;
+ patch )
+ RELEASE_TAG=$1
+ PATCH_DIR=$2
+ PROJECT=${3:-"OpenDaylight"}
+ version_patch
+ ;;
* )
echo "Invalid command: $subcommand" 1>&2
print_version_usage
done
}
+version_patch() {
+ # Patches a git repo using bundle files and creates a version bump commit
+ #
+ # This command is a macro to perform 3 actions:
+ #
+ # 1) Apply a git.bundle patch to the current repo
+ # 2) Create a git tag against the commit provided by the git.bundle
+ # 3) Version bumps by x.y.(z+1)-SNAPSHOT to prepare repo for next dev cycle
+ #
+ # The original purpose of patch is to:
+ #
+ # 1) Apply autorelease patches for a ODL Release
+ # 2) Create version bump commit for post-release dev cycle
+ #
+ # However we try to ensure the code here is not specific to the OpenDaylight
+ # project in case it is useful for other projects that need to patch multiple
+ # repos in a quick way using git.bundle files.
+ #
+ # Expected variables:
+ # RELEASE_TAG - The release tag of the release being performed
+ # PATCH_DIR - The directory path containing the git.bundle files (and taglist.log)
+ # PROJECT - The top level project that we're patching eg. OpenDaylight
+
+ # OpenDaylight uses the format Boron-SR1 as a release tag where "boron" is
+ # the branch name of the maintenance branch and SR1 (if exists) is the
+ # service release. Strip out the branch from the tag and set the stable release
+ # branch.
+ STABLE_BRANCH="stable/$( cut -d '-' -f1 <<< "${RELEASE_TAG,,}")"
+
+
+ subproject="${PWD##*/}"
+
+ # Validate that we're patching at the same commit level as when autorelease
+ # built the release. Basically ensuring that no new patches snuck into the
+ # project during code freeze.
+ EXPECTED_HASH=$(grep "^${subproject} " "$PATCH_DIR/taglist.log" | awk '{ print $2 }')
+ if [ "$EXPECTED_HASH" == "" ]; then
+ parent_dir="$(dirname "$(pwd)")"
+ subproject="${parent_dir##*/}/$subproject"
+ EXPECTED_HASH=$(grep "^${subproject} " "$PATCH_DIR/taglist.log" | awk '{ print $2 }')
+ fi
+
+ git checkout "$EXPECTED_HASH"
+ CURRENT_HASH=$(git rev-parse HEAD)
+
+ echo "Current Hash: $CURRENT_HASH"
+ echo "Expected Hash: $EXPECTED_HASH"
+ if [ "$CURRENT_HASH" != "$EXPECTED_HASH" ]
+ then
+ echo "ERROR: Current project hash does not match expected hash"
+ exit 1
+ fi
+
+ #######################
+ # Start apply patches #
+ #######################
+ git fetch "${PATCH_DIR}/${subproject/\//-}.bundle"
+ git merge FETCH_HEAD
+ git tag -asm "$PROJECT $RELEASE_TAG release" "release/${RELEASE_TAG,,}"
+ find . -name pom.xml -print0 | xargs -0 grep SNAPSHOT
+
+ git checkout "${STABLE_BRANCH}"
+ # Release and then Bump so that the version.sh script creates the right patches
+ version_release "$RELEASE_TAG"
+ version_bump "$RELEASE_TAG"
+ git commit -asm "Bumping versions by x.y.(z+1) for next dev cycle"
+ find . -name pom.xml -print0 | xargs -0 grep "$RELEASE_TAG"
+
+ echo "Tagging and version bumping complete"
+}
+
# Only run the script if it is being called directly and not sourced.
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
then