Skip to content

Commit b159df5

Browse files
committed
feat: Allow lint and test specific service
1 parent 9c5ba30 commit b159df5

File tree

3 files changed

+80
-45
lines changed

3 files changed

+80
-45
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ project-tools:
1313
# LINT
1414
lint-golangci-lint:
1515
@echo "Linting with golangci-lint"
16-
@$(SCRIPTS_BASE)/lint-golangci-lint.sh ${skip-non-generated-files}
16+
@$(SCRIPTS_BASE)/lint-golangci-lint.sh "${skip-non-generated-files}" "${service}"
1717

1818
lint-scripts:
1919
@echo "Linting scripts"
@@ -24,19 +24,19 @@ sync-tidy:
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:
3131
@echo "Running Go tests"
32-
@$(SCRIPTS_BASE)/test-go.sh ${skip-non-generated-files}
32+
@$(SCRIPTS_BASE)/test-go.sh "${skip-non-generated-files}" "${service}"
3333

3434
test-scripts:
3535
@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

Lines changed: 39 additions & 22 deletions
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-
32-
for service_dir in ${SERVICES_PATH}/*; do
33-
service=$(basename ${service_dir})
34-
echo ">> Linting service ${service}"
35-
cd ${service_dir}
31+
# If a service is specified, only lint that service
32+
if [ ! -z "${SERVICE}" ]; then
33+
echo ">> Linting service ${SERVICE}"
34+
cd ${SERVICES_PATH}/${SERVICE}
3635
if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then
3736
golangci-lint run ${GOLANG_CI_ARGS} --skip-dirs wait # All manually maintained files are in subfolders
3837
else
3938
golangci-lint run ${GOLANG_CI_ARGS}
4039
fi
41-
done
42-
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}
40+
# Otherwise, lint all modules and examples
41+
else
42+
if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then
43+
echo ">> Linting core"
44+
cd ${CORE_PATH}
4845
golangci-lint run ${GOLANG_CI_ARGS}
46+
fi
47+
48+
for service_dir in ${SERVICES_PATH}/*; do
49+
service=$(basename ${service_dir})
50+
echo ">> Linting service ${service}"
51+
cd ${service_dir}
52+
if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then
53+
golangci-lint run ${GOLANG_CI_ARGS} --skip-dirs wait # All manually maintained files are in subfolders
54+
else
55+
golangci-lint run ${GOLANG_CI_ARGS}
56+
fi
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

Lines changed: 37 additions & 19 deletions
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,41 @@ 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
39-
40-
echo ">> Testing services/${service}"
41-
cd ${service_dir}
28+
# If a service is specified, only test that service
29+
if [ ! -z "${SERVICE}" ]; then
30+
echo ">> Testing services/${SERVICE}"
31+
cd ${SERVICES_PATH}/${SERVICE}
4232
if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then
4333
go test ./ ${GOTEST_ARGS} # All manually maintained files are in subfolders
4434
else
4535
go test ./... ${GOTEST_ARGS}
4636
fi
47-
done
37+
exit 0
38+
# Otherwise, test all modules
39+
else
40+
41+
if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then
42+
echo ">> Testing core"
43+
cd ${CORE_PATH}
44+
go test ./... ${GOTEST_ARGS}
45+
fi
46+
47+
for service_dir in ${SERVICES_PATH}/*; do
48+
service=$(basename ${service_dir})
49+
50+
# Our unit test template fails because it doesn't support fields with validations,
51+
# such as the UUID component used by IaaS. We introduce this hardcoded skip until we fix it
52+
if [ "${service}" = "iaas" ] || [ "${service}" = "iaasalpha" ]; then
53+
echo ">> Skipping services/${service}"
54+
continue
55+
fi
56+
57+
echo ">> Testing services/${service}"
58+
cd ${service_dir}
59+
if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then
60+
go test ./ ${GOTEST_ARGS} # All manually maintained files are in subfolders
61+
else
62+
go test ./... ${GOTEST_ARGS}
63+
fi
64+
done
65+
fi

0 commit comments

Comments
 (0)