Skip to content

Commit 240be3b

Browse files
authored
CLOUDP-206784: Check licenses from CI (mongodb#1464)
Signed-off-by: jose.vazquez <[email protected]>
1 parent b18ad3e commit 240be3b

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

.github/workflows/go.yml

+3
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ jobs:
3030

3131
- name: Test mongotester
3232
run: go test -v ./test/e2e/util/mongotester/...
33+
34+
- name: Check licenses
35+
run: make check-licenses

Makefile

+18-6
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,37 @@ vet: ## Run go vet against code
4646
generate: controller-gen ## Generate code
4747
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
4848

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

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

57-
.PHONY: check-licenses
58-
check-licenses: licenses.csv ## Check licenses
59+
# We only check that go.mod is NOT newer than licenses.csv because the CI
60+
# tends to generate slightly different results, so content comparison wouldn't work
61+
licenses-tracked: ## Checks license.csv is up to date
62+
@if [ go.mod -nt licenses.csv ]; then \
63+
echo "License.csv is stale! Please run 'make licenses.csv' and commit"; exit 1; \
64+
else echo "License.csv OK (up to date)"; fi
65+
66+
.PHONY: check-licenses-compliance
67+
check-licenses-compliance: licenses.csv ## Check licenses are compliant with our restrictions
5968
@echo "Checking licenses not to be: $(DISALLOWED_LICENSES)"
6069
@echo "============================================"
6170
GOOS=linux GOARCH=amd64 $(GO_LICENSES) check --include_tests $(BASE_GO_PACKAGE)/... \
6271
--disallowed_types $(DISALLOWED_LICENSES)
6372
@echo "--------------------"
6473
@echo "Licenses check: PASS"
6574

75+
.PHONY: check-licenses
76+
check-licenses: licenses-tracked check-licenses-compliance ## Check license tracking & compliance
77+
6678
TEST ?= ./pkg/... ./api/... ./cmd/... ./controllers/... ./test/e2e/util/mongotester/...
67-
test: generate fmt vet manifests check-licenses ## Run unit tests
79+
test: generate fmt vet manifests ## Run unit tests
6880
go test $(options) $(TEST) -coverprofile cover.out
6981

7082
manager: generate fmt vet ## Build operator binary

0 commit comments

Comments
 (0)