From e4af3412f75a95c56b6650961c1e5b41caad1da0 Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Wed, 12 Apr 2017 20:01:32 -0700 Subject: [PATCH] add swagger checker update travis upadte travis update update travis update travis update to git commit id add travis var add push and pull support --- .travis.yml | 1 + tests/swaggerchecker.sh | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 tests/swaggerchecker.sh diff --git a/.travis.yml b/.travis.yml index 8977620aa..df904d80a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -101,6 +101,7 @@ script: - docker ps - ./tests/notarytest.sh + - ./tests/swaggerchecker.sh - ./tests/startuptest.sh - ./tests/userlogintest.sh ${HARBOR_ADMIN} ${HARBOR_ADMIN_PASSWD} diff --git a/tests/swaggerchecker.sh b/tests/swaggerchecker.sh new file mode 100755 index 000000000..83a05a5ae --- /dev/null +++ b/tests/swaggerchecker.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +set +e + +SWAGGER_ONLINE_VALIDATOR="http://online.swagger.io/validator" +if [ $TRAVIS_EVENT_TYPE = "push" ]; then + HARBOR_SWAGGER_FILE="https://raw.githubusercontent.com/$TRAVIS_REPO_SLUG/$TRAVIS_COMMIT/docs/swagger.yaml" +elif [ $TRAVIS_EVENT_TYPE = "pull_request" ]; then + HARBOR_SWAGGER_FILE="https://raw.githubusercontent.com/$TRAVIS_PULL_REQUEST_SLUG/$TRAVIS_PULL_REQUEST_SHA/docs/swagger.yaml" +else + echo "* don't support this kinds of action ($TRAVIS_EVENT_TYPE), but don't fail the travis CI." + exit 0 +fi +HARBOR_SWAGGER_VALIDATOR_URL="$SWAGGER_ONLINE_VALIDATOR/debug?url=$HARBOR_SWAGGER_FILE" +echo $HARBOR_SWAGGER_VALIDATOR_URL + +# Now try to ping swagger online validator, then to use it to do the validation. +eval curl -f -I $SWAGGER_ONLINE_VALIDATOR +curl_ping_res=$? +if [ ${curl_ping_res} -eq 0 ]; then + echo "* cURL ping swagger validator returned success" +else + echo "* cURL ping swagger validator returned an error (${curl_ping_res}), but don't fail the travis CI here." + exit 0 +fi + +# Use the swagger online validator to validate the harbor swagger file. +eval curl -s $HARBOR_SWAGGER_VALIDATOR_URL > output.json +curl_validate_res=$? +validate_expected_results="{}" +validate_actual_results=$(cat < output.json) + +if [ ${curl_validate_res} -eq 0 ]; then + if [ $validate_actual_results = $validate_expected_results ]; then + echo "* cURL check Harbor swagger file returned success" + else + echo "* cURL check Harbor swagger file returned an error ($validate_actual_results)" + fi +else + echo "* cURL check Harbor swagger file returned an error (${curl_validate_res})" + exit ${curl_validate_res} +fi