Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to lint and test automatically generated files only #108

Merged
merged 10 commits into from
Oct 9, 2023
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
4 changes: 2 additions & 2 deletions CONTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `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

Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ 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}
hcsa73 marked this conversation as resolved.
Show resolved Hide resolved

# 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}
34 changes: 24 additions & 10 deletions scripts/lint-golangci-lint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#!/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}"
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"
SERVICES_PATH="${ROOT_DIR}/services"
Expand All @@ -17,20 +23,28 @@ else
exit 1
fi

echo ">> Linting core"
cd ${CORE_PATH}
golangci-lint run ${GOLANG_CI_ARGS}
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})
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 # All manually maintained files are in subfolders
else
golangci-lint run ${GOLANG_CI_ARGS}
fi
done

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
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
20 changes: 16 additions & 4 deletions scripts/test-go.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#!/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}"
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"
Expand All @@ -15,13 +21,19 @@ else
exit 1
fi

echo ">> Testing core"
cd ${CORE_PATH}
go test ./... ${GOTEST_ARGS}
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})
echo ">> Testing services/${service}"
cd ${service_dir}
go test ./... ${GOTEST_ARGS}
if [ "${SKIP_NON_GENERATED_FILES}" = true ]; then
go test ./ ${GOTEST_ARGS} # All manually maintained files are in subfolders
else
go test ./... ${GOTEST_ARGS}
fi
done
Loading