2021-02-13 00:54:06 +03:00
|
|
|
SHELL := /bin/bash
|
2021-05-17 22:20:28 +03:00
|
|
|
GOPATH := $(go env GOPATH)
|
|
|
|
GINKGO := ginkgo
|
2021-08-12 23:46:06 +03:00
|
|
|
GIT_HASH := $(shell git rev-parse HEAD)
|
2021-05-17 22:20:28 +03:00
|
|
|
GOLANGGCI_LINT := golangci-lint
|
|
|
|
PROTOC_GEN_GO := protoc-gen-go
|
2021-05-15 23:58:01 +03:00
|
|
|
PROTOC := $(shell which protoc)
|
2021-02-24 22:46:41 +03:00
|
|
|
IMAGE_NAME = scorecard
|
2021-02-25 22:51:57 +03:00
|
|
|
OUTPUT = output
|
2021-07-13 04:29:23 +03:00
|
|
|
IGNORED_CI_TEST="E2E TEST:blob|E2E TEST:executable"
|
2021-05-15 23:58:01 +03:00
|
|
|
|
2021-08-09 21:22:30 +03:00
|
|
|
VERSION_LDFLAGS=$(shell ./scripts/version-ldflags)
|
2021-07-27 20:37:27 +03:00
|
|
|
|
2021-05-15 23:58:01 +03:00
|
|
|
############################### make help #####################################
|
2021-02-22 02:35:39 +03:00
|
|
|
.PHONY: help
|
|
|
|
help: ## Display this help
|
|
|
|
@awk \
|
|
|
|
-v "col=${COLOR}" -v "nocol=${NOCOLOR}" \
|
|
|
|
' \
|
|
|
|
BEGIN { \
|
|
|
|
FS = ":.*##" ; \
|
|
|
|
printf "Available targets:\n"; \
|
|
|
|
} \
|
|
|
|
/^[a-zA-Z0-9_-]+:.*?##/ { \
|
|
|
|
printf " %s%-25s%s %s\n", col, $$1, nocol, $$2 \
|
|
|
|
} \
|
|
|
|
/^##@/ { \
|
|
|
|
printf "\n%s%s%s\n", col, substr($$0, 5), nocol \
|
|
|
|
} \
|
|
|
|
' $(MAKEFILE_LIST)
|
2021-05-15 23:58:01 +03:00
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
################################ make install #################################
|
|
|
|
.PHONY: install
|
|
|
|
install: ## Installs all dependencies needed to compile Scorecard
|
2021-06-09 02:55:43 +03:00
|
|
|
install: | $(PROTOC)
|
2021-09-06 20:34:17 +03:00
|
|
|
@echo Installing tools from tools/tools.go
|
|
|
|
cd tools; cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install %
|
2020-12-23 00:43:24 +03:00
|
|
|
|
2021-05-15 23:58:01 +03:00
|
|
|
$(PROTOC):
|
|
|
|
ifeq (,$(PROTOC))
|
|
|
|
$(error download and install protobuf compiler package - https://developers.google.com/protocol-buffers/docs/downloads)
|
|
|
|
endif
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
################################## make all ###################################
|
2021-02-22 02:35:39 +03:00
|
|
|
all: ## Runs build, test and verify
|
2021-06-10 23:24:33 +03:00
|
|
|
all-targets = update-dependencies build check-linter unit-test add-projects validate-projects tree-status
|
2021-05-15 23:58:01 +03:00
|
|
|
.PHONY: all $(all-targets)
|
|
|
|
all: $(all-targets)
|
|
|
|
|
|
|
|
update-dependencies: ## Update go dependencies for all modules
|
|
|
|
# Update root go modules
|
|
|
|
go mod tidy && go mod verify
|
2021-09-06 20:34:17 +03:00
|
|
|
cd tools
|
|
|
|
go mod tidy && go mod verify
|
2021-05-15 23:58:01 +03:00
|
|
|
|
2021-05-17 22:20:28 +03:00
|
|
|
$(GOLANGGCI_LINT): install
|
2021-05-15 23:58:01 +03:00
|
|
|
check-linter: ## Install and run golang linter
|
2021-05-17 22:20:28 +03:00
|
|
|
check-linter: $(GOLANGGCI_LINT)
|
2021-05-15 23:58:01 +03:00
|
|
|
# Run golangci-lint linter
|
2021-05-20 04:45:23 +03:00
|
|
|
golangci-lint run -c .golangci.yml
|
2021-05-15 23:58:01 +03:00
|
|
|
|
2021-06-10 23:24:33 +03:00
|
|
|
add-projects: ## Adds new projects to ./cron/data/projects.csv
|
|
|
|
add-projects: ./cron/data/projects.csv | build-add-script
|
|
|
|
# Add new projects to ./cron/data/projects.csv
|
2021-07-19 03:33:45 +03:00
|
|
|
./cron/data/add/add ./cron/data/projects.csv ./cron/data/projects.new.csv
|
2021-06-19 02:00:08 +03:00
|
|
|
mv ./cron/data/projects.new.csv ./cron/data/projects.csv
|
2021-06-10 23:24:33 +03:00
|
|
|
|
2021-06-03 00:27:09 +03:00
|
|
|
validate-projects: ## Validates ./cron/data/projects.csv
|
2021-06-10 23:24:33 +03:00
|
|
|
validate-projects: ./cron/data/projects.csv | build-validate-script
|
2021-06-03 00:27:09 +03:00
|
|
|
# Validate ./cron/data/projects.csv
|
2021-07-19 03:33:45 +03:00
|
|
|
./cron/data/validate/validate ./cron/data/projects.csv
|
2021-02-22 02:35:39 +03:00
|
|
|
|
2021-05-15 23:58:01 +03:00
|
|
|
tree-status: ## Verify tree is clean and all changes are committed
|
|
|
|
# Verify the tree is clean and all changes are commited
|
|
|
|
./scripts/tree-status
|
2021-05-17 22:20:28 +03:00
|
|
|
|
|
|
|
|
2021-05-15 23:58:01 +03:00
|
|
|
###############################################################################
|
|
|
|
|
2021-06-10 23:24:33 +03:00
|
|
|
################################## make build #################################
|
2021-08-25 16:31:04 +03:00
|
|
|
build-targets = generate-docs build-proto build-scorecard build-pubsub build-bq-transfer \
|
2021-06-10 23:24:33 +03:00
|
|
|
build-add-script build-validate-script build-update-script dockerbuild
|
2021-05-15 23:58:01 +03:00
|
|
|
.PHONY: build $(build-targets)
|
2021-09-04 18:39:10 +03:00
|
|
|
build: ## Build all binaries and images in the repo.
|
2021-05-15 23:58:01 +03:00
|
|
|
build: $(build-targets)
|
|
|
|
|
|
|
|
build-proto: ## Compiles and generates all required protobufs
|
2021-08-31 02:14:42 +03:00
|
|
|
build-proto: cron/data/request.pb.go cron/data/metadata.pb.go clients/branch.pb.go
|
2021-05-17 22:20:28 +03:00
|
|
|
cron/data/request.pb.go: cron/data/request.proto | $(PROTOC)
|
2021-05-15 23:58:01 +03:00
|
|
|
protoc --go_out=../../../ cron/data/request.proto
|
2021-08-06 21:07:42 +03:00
|
|
|
cron/data/metadata.pb.go: cron/data/metadata.proto | $(PROTOC)
|
|
|
|
protoc --go_out=../../../ cron/data/metadata.proto
|
2021-08-31 02:14:42 +03:00
|
|
|
clients/branch.pb.go: clients/branch.proto | $(PROTOC)
|
|
|
|
protoc --go_out=../../../ clients/branch.proto
|
2021-05-15 23:58:01 +03:00
|
|
|
|
|
|
|
generate-docs: ## Generates docs
|
2021-07-29 23:29:12 +03:00
|
|
|
generate-docs: docs/checks.md
|
2021-09-10 01:09:39 +03:00
|
|
|
docs/checks.md: docs/checks/internal/checks.yaml docs/checks/internal/*.go docs/checks/internal/generate/*.go
|
2021-07-29 23:29:12 +03:00
|
|
|
# Validating checks.yaml
|
2021-09-10 01:09:39 +03:00
|
|
|
go run ./docs/checks/internal/validate/main.go
|
2021-05-15 23:58:01 +03:00
|
|
|
# Generating checks.md
|
2021-09-10 18:26:27 +03:00
|
|
|
go run ./docs/checks/internal/generate/main.go docs/checks.md
|
2021-05-15 23:58:01 +03:00
|
|
|
|
|
|
|
build-scorecard: ## Runs go build on repo
|
|
|
|
# Run go build and generate scorecard executable
|
2021-07-27 20:37:27 +03:00
|
|
|
CGO_ENABLED=0 go build -a -tags netgo -ldflags '-w -extldflags "-static" $(VERSION_LDFLAGS)'
|
2020-12-23 00:43:24 +03:00
|
|
|
|
2021-05-19 01:18:08 +03:00
|
|
|
build-pubsub: ## Runs go build on the PubSub cron job
|
|
|
|
# Run go build and the PubSub cron job
|
|
|
|
cd cron/controller && CGO_ENABLED=0 go build -a -ldflags '-w -extldflags "static"' -o controller
|
2021-09-14 18:00:32 +03:00
|
|
|
cd cron/worker && CGO_ENABLED=0 go build -a -ldflags '-w -extldflags "-static" $(VERSION_LDFLAGS)' -o worker
|
2021-05-19 01:18:08 +03:00
|
|
|
|
2021-06-15 02:25:32 +03:00
|
|
|
build-bq-transfer: ## Runs go build on the BQ transfer cron job
|
|
|
|
build-bq-transfer: ./cron/bq/*.go
|
|
|
|
# Run go build on the Copier cron job
|
|
|
|
cd cron/bq && CGO_ENABLED=0 go build -a -ldflags '-w -extldflags "static"' -o data-transfer
|
|
|
|
|
2021-08-11 04:45:01 +03:00
|
|
|
build-webhook: ## Runs go build on the cron webhook
|
|
|
|
# Run go build on the cron webhook
|
|
|
|
cd cron/webhook && CGO_ENABLED=0 go build -a -ldflags '-w -extldflags "static"' -o webhook
|
|
|
|
|
2021-06-10 23:24:33 +03:00
|
|
|
build-add-script: ## Runs go build on the add script
|
|
|
|
build-add-script: cron/data/add/add
|
2021-09-02 22:31:55 +03:00
|
|
|
cron/data/add/add: cron/data/add/*.go cron/data/*.go repos/*.go cron/data/projects.csv
|
2021-06-10 23:24:33 +03:00
|
|
|
# Run go build on the add script
|
|
|
|
cd cron/data/add && CGO_ENABLED=0 go build -a -ldflags '-w -extldflags "-static"' -o add
|
|
|
|
|
2021-06-09 02:55:43 +03:00
|
|
|
build-validate-script: ## Runs go build on the validate script
|
|
|
|
build-validate-script: cron/data/validate/validate
|
2021-06-19 02:00:08 +03:00
|
|
|
cron/data/validate/validate: cron/data/validate/*.go cron/data/*.go cron/data/projects.csv
|
2021-06-09 02:55:43 +03:00
|
|
|
# Run go build on the validate script
|
|
|
|
cd cron/data/validate && CGO_ENABLED=0 go build -a -ldflags '-w -extldflags "-static"' -o validate
|
|
|
|
|
|
|
|
build-update-script: ## Runs go build on the update script
|
|
|
|
build-update-script: cron/data/update/projects-update
|
|
|
|
cron/data/update/projects-update: cron/data/update/*.go cron/data/*.go
|
|
|
|
# Run go build on the update script
|
|
|
|
cd cron/data/update && CGO_ENABLED=0 go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o projects-update
|
2020-12-23 00:43:24 +03:00
|
|
|
|
2021-05-15 23:58:01 +03:00
|
|
|
dockerbuild: ## Runs docker build
|
|
|
|
# Build all Docker images in the Repo
|
|
|
|
$(call ndef, GITHUB_AUTH_TOKEN)
|
|
|
|
DOCKER_BUILDKIT=1 docker build . --file Dockerfile --tag $(IMAGE_NAME)
|
2021-08-06 21:07:42 +03:00
|
|
|
DOCKER_BUILDKIT=1 docker build . --file cron/controller/Dockerfile \
|
|
|
|
--build-arg=COMMIT_SHA=$(GIT_HASH) --tag $(IMAGE_NAME)-batch-controller
|
|
|
|
DOCKER_BUILDKIT=1 docker build . --file cron/worker/Dockerfile --tag $(IMAGE_NAME)-batch-worker
|
2021-06-15 02:25:32 +03:00
|
|
|
DOCKER_BUILDKIT=1 docker build . --file cron/bq/Dockerfile --tag $(IMAGE_NAME)-bq-transfer
|
2021-08-11 04:45:01 +03:00
|
|
|
DOCKER_BUILDKIT=1 docker build . --file cron/webhook/Dockerfile --tag ${IMAGE_NAME}-webhook
|
2021-05-15 23:58:01 +03:00
|
|
|
###############################################################################
|
2020-12-23 00:43:24 +03:00
|
|
|
|
2021-05-15 23:58:01 +03:00
|
|
|
################################# make test ###################################
|
2021-07-13 04:29:23 +03:00
|
|
|
test-targets = unit-test e2e ci-e2e
|
2021-05-15 23:58:01 +03:00
|
|
|
.PHONY: test $(test-targets)
|
|
|
|
test: $(test-targets)
|
2020-12-23 00:43:24 +03:00
|
|
|
|
2021-05-15 23:58:01 +03:00
|
|
|
unit-test: ## Runs unit test without e2e
|
|
|
|
# Run unit tests, ignoring e2e tests
|
2021-08-27 17:17:14 +03:00
|
|
|
go test -race -covermode atomic `go list ./... | grep -v e2e`
|
2021-02-13 00:54:06 +03:00
|
|
|
|
2021-05-15 23:58:01 +03:00
|
|
|
e2e: ## Runs e2e tests. Requires GITHUB_AUTH_TOKEN env var to be set to GitHub personal access token
|
|
|
|
e2e: build-scorecard check-env | $(GINKGO)
|
|
|
|
# Run e2e tests. GITHUB_AUTH_TOKEN with personal access token must be exported to run this
|
2021-08-27 17:17:14 +03:00
|
|
|
$(GINKGO) --race --skip="E2E TEST:executable" -p -v -cover ./...
|
2021-05-17 22:20:28 +03:00
|
|
|
|
|
|
|
$(GINKGO): install
|
|
|
|
|
2021-05-15 23:58:01 +03:00
|
|
|
ci-e2e: ## Runs CI e2e tests. Requires GITHUB_AUTH_TOKEN env var to be set to GitHub personal access token
|
2021-06-03 00:27:09 +03:00
|
|
|
ci-e2e: build-scorecard check-env | $(GINKGO)
|
2021-05-15 23:58:01 +03:00
|
|
|
# Run CI e2e tests. GITHUB_AUTH_TOKEN with personal access token must be exported to run this
|
2021-02-13 00:54:06 +03:00
|
|
|
$(call ndef, GITHUB_AUTH_TOKEN)
|
2021-02-26 21:00:05 +03:00
|
|
|
@echo Ignoring these test for ci-e2e $(IGNORED_CI_TEST)
|
2021-05-17 22:20:28 +03:00
|
|
|
$(GINKGO) -p -v -cover --skip=$(IGNORED_CI_TEST) ./e2e/...
|
2021-02-26 21:00:05 +03:00
|
|
|
|
|
|
|
|
2021-05-15 23:58:01 +03:00
|
|
|
check-env:
|
|
|
|
ifndef GITHUB_AUTH_TOKEN
|
|
|
|
$(error GITHUB_AUTH_TOKEN is undefined)
|
|
|
|
endif
|
|
|
|
###############################################################################
|