On 9.12.2015 15:30, Petr Spacek wrote: > Hello, > > this patch automates some of sanity checks proposed by Petr Vobornik. > > 'make review' should be used in root of clean Git tree which has patches under > review applied. > > Magic in review.sh attempts to detect nearest remote branch which can be used > as diff base for review. Please see review.sh for further details.
And here is the patch! :-) -- Petr^2 Spacek
From 52393bf2bb0ad74dbe37e496b1fd41a6ab22bd90 Mon Sep 17 00:00:00 2001 From: Petr Spacek <pspa...@redhat.com> Date: Tue, 8 Dec 2015 12:06:33 +0100 Subject: [PATCH] Add 'review' target for make. It automates following tasks: - check if ACI.txt and API.txt are up-to-date - check if VERSION was changed if API was changed - pep8 --diff does not produce new errors when ran on diff from origin/branch - make lint does not produce errors --- Makefile | 4 ++++ review.sh | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100755 review.sh diff --git a/Makefile b/Makefile index d2c37f1597a011af2bd9ef1a4f7ce87ac59620a3..b85b3a5d6362150dcebf16745414c3d416c9547f 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,10 @@ check: bootstrap-autogen server tests (cd $$subdir && $(MAKE) check) || exit 1; \ done +# works only in Git tree +review: version-update + ./review.sh + bootstrap-autogen: version-update client-autogen @echo "Building IPA $(IPA_VERSION)" cd asn1; if [ ! -e Makefile ]; then ../autogen.sh --prefix=/usr --sysconfdir=/etc --localstatedir=/var --libdir=$(LIBDIR); fi diff --git a/review.sh b/review.sh new file mode 100755 index 0000000000000000000000000000000000000000..3a5114fbe88d3aba8e926e049500f5ac5f41a83e --- /dev/null +++ b/review.sh @@ -0,0 +1,64 @@ +#!/bin/bash +is_tree_clean() { + test "$(git status --porcelain "$@")" == "" + return $? +} + +log_error() { + echo "ERROR: ${1}, continuing ..." + errs=(${errs[@]} "ERROR: ${1}\n") +} + +set -o errexit -o nounset #-o xtrace + +LOGFILE="$(mktemp --suff=.log)" +exec > >(tee -i ${LOGFILE}) +exec 2>&1 + +echo -n "make lint is running ... " +make --silent lint || log_error "make lint failed" + +# Go backwards in history until you find a remote branch from which current +# branch was created. This will be used as base for git diff. +PATCHCNT=0 +BASEBRANCH="" +CURRBRANCH="$(git branch --remote --contains)" +while [ "${BASEBRANCH}" == "" ] +do + BASEBRANCH="$(git branch --remote --contains "HEAD~${PATCHCNT}" | grep -v "^. ${CURRBRANCH}$" || :)" + PATCHCNT="$(expr "${PATCHCNT}" + 1)" +done +echo "Detected base branch: ${BASEBRANCH}" +echo -n "Checks will be made against following base commit: " +git log -1 --oneline ${BASEBRANCH} + +# gather all errors in one array and print error summary at the end +declare -a errs +errs=("Summary of detected errors:\n") + +is_tree_clean || log_error "Git tree must be clean before you start review" + +./makeapi +is_tree_clean "API.txt" || log_error "./makeapi changed something" + +./makeaci +is_tree_clean "ACI.txt" || log_error "./makeaci changed something" + +git diff ${BASEBRANCH} -U0 | pep8 --diff || log_error "PEP8 --diff failed" + +# if API.txt is changed require change in VERSION +if ! git diff ${BASEBRANCH} --quiet -- API.txt; +then + git diff ${BASEBRANCH} --quiet -- VERSION && log_error "API.txt was changed without a change in VERSION" +fi + +# print error summary +if [ "${#errs[*]}" != "1" ] +then + echo -e "${errs[*]}" + echo "Please see ${LOGFILE}" + exit 1 +else + rm "${LOGFILE}" + echo "review.sh did not detect any problem" +fi -- 2.5.0
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code