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

CLOUDP-206784: Check licenses from CI #1464

Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ jobs:

- name: Test mongotester
run: go test -v ./test/e2e/util/mongotester/...

- name: Check licenses
run: make check-licenses
24 changes: 18 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,37 @@ vet: ## Run go vet against code
generate: controller-gen ## Generate code
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

$(GO-LICENSES):
go install github.com/google/go-licenses@latest
$(GO_LICENSES):
@if ! which $@ &> /dev/null; then \
go install github.com/google/go-licenses@latest; \
fi

licenses.csv: go.mod ## Track licenses in a CSV file
licenses.csv: go.mod $(GO_LICENSES) ## Track licenses in a CSV file
@echo "Tracking licenses into file $@"
@echo "========================================"
GOOS=linux GOARCH=amd64 $(GO_LICENSES) csv --include_tests $(BASE_GO_PACKAGE)/... > $@

.PHONY: check-licenses
check-licenses: licenses.csv ## Check licenses
# We only check that go.mod is NOT newer than licenses.csv because the CI
# tends to generate slightly different results, so content comparison wouldn't work
licenses-tracked: ## Checks license.csv is up to date
@if [ go.mod -nt licenses.csv ]; then \
echo "License.csv is stale! Please run 'make licenses.csv' and commit"; exit 1; \
else echo "License.csv OK (up to date)"; fi

.PHONY: check-licenses-compliance
check-licenses-compliance: licenses.csv ## Check licenses are compliant with our restrictions
@echo "Checking licenses not to be: $(DISALLOWED_LICENSES)"
@echo "============================================"
GOOS=linux GOARCH=amd64 $(GO_LICENSES) check --include_tests $(BASE_GO_PACKAGE)/... \
--disallowed_types $(DISALLOWED_LICENSES)
@echo "--------------------"
@echo "Licenses check: PASS"

.PHONY: check-licenses
check-licenses: licenses-tracked check-licenses-compliance ## Check license tracking & compliance

TEST ?= ./pkg/... ./api/... ./cmd/... ./controllers/... ./test/e2e/util/mongotester/...
test: generate fmt vet manifests check-licenses ## Run unit tests
test: generate fmt vet manifests ## Run unit tests
go test $(options) $(TEST) -coverprofile cover.out

manager: generate fmt vet ## Build operator binary
Expand Down
Loading