From: Thanh Ha Date: Mon, 6 Mar 2017 03:57:24 +0000 (-0500) Subject: Add patch-odl-release as a subcommand of version X-Git-Tag: v0.0.7^0 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F59%2F4059%2F3;p=releng%2Flftools.git Add patch-odl-release as a subcommand of version This patch makes patch-odl-release be less specific to the OpenDaylight project in case other projects might want to use it in the future. It also moves it into the version tool as a sub-command. Refactor cli code around to make it easier to manage version subcommands. Change-Id: I100927195f61c33584219445a9dfac1e3e59ceab Signed-off-by: Thanh Ha --- diff --git a/lftools/cli/__init__.py b/lftools/cli/__init__.py new file mode 100644 index 00000000..52222b4a --- /dev/null +++ b/lftools/cli/__init__.py @@ -0,0 +1,30 @@ +# @License 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={}) diff --git a/lftools/cli.py b/lftools/cli/version.py similarity index 59% rename from lftools/cli.py rename to lftools/cli/version.py index c380a5e4..10b3cedd 100644 --- a/lftools/cli.py +++ b/lftools/cli/version.py @@ -10,39 +10,21 @@ # 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: ..[-] * Human readable tag should not have any dots in it @@ -70,11 +52,61 @@ def version(ctx, command, release_tag): #. 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) diff --git a/setup.py b/setup.py index c7d860ea..99541182 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open('requirements.txt') as f: setup( name='lftools', - version='0.0.6', + version='0.0.7', author='Thanh Ha', author_email='thanh.ha@linuxfoundation.org', url='', @@ -39,7 +39,6 @@ setup( lftools=lftools.cli:cli ''', scripts=[ - 'shell/patch-odl-release', 'shell/version', ], ) diff --git a/shell/patch-odl-release b/shell/patch-odl-release deleted file mode 100755 index b6779aec..00000000 --- a/shell/patch-odl-release +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash - -# @License 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 \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" diff --git a/shell/version b/shell/version index 12a74995..4c8f432e 100755 --- a/shell/version +++ b/shell/version @@ -62,6 +62,12 @@ version() { 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 @@ -103,6 +109,77 @@ version_release() { 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