diff --git a/.travis.yml b/.travis.yml index 6cd7c43..3238f23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,5 +10,6 @@ script: - go test -race ./... - go vet ./... - diff -u <(echo -n) <(gofmt -d -s .) + - diff -u <(echo -n) <(scripts/autogen_licences.sh .) after_success: - ./scripts/coverage.sh diff --git a/scripts/autogen_licences.sh b/scripts/autogen_licences.sh index 6c31c7a..d8190c1 100755 --- a/scripts/autogen_licences.sh +++ b/scripts/autogen_licences.sh @@ -28,7 +28,11 @@ if [ "$#" -eq 0 ]; then fi DIRECTORY="$1" -WRITE="$2" + +WRITE="" +if [ "$#" -ge 3 ]; then + WRITE="$2" +fi if [ ! -d "${BIN_DIR}" ]; then echo "Directory ${BIN_DIR} doesn't exist." @@ -49,16 +53,23 @@ if [ "${WRITE}" == "WRITE" ]; then DRY_RUN="" else DRY_RUN="echo " - echo "The WRITE argument not specified, dry run mode." - echo "Would have executed:" fi ADD_LICENCE="${DRY_RUN}${AUTOGEN} -i --no-top-level-comment" FIND_FILES="find ${DIRECTORY} -type f -name \*.go" LICENCE="Licensed under the Apache License" +MISSING=0 + for FILE in `eval ${FIND_FILES}`; do if ! grep -q "${LICENCE}" "${FILE}"; then + MISSING=1 eval "${ADD_LICENCE} ${FILE}" fi done + +if [[ ! -z "$DRY_RUN" ]] && [ $MISSING -eq 1 ]; then + echo -e "\nFound files with missing licences. To fix, run the commands above." + echo "Or just execute:" + echo "$0 . WRITE" +fi