Skip to content

Commit

Permalink
Add option to lint and test automatically generated files only (#108)
Browse files Browse the repository at this point in the history
* Add flag to skip non generated flags

* Fix core not being skipped, rewrite logic

* Add flag to skip non generated flags

* Add new options

* Fix typo

* Remove test echo

* Cleanup input arg

* Add comment

* Clarify command usage

* Add comment

---------

Co-authored-by: Henrique Santos <[email protected]>
  • Loading branch information
hcsa73 and Henrique Santos authored Oct 9, 2023
1 parent 8215c41 commit 8cd6884
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
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}

# 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

0 comments on commit 8cd6884

Please sign in to comment.