From 3c707002c2e7a782eedc1336b3a2fd2467f9bea9 Mon Sep 17 00:00:00 2001 From: Henrique Santos Date: Mon, 9 Oct 2023 14:48:44 +0100 Subject: [PATCH 01/10] Add flag to skip non generated flags --- Makefile | 5 +++-- scripts/lint-golangci-lint.sh | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 79164020..23bae369 100644 --- a/Makefile +++ b/Makefile @@ -11,13 +11,14 @@ project-tools: # LINT lint-golangci-lint: @echo "Linting with golangci-lint" - @$(SCRIPTS_BASE)/lint-golangci-lint.sh + @$(SCRIPTS_BASE)/lint-golangci-lint.sh ${skip-non-generated-files} sync-tidy: @echo "Syncing and tidying dependencies" @$(SCRIPTS_BASE)/sync-tidy.sh -lint: sync-tidy lint-golangci-lint +lint: sync-tidy + @$(MAKE) --no-print-directory lint-golangci-lint skip-non-generated-files=${skip-non-generated-files} # TEST test-go: diff --git a/scripts/lint-golangci-lint.sh b/scripts/lint-golangci-lint.sh index e39c4c23..2850a7f6 100755 --- a/scripts/lint-golangci-lint.sh +++ b/scripts/lint-golangci-lint.sh @@ -1,8 +1,11 @@ #!/bin/bash # This script lints the SDK modules and examples +# To skip manually maintained files, pass an extra "true" argument # Pre-requisites: golangci-lint set -eo pipefail +SKIP_NON_GENERATED_FILES="${1:-false}" + ROOT_DIR=$(git rev-parse --show-toplevel) CORE_PATH="${ROOT_DIR}/core" SERVICES_PATH="${ROOT_DIR}/services" @@ -25,9 +28,17 @@ for service_dir in ${SERVICES_PATH}/*; do service=$(basename ${service_dir}) echo ">> Linting service ${service}" cd ${service_dir} - golangci-lint run ${GOLANG_CI_ARGS} + if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then + golangci-lint run ${GOLANG_CI_ARGS} --skip-dirs wait + else + golangci-lint run ${GOLANG_CI_ARGS} + fi done +if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then + exit 0 +fi + for example_dir in ${EXAMPLES_PATH}/*; do example=$(basename ${example_dir}) echo ">> Linting example ${example}" From 6e858cf11468750127a3854d9c3ef787a669a617 Mon Sep 17 00:00:00 2001 From: Henrique Santos Date: Mon, 9 Oct 2023 14:58:24 +0100 Subject: [PATCH 02/10] Fix core not being skipped, rewrite logic --- scripts/lint-golangci-lint.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/lint-golangci-lint.sh b/scripts/lint-golangci-lint.sh index 2850a7f6..d824ad35 100755 --- a/scripts/lint-golangci-lint.sh +++ b/scripts/lint-golangci-lint.sh @@ -20,9 +20,11 @@ else exit 1 fi -echo ">> Linting core" -cd ${CORE_PATH} -golangci-lint run ${GOLANG_CI_ARGS} +if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; 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}) @@ -35,13 +37,11 @@ for service_dir in ${SERVICES_PATH}/*; do fi done -if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then - exit 0 +if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; 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 - -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 From 740de650c79ca3c97128879f13a02aa65292cce7 Mon Sep 17 00:00:00 2001 From: Henrique Santos Date: Mon, 9 Oct 2023 15:24:06 +0100 Subject: [PATCH 03/10] Add flag to skip non generated flags --- Makefile | 5 +++-- scripts/test-go.sh | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 23bae369..4798552f 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ lint: sync-tidy # TEST test-go: @echo "Running Go tests" - @$(SCRIPTS_BASE)/test-go.sh + @$(SCRIPTS_BASE)/test-go.sh ${skip-non-generated-files} -test: test-go +test: + @$(MAKE) --no-print-directory test-go skip-non-generated-files=${skip-non-generated-files} diff --git a/scripts/test-go.sh b/scripts/test-go.sh index e058cbc3..6cb9856f 100755 --- a/scripts/test-go.sh +++ b/scripts/test-go.sh @@ -1,8 +1,12 @@ #!/bin/bash # This script tests the SDK modules +# To skip manually maintained files, pass an extra "true" argument # Pre-requisites: Go set -eo pipefail +SKIP_NON_GENERATED_FILES="${1:-false}" +echo "${SKIP_NON_GENERATED_FILES}" + ROOT_DIR=$(git rev-parse --show-toplevel) GOTEST_ARGS="-timeout=5m -cover -count=1" CORE_PATH="${ROOT_DIR}/core" @@ -15,13 +19,19 @@ else exit 1 fi -echo ">> Testing core" -cd ${CORE_PATH} -go test ./... ${GOTEST_ARGS} +if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then + echo ">> Testing core" + cd ${CORE_PATH} + go test ./... ${GOTEST_ARGS} +fi for service_dir in ${SERVICES_PATH}/*; do service=$(basename ${service_dir}) echo ">> Testing services/${service}" cd ${service_dir} - go test ./... ${GOTEST_ARGS} + if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then + go test ./ ${GOTEST_ARGS} + else + go test ./... ${GOTEST_ARGS} + fi done From 0905b1bc1485762f92175751ad23448f182f489c Mon Sep 17 00:00:00 2001 From: Henrique Santos Date: Mon, 9 Oct 2023 15:31:11 +0100 Subject: [PATCH 04/10] Add new options --- CONTRIBUTION.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md index f33e751e..9910b542 100644 --- a/CONTRIBUTION.md +++ b/CONTRIBUTION.md @@ -21,8 +21,8 @@ Check the [Getting Started](README.md#getting-started) and [Authentication](READ These commands can be executed from the project root: - `make project-tools`: get the required dependencies -- `make lint`: lint the code and the examples and sync dependencies -- `make test`: run unit tests +- `make lint`: lint the code and the examples and sync dependencies. To only lint automatically generated files, run with `skip-non-generated-files=true` +- `make test`: run unit tests. To only lint automatically generated files, run with `skip-non-generated-files=true` ## Code Contributions From cf557796c3f2bffe532bf35d254cd4f0fa3099ee Mon Sep 17 00:00:00 2001 From: Henrique Santos Date: Mon, 9 Oct 2023 15:33:35 +0100 Subject: [PATCH 05/10] Fix typo --- CONTRIBUTION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md index 9910b542..5536517d 100644 --- a/CONTRIBUTION.md +++ b/CONTRIBUTION.md @@ -22,7 +22,7 @@ These commands can be executed from the project root: - `make project-tools`: get the required dependencies - `make lint`: lint the code and the examples and sync dependencies. To only lint automatically generated files, run with `skip-non-generated-files=true` -- `make test`: run unit tests. To only lint automatically generated files, run with `skip-non-generated-files=true` +- `make test`: run unit tests. To only test automatically generated files, run with `skip-non-generated-files=true` ## Code Contributions From 7662e107f1e9f5c404cce104cc08687bac562555 Mon Sep 17 00:00:00 2001 From: Henrique Santos Date: Mon, 9 Oct 2023 16:45:13 +0100 Subject: [PATCH 06/10] Remove test echo --- scripts/test-go.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/test-go.sh b/scripts/test-go.sh index 6cb9856f..074756e6 100755 --- a/scripts/test-go.sh +++ b/scripts/test-go.sh @@ -5,8 +5,6 @@ set -eo pipefail SKIP_NON_GENERATED_FILES="${1:-false}" -echo "${SKIP_NON_GENERATED_FILES}" - ROOT_DIR=$(git rev-parse --show-toplevel) GOTEST_ARGS="-timeout=5m -cover -count=1" CORE_PATH="${ROOT_DIR}/core" From 40c5ba5d3826bf50e7351bb4b3bd87adb35eb5ca Mon Sep 17 00:00:00 2001 From: Henrique Santos Date: Mon, 9 Oct 2023 16:57:40 +0100 Subject: [PATCH 07/10] Cleanup input arg --- scripts/lint-golangci-lint.sh | 9 ++++++--- scripts/test-go.sh | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/lint-golangci-lint.sh b/scripts/lint-golangci-lint.sh index d824ad35..15fcde07 100755 --- a/scripts/lint-golangci-lint.sh +++ b/scripts/lint-golangci-lint.sh @@ -4,7 +4,10 @@ # Pre-requisites: golangci-lint set -eo pipefail -SKIP_NON_GENERATED_FILES="${1:-false}" +SKIP_NON_GENERATED_FILES="${1}" +if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then + SKIP_NON_GENERATED_FILES=false +fi ROOT_DIR=$(git rev-parse --show-toplevel) CORE_PATH="${ROOT_DIR}/core" @@ -20,7 +23,7 @@ else exit 1 fi -if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then +if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then echo ">> Linting core" cd ${CORE_PATH} golangci-lint run ${GOLANG_CI_ARGS} @@ -37,7 +40,7 @@ for service_dir in ${SERVICES_PATH}/*; do fi done -if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then +if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then for example_dir in ${EXAMPLES_PATH}/*; do example=$(basename ${example_dir}) echo ">> Linting example ${example}" diff --git a/scripts/test-go.sh b/scripts/test-go.sh index 074756e6..f0b9369f 100755 --- a/scripts/test-go.sh +++ b/scripts/test-go.sh @@ -4,7 +4,11 @@ # Pre-requisites: Go set -eo pipefail -SKIP_NON_GENERATED_FILES="${1:-false}" +SKIP_NON_GENERATED_FILES="${1}" +if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then + SKIP_NON_GENERATED_FILES=false +fi + ROOT_DIR=$(git rev-parse --show-toplevel) GOTEST_ARGS="-timeout=5m -cover -count=1" CORE_PATH="${ROOT_DIR}/core" @@ -17,7 +21,7 @@ else exit 1 fi -if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then +if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then echo ">> Testing core" cd ${CORE_PATH} go test ./... ${GOTEST_ARGS} From dec57050ba93c4c54b11495d568f5ea03b60cfcf Mon Sep 17 00:00:00 2001 From: Henrique Santos Date: Mon, 9 Oct 2023 16:58:28 +0100 Subject: [PATCH 08/10] Add comment --- scripts/test-go.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test-go.sh b/scripts/test-go.sh index f0b9369f..869dcdba 100755 --- a/scripts/test-go.sh +++ b/scripts/test-go.sh @@ -32,7 +32,7 @@ for service_dir in ${SERVICES_PATH}/*; do echo ">> Testing services/${service}" cd ${service_dir} if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then - go test ./ ${GOTEST_ARGS} + go test ./ ${GOTEST_ARGS} # All manually maintained files are in subfolders else go test ./... ${GOTEST_ARGS} fi From dd885ab560251fff0b8c796f57da560664098726 Mon Sep 17 00:00:00 2001 From: Henrique Santos Date: Mon, 9 Oct 2023 16:59:15 +0100 Subject: [PATCH 09/10] Clarify command usage --- CONTRIBUTION.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md index 5536517d..ddfb223f 100644 --- a/CONTRIBUTION.md +++ b/CONTRIBUTION.md @@ -21,8 +21,8 @@ Check the [Getting Started](README.md#getting-started) and [Authentication](READ These commands can be executed from the project root: - `make project-tools`: get the required dependencies -- `make lint`: lint the code and the examples and sync dependencies. To only lint automatically generated files, run with `skip-non-generated-files=true` -- `make test`: run unit tests. To only test automatically generated files, run with `skip-non-generated-files=true` +- `make lint`: lint the code and the examples and sync dependencies. To only lint automatically generated files, run `make lint skip-non-generated-files=true` +- `make test`: run unit tests. To only test automatically generated files, run `make lint skip-non-generated-files=true` ## Code Contributions From c07c0b81235cbec0d4b2d6aa810615382184eb98 Mon Sep 17 00:00:00 2001 From: Henrique Santos Date: Mon, 9 Oct 2023 16:59:40 +0100 Subject: [PATCH 10/10] Add comment --- scripts/lint-golangci-lint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lint-golangci-lint.sh b/scripts/lint-golangci-lint.sh index 15fcde07..28cdd476 100755 --- a/scripts/lint-golangci-lint.sh +++ b/scripts/lint-golangci-lint.sh @@ -34,7 +34,7 @@ for service_dir in ${SERVICES_PATH}/*; do echo ">> Linting service ${service}" cd ${service_dir} if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then - golangci-lint run ${GOLANG_CI_ARGS} --skip-dirs wait + golangci-lint run ${GOLANG_CI_ARGS} --skip-dirs wait # All manually maintained files are in subfolders else golangci-lint run ${GOLANG_CI_ARGS} fi