From 8ae0aee7e55756d2bb41afb6d4eab114ff57b60b Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Mon, 13 Nov 2017 16:26:10 +0100 Subject: [PATCH] hack: validate tests for crioctl deprecation Signed-off-by: Antonio Murdaca --- .travis.yml | 3 +++ Makefile | 3 +++ hack/validate/.validate | 30 ++++++++++++++++++++++++++++++ hack/validate/deprecate-crioctl | 31 +++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 hack/validate/.validate create mode 100755 hack/validate/deprecate-crioctl diff --git a/.travis.yml b/.travis.yml index 3e1047b2..293177b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,7 @@ jobs: - make .gitvalidation - make gofmt - make lint + - make verify - make testunit - make docs - make @@ -41,12 +42,14 @@ jobs: - make .gitvalidation - make gofmt - make lint + - make verify - make testunit - make docs - make go: 1.9.x - script: - make .gitvalidation + - make verify - make testunit - make docs - make diff --git a/Makefile b/Makefile index c458fd37..5f3a74a3 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,9 @@ lint: .gopathok gofmt: @./hack/verify-gofmt.sh +verify: + @./hack/validate/deprecate-crioctl + conmon: $(MAKE) -C $@ diff --git a/hack/validate/.validate b/hack/validate/.validate new file mode 100644 index 00000000..9f05ff11 --- /dev/null +++ b/hack/validate/.validate @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -e -o pipefail + +if [ -z "$VALIDATE_UPSTREAM" ]; then + # this is kind of an expensive check, so let's not do this twice if we + # are running more than one validate bundlescript + + VALIDATE_REPO='https://github.com/kubernetes-incubator/cri-o.git' + VALIDATE_BRANCH='master' + + VALIDATE_HEAD="$(git rev-parse --verify HEAD)" + + git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH" + VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)" + + VALIDATE_COMMIT_LOG="$VALIDATE_UPSTREAM..$VALIDATE_HEAD" + VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD" + + validate_diff() { + if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then + git diff "$VALIDATE_COMMIT_DIFF" "$@" + fi + } + validate_log() { + if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then + git log "$VALIDATE_COMMIT_LOG" "$@" + fi + } +fi diff --git a/hack/validate/deprecate-crioctl b/hack/validate/deprecate-crioctl new file mode 100755 index 00000000..e71a434d --- /dev/null +++ b/hack/validate/deprecate-crioctl @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# Check that no new tests are being added using crioctl + +export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "${SCRIPTDIR}/.validate" + +IFS=$'\n' +files=( $(validate_diff --diff-filter=ACMR --name-only -- 'test/*.bats' || true) ) +unset IFS + +badFiles=() +for f in "${files[@]}"; do + # we use "git show" here to validate that what's committed doesn't contain crioctl calls + if git show "$VALIDATE_HEAD:$f" | grep -q crioctl; then + badFiles+=( "$f" ) + fi +done + +if [ ${#badFiles[@]} -eq 0 ]; then + echo 'Congratulations! No new tests have been added using crioctl.' +else + { + echo "These files use crioctl instead of crictl:" + echo "" + for f in "${badFiles[@]}"; do + echo " - $f" + done + echo + } >&2 + false +fi