Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
55 changes: 36 additions & 19 deletions scripts/lint-golangci-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,64 @@
# 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"
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
echo "golangci-lint not installed, unable to proceed."
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
52 changes: 33 additions & 19 deletions scripts/test-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Loading