Skip to content

Commit

Permalink
build(env): added dev build tag (Checkmarx#4729)
Browse files Browse the repository at this point in the history
Signed-off-by: João Reigota <[email protected]>
  • Loading branch information
joaoReigota1 authored Jan 21, 2022
1 parent db927f9 commit a143128
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 3 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ jobs:
uses: actions/[email protected]
with:
persist-credentials: false
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
src:
- 'pkg/terraformer/**'
- name: Get cache paths
id: go-cache-paths
run: |
Expand All @@ -76,15 +82,25 @@ jobs:
maximum-size: 32GB
disk-root: "C:"
- name: Test and Generate Report
if: matrix.os != 'windows-latest'
if: matrix.os != 'windows-latest' && steps.changes.outputs.src == 'true'
run: |
go test -mod=vendor -v $(go list ./... | grep -v e2e) -count=1 -coverprofile=cover.out | tee unit-test.log
result_code=${PIPESTATUS[0]}
exit $result_code
- name: Test and Generate Report Dev
if: matrix.os != 'windows-latest' && steps.changes.outputs.src == 'false'
run: |
go test -tags dev -mod=vendor -v $(go list -tags dev ./... | grep -v e2e) -count=1 -coverprofile=cover.out | tee unit-test.log
result_code=${PIPESTATUS[0]}
exit $result_code
- name: Test and Generate Report Windows
if: matrix.os == 'windows-latest'
if: matrix.os == 'windows-latest' && steps.changes.outputs.src == 'true'
run: |
go test -mod=vendor -v $(go list ./... | grep -v e2e) -count=1 -coverprofile=cover.out | tee unit-test.log
- name: Test and Generate Report Windows Dev
if: matrix.os == 'windows-latest' && steps.changes.outputs.src == 'false'
run: |
go test -mod=vendor -tags dev -v $(go list -tags dev ./... | grep -v e2e) -count=1 -coverprofile=cover.out | tee unit-test.log
- name: Archive test logs
if: always()
uses: actions/upload-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up Node v14
uses: actions/setup-node@v2
with:
node-version: '14'
node-version: "14"
- name: Check out code
uses: actions/[email protected]
with:
Expand Down
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ build: generate
@go build -o ${TARGET_BIN} -ldflags "-X ${CONSTANTS_PATH}.SCMCommit=${COMMIT} -X ${CONSTANTS_PATH}.Version=${VERSION} -X ${CONSTANTS_PATH}.BaseURL=${DESCRIPTIONS_URL}" \
cmd/console/main.go

.PHONY: build-dev
build-dev: ## go build dev
build-dev: generate
$(call print-target)
@go build -o ${TARGET_BIN} -tags dev -ldflags "-X ${CONSTANTS_PATH}.SCMCommit=${COMMIT} -X ${CONSTANTS_PATH}.Version=${VERSION} -X ${CONSTANTS_PATH}.BaseURL=${DESCRIPTIONS_URL}" \
cmd/console/main.go

.PHONY: go-clean
go-clean: ## Go clean build, test and modules caches
$(call print-target)
Expand All @@ -81,11 +88,28 @@ test-short: generate
$(call print-target)
@go test -short ./...

.PHONY: test
test-short-dev: # Run sanity unit tests
test-short-dev: generate
$(call print-target)
@go test -tags dev -short ./...

.PHONY: test
test: ## Run all tests
test: test-cover test-e2e
$(call print-target)

.PHONY: test
test-dev: ## Run all tests
test-dev: test-cover test-e2e
$(call print-target)

.PHONY: test-race-dev
test-race-dev: ## Run tests with race detector
test-race-dev: generate
$(call print-target)
@go test -tags dev -race $(shell go list ./... | grep -v e2e)

.PHONY: test-race
test-race: ## Run tests with race detector
test-race: generate
Expand All @@ -98,12 +122,24 @@ test-unit: generate
$(call print-target)
@go test $(shell go list ./... | grep -v e2e)

.PHONY: test-unit-dev
test-unit-dev: ## Run unit tests
test-unit-dev: generate
$(call print-target)
@go test -tags dev $(shell go list ./... | grep -v e2e)

.PHONY: test-cover
test-cover: ## Run tests with code coverage
test-cover: generate
$(call print-target)
@go test -covermode=atomic -v -coverprofile=coverage.out $(shell go list ./... | grep -v e2e)

.PHONY: test-cover-dev
test-cover-dev: ## Run tests with code coverage
test-cover-dev: generate
$(call print-target)
@go test -tags dev -covermode=atomic -v -coverprofile=coverage.out $(shell go list ./... | grep -v e2e)

.PHONY: test-coverage-report
test-coverage-report: ## Run unit tests and generate test coverage report
test-coverage-report: test-cover
Expand All @@ -117,6 +153,12 @@ test-e2e: build
$(call print-target)
E2E_KICS_BINARY=$(PWD)/bin/kics go test "github.com/Checkmarx/kics/e2e" -v -timeout 1500s

.PHONY: test-e2e-dev
test-e2e-dev: ## Run E2E tests
test-e2e-dev: build
$(call print-target)
E2E_KICS_BINARY=$(PWD)/bin/kics go test -tags dev "github.com/Checkmarx/kics/e2e" -v -timeout 1500s

.PHONY: cover
cover: ## generate coverage report
cover: test
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ The nightly release will have a "nightly" prefix with the last commit hash code.
KICS is a true community project. It's built as an open source from day one, and anyone can find his own way to contribute to the project.
[Check out how](docs/CONTRIBUTING.md), within just minutes, you can start making a difference, by sharing your expertise with a community of thousands of security experts and software developers.

**Note:** For development not related to terraformer please use the Golang build tag `dev` in commands `go run, go build and go test`

Examples:

- `go test -tags dev ./...`
- `go run -tags dev cmd/console/main.go`
- `go build -tags dev cmd/console/main.go`


## Meet us at conferences
- [AWS re:Invent 2021: AWS On Air](https://youtu.be/9ZKldJeBHl4) ([video](https://youtu.be/9ZKldJeBHl4))
- [OWASP Bristol & Suffolk Chapter - Meetup](https://www.meetup.com/OWASP-Bristol/events/281869377/) ([video](https://youtu.be/KKZJEJF6I0M))
Expand Down
3 changes: 3 additions & 0 deletions pkg/terraformer/aws/aws_cloud_provider.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !dev
// +build !dev

package aws

import (
Expand Down
3 changes: 3 additions & 0 deletions pkg/terraformer/aws/aws_cloud_provider_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !dev
// +build !dev

package aws

import (
Expand Down
3 changes: 3 additions & 0 deletions pkg/terraformer/terraformer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !dev
// +build !dev

package terraformer

import (
Expand Down
17 changes: 17 additions & 0 deletions pkg/terraformer/terraformer_alt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build dev
// +build dev

package terraformer

/*
Since terraformer import is very big, this creates problems for the dev env
regarding CPU and MEM usage.
To fix this issue an alternative terraformer file is used which disables terraformer,
and mocks the import function.
To use this alternative terraformer file, be sure to run kics with the tag "dev".
*/

// Import is a mock function that does nothing
func Import(terraformerPath, destinationPath string) (string, error) {
return "", nil
}
3 changes: 3 additions & 0 deletions pkg/terraformer/terraformer_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !dev
// +build !dev

package terraformer

import (
Expand Down

0 comments on commit a143128

Please sign in to comment.