diff --git a/Makefile b/Makefile index 93b7cfb54..9a3c3c0b6 100644 --- a/Makefile +++ b/Makefile @@ -12,31 +12,31 @@ project-tools: # LINT lint-golangci-lint: - @echo "Linting with golangci-lint" - @$(SCRIPTS_BASE)/lint-golangci-lint.sh ${skip-non-generated-files} + @echo ">> Linting with golangci-lint" + @$(SCRIPTS_BASE)/lint-golangci-lint.sh "${skip-non-generated-files}" "${service}" lint-scripts: - @echo "Linting scripts" + @echo ">> Linting scripts" @cd ${ROOT_DIR}/scripts && golangci-lint run ${GOLANG_CI_ARGS} sync-tidy: - @echo "Syncing and tidying dependencies" + @echo ">> Syncing and tidying dependencies" @$(SCRIPTS_BASE)/sync-tidy.sh lint: sync-tidy - @$(MAKE) --no-print-directory lint-golangci-lint skip-non-generated-files=${skip-non-generated-files} + @$(MAKE) --no-print-directory lint-golangci-lint skip-non-generated-files=${skip-non-generated-files} service=${service} # TEST test-go: - @echo "Running Go tests" - @$(SCRIPTS_BASE)/test-go.sh ${skip-non-generated-files} + @echo ">> Running Go tests" + @$(SCRIPTS_BASE)/test-go.sh "${skip-non-generated-files}" "${service}" test-scripts: - @echo "Running Go tests for scripts" + @echo ">> Running Go tests for scripts" @go test $(ROOT_DIR)/scripts/... ${GOTEST_ARGS} test: - @$(MAKE) --no-print-directory test-go skip-non-generated-files=${skip-non-generated-files} + @$(MAKE) --no-print-directory test-go skip-non-generated-files=${skip-non-generated-files} service=${service} # AUTOMATIC TAG sdk-tag-services: diff --git a/scripts/lint-golangci-lint.sh b/scripts/lint-golangci-lint.sh index 28cdd476c..3b687797e 100755 --- a/scripts/lint-golangci-lint.sh +++ b/scripts/lint-golangci-lint.sh @@ -4,11 +4,7 @@ # Pre-requisites: golangci-lint set -eo pipefail -SKIP_NON_GENERATED_FILES="${1}" -if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then - SKIP_NON_GENERATED_FILES=false -fi - +# Global flags ROOT_DIR=$(git rev-parse --show-toplevel) CORE_PATH="${ROOT_DIR}/core" SERVICES_PATH="${ROOT_DIR}/services" @@ -16,6 +12,15 @@ EXAMPLES_PATH="${ROOT_DIR}/examples" GOLANG_CI_YAML_PATH="${ROOT_DIR}/golang-ci.yaml" GOLANG_CI_ARGS="--allow-parallel-runners --timeout=5m --config=${GOLANG_CI_YAML_PATH}" +# Arguments +SKIP_NON_GENERATED_FILES="${1}" +SERVICE="${2}" + +# Default values +if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then + SKIP_NON_GENERATED_FILES=false +fi + if type -p golangci-lint >/dev/null; then : else @@ -23,28 +28,40 @@ else exit 1 fi -if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then - echo ">> Linting core" - cd ${CORE_PATH} - golangci-lint run ${GOLANG_CI_ARGS} -fi +lint_service() { + service=$1 -for service_dir in ${SERVICES_PATH}/*; do - service=$(basename ${service_dir}) echo ">> Linting service ${service}" - cd ${service_dir} + cd ${SERVICES_PATH}/${service} if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then golangci-lint run ${GOLANG_CI_ARGS} --skip-dirs wait # All manually maintained files are in subfolders else golangci-lint run ${GOLANG_CI_ARGS} fi -done +} -if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then - for example_dir in ${EXAMPLES_PATH}/*; do - example=$(basename ${example_dir}) - echo ">> Linting example ${example}" - cd ${example_dir} +# If a service is specified, only lint that service +if [ ! -z "${SERVICE}" ]; then + lint_service ${SERVICE} +# Otherwise, lint all modules and examples +else + if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then + echo ">> Linting core" + cd ${CORE_PATH} golangci-lint run ${GOLANG_CI_ARGS} + fi + + for service_dir in ${SERVICES_PATH}/*; do + service=$(basename ${service_dir}) + lint_service ${service} done + + if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then + for example_dir in ${EXAMPLES_PATH}/*; do + example=$(basename ${example_dir}) + echo ">> Linting example ${example}" + cd ${example_dir} + golangci-lint run ${GOLANG_CI_ARGS} + done + fi fi diff --git a/scripts/test-go.sh b/scripts/test-go.sh index 8dce3917a..d58e11947 100755 --- a/scripts/test-go.sh +++ b/scripts/test-go.sh @@ -4,7 +4,11 @@ # Pre-requisites: Go set -eo pipefail +# Arguments SKIP_NON_GENERATED_FILES="${1}" +SERVICE="${2}" + +# Default values if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then SKIP_NON_GENERATED_FILES=false fi @@ -21,27 +25,37 @@ else exit 1 fi -if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then - echo ">> Testing core" - cd ${CORE_PATH} - go test ./... ${GOTEST_ARGS} -fi - -for service_dir in ${SERVICES_PATH}/*; do - service=$(basename ${service_dir}) - - # Our unit test template fails because it doesn't support fields with validations, - # such as the UUID component used by IaaS. We introduce this hardcoded skip until we fix it - if [ "${service}" = "iaas" ] || [ "${service}" = "iaasalpha" ]; then - echo ">> Skipping services/${service}" - continue - fi +test_service() { + service=$1 echo ">> Testing services/${service}" - cd ${service_dir} if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then - go test ./ ${GOTEST_ARGS} # All manually maintained files are in subfolders + go test ${SERVICES_PATH}/${service}/... ${GOTEST_ARGS} # All manually maintained files are in subfolders else - go test ./... ${GOTEST_ARGS} + go test ${SERVICES_PATH}/${service}/... ${GOTEST_ARGS} + fi +} + +# If a service is specified, only test that service +if [ ! -z "${SERVICE}" ]; then + test_service ${SERVICE} +# Otherwise, test all services and core +else + if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then + echo ">> Testing core" + go test ${CORE_PATH}/... ${GOTEST_ARGS} fi -done + + for service_dir in ${SERVICES_PATH}/*; do + service=$(basename ${service_dir}) + + # Our unit test template fails because it doesn't support fields with validations, + # such as the UUID component used by IaaS. We introduce this hardcoded skip until we fix it + if [ "${service}" = "iaas" ] || [ "${service}" = "iaasalpha" ]; then + echo ">> Skipping services/${service}" + continue + fi + + test_service ${service} + done +fi