Skip to content

Commit bf4898b

Browse files
authored
Allow lint and test specific service (#1034)
* feat: Allow lint and test specific service * feat: Improve based on review comments * feat: Improve echos in Makefile
1 parent 9c5ba30 commit bf4898b

File tree

3 files changed

+78
-47
lines changed

3 files changed

+78
-47
lines changed

Makefile

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@ project-tools:
1212

1313
# LINT
1414
lint-golangci-lint:
15-
@echo "Linting with golangci-lint"
16-
@$(SCRIPTS_BASE)/lint-golangci-lint.sh ${skip-non-generated-files}
15+
@echo ">> Linting with golangci-lint"
16+
@$(SCRIPTS_BASE)/lint-golangci-lint.sh "${skip-non-generated-files}" "${service}"
1717

1818
lint-scripts:
19-
@echo "Linting scripts"
19+
@echo ">> Linting scripts"
2020
@cd ${ROOT_DIR}/scripts && golangci-lint run ${GOLANG_CI_ARGS}
2121

2222
sync-tidy:
23-
@echo "Syncing and tidying dependencies"
23+
@echo ">> Syncing and tidying dependencies"
2424
@$(SCRIPTS_BASE)/sync-tidy.sh
2525

2626
lint: sync-tidy
27-
@$(MAKE) --no-print-directory lint-golangci-lint skip-non-generated-files=${skip-non-generated-files}
27+
@$(MAKE) --no-print-directory lint-golangci-lint skip-non-generated-files=${skip-non-generated-files} service=${service}
2828

2929
# TEST
3030
test-go:
31-
@echo "Running Go tests"
32-
@$(SCRIPTS_BASE)/test-go.sh ${skip-non-generated-files}
31+
@echo ">> Running Go tests"
32+
@$(SCRIPTS_BASE)/test-go.sh "${skip-non-generated-files}" "${service}"
3333

3434
test-scripts:
35-
@echo "Running Go tests for scripts"
35+
@echo ">> Running Go tests for scripts"
3636
@go test $(ROOT_DIR)/scripts/... ${GOTEST_ARGS}
3737

3838
test:
39-
@$(MAKE) --no-print-directory test-go skip-non-generated-files=${skip-non-generated-files}
39+
@$(MAKE) --no-print-directory test-go skip-non-generated-files=${skip-non-generated-files} service=${service}
4040

4141
# AUTOMATIC TAG
4242
sdk-tag-services:

scripts/lint-golangci-lint.sh

+36-19
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,64 @@
44
# Pre-requisites: golangci-lint
55
set -eo pipefail
66

7-
SKIP_NON_GENERATED_FILES="${1}"
8-
if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then
9-
SKIP_NON_GENERATED_FILES=false
10-
fi
11-
7+
# Global flags
128
ROOT_DIR=$(git rev-parse --show-toplevel)
139
CORE_PATH="${ROOT_DIR}/core"
1410
SERVICES_PATH="${ROOT_DIR}/services"
1511
EXAMPLES_PATH="${ROOT_DIR}/examples"
1612
GOLANG_CI_YAML_PATH="${ROOT_DIR}/golang-ci.yaml"
1713
GOLANG_CI_ARGS="--allow-parallel-runners --timeout=5m --config=${GOLANG_CI_YAML_PATH}"
1814

15+
# Arguments
16+
SKIP_NON_GENERATED_FILES="${1}"
17+
SERVICE="${2}"
18+
19+
# Default values
20+
if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then
21+
SKIP_NON_GENERATED_FILES=false
22+
fi
23+
1924
if type -p golangci-lint >/dev/null; then
2025
:
2126
else
2227
echo "golangci-lint not installed, unable to proceed."
2328
exit 1
2429
fi
2530

26-
if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then
27-
echo ">> Linting core"
28-
cd ${CORE_PATH}
29-
golangci-lint run ${GOLANG_CI_ARGS}
30-
fi
31+
lint_service() {
32+
service=$1
3133

32-
for service_dir in ${SERVICES_PATH}/*; do
33-
service=$(basename ${service_dir})
3434
echo ">> Linting service ${service}"
35-
cd ${service_dir}
35+
cd ${SERVICES_PATH}/${service}
3636
if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then
3737
golangci-lint run ${GOLANG_CI_ARGS} --skip-dirs wait # All manually maintained files are in subfolders
3838
else
3939
golangci-lint run ${GOLANG_CI_ARGS}
4040
fi
41-
done
41+
}
4242

43-
if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then
44-
for example_dir in ${EXAMPLES_PATH}/*; do
45-
example=$(basename ${example_dir})
46-
echo ">> Linting example ${example}"
47-
cd ${example_dir}
43+
# If a service is specified, only lint that service
44+
if [ ! -z "${SERVICE}" ]; then
45+
lint_service ${SERVICE}
46+
# Otherwise, lint all modules and examples
47+
else
48+
if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then
49+
echo ">> Linting core"
50+
cd ${CORE_PATH}
4851
golangci-lint run ${GOLANG_CI_ARGS}
52+
fi
53+
54+
for service_dir in ${SERVICES_PATH}/*; do
55+
service=$(basename ${service_dir})
56+
lint_service ${service}
4957
done
58+
59+
if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then
60+
for example_dir in ${EXAMPLES_PATH}/*; do
61+
example=$(basename ${example_dir})
62+
echo ">> Linting example ${example}"
63+
cd ${example_dir}
64+
golangci-lint run ${GOLANG_CI_ARGS}
65+
done
66+
fi
5067
fi

scripts/test-go.sh

+33-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
# Pre-requisites: Go
55
set -eo pipefail
66

7+
# Arguments
78
SKIP_NON_GENERATED_FILES="${1}"
9+
SERVICE="${2}"
10+
11+
# Default values
812
if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then
913
SKIP_NON_GENERATED_FILES=false
1014
fi
@@ -21,27 +25,37 @@ else
2125
exit 1
2226
fi
2327

24-
if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then
25-
echo ">> Testing core"
26-
cd ${CORE_PATH}
27-
go test ./... ${GOTEST_ARGS}
28-
fi
29-
30-
for service_dir in ${SERVICES_PATH}/*; do
31-
service=$(basename ${service_dir})
32-
33-
# Our unit test template fails because it doesn't support fields with validations,
34-
# such as the UUID component used by IaaS. We introduce this hardcoded skip until we fix it
35-
if [ "${service}" = "iaas" ] || [ "${service}" = "iaasalpha" ]; then
36-
echo ">> Skipping services/${service}"
37-
continue
38-
fi
28+
test_service() {
29+
service=$1
3930

4031
echo ">> Testing services/${service}"
41-
cd ${service_dir}
4232
if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then
43-
go test ./ ${GOTEST_ARGS} # All manually maintained files are in subfolders
33+
go test ${SERVICES_PATH}/${service}/... ${GOTEST_ARGS} # All manually maintained files are in subfolders
4434
else
45-
go test ./... ${GOTEST_ARGS}
35+
go test ${SERVICES_PATH}/${service}/... ${GOTEST_ARGS}
36+
fi
37+
}
38+
39+
# If a service is specified, only test that service
40+
if [ ! -z "${SERVICE}" ]; then
41+
test_service ${SERVICE}
42+
# Otherwise, test all services and core
43+
else
44+
if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then
45+
echo ">> Testing core"
46+
go test ${CORE_PATH}/... ${GOTEST_ARGS}
4647
fi
47-
done
48+
49+
for service_dir in ${SERVICES_PATH}/*; do
50+
service=$(basename ${service_dir})
51+
52+
# Our unit test template fails because it doesn't support fields with validations,
53+
# such as the UUID component used by IaaS. We introduce this hardcoded skip until we fix it
54+
if [ "${service}" = "iaas" ] || [ "${service}" = "iaasalpha" ]; then
55+
echo ">> Skipping services/${service}"
56+
continue
57+
fi
58+
59+
test_service ${service}
60+
done
61+
fi

0 commit comments

Comments
 (0)