Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

makefile add check/add license feature #47

Merged
merged 4 commits into from
Mar 5, 2021
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
6 changes: 2 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ jobs:
run: make install-tools
- name: Add Permissions to Tool Binaries
run: chmod -R +x ~/go/bin
- name: Vet
run: make vet
- name: Lint
run: make lint
- name: Check
run: make ci-check

test-linux:
runs-on: ubuntu-latest
Expand Down
35 changes: 32 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ GIT_SHA=$(shell git rev-parse --short HEAD)
PROJECT_ROOT = $(shell pwd)
ARTIFACTS = ${PROJECT_ROOT}/artifacts
ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort )
ALL_SRC := $(shell find . -name '*.go' -type f | sort)
ADDLICENCESE=addlicense


TOOLS_MOD_DIR := ./internal/tools
.PHONY: install-tools
install-tools:
go install github.com/golangci/golangci-lint/cmd/golangci-lint
go install github.com/vektra/mockery/cmd/mockery
cd $(TOOLS_MOD_DIR) && go install github.com/golangci/golangci-lint/cmd/golangci-lint
cd $(TOOLS_MOD_DIR) && go install github.com/vektra/mockery/cmd/mockery
cd $(TOOLS_MOD_DIR) && go install github.com/google/addlicense

.PHONY: test
test: vet test-only
Expand Down Expand Up @@ -54,8 +57,34 @@ vet:
generate:
go generate ./...

.PHONY: check-license
check-license:
@ADDLICENCESEOUT=`$(ADDLICENCESE) -check $(ALL_SRC) 2>&1`; \
if [ "$$ADDLICENCESEOUT" ]; then \
echo "$(ADDLICENCESE) FAILED => add License errors:\n"; \
echo "$$ADDLICENCESEOUT\n"; \
echo "Use 'make add-license' to fix this."; \
exit 1; \
else \
echo "Check License finished successfully"; \
fi

.PHONY: add-license
add-license:
@ADDLICENCESEOUT=`$(ADDLICENCESE) -y "" -c "The OpenTelemetry Authors" $(ALL_SRC) 2>&1`; \
if [ "$$ADDLICENCESEOUT" ]; then \
echo "$(ADDLICENCESE) FAILED => add License errors:\n"; \
echo "$$ADDLICENCESEOUT\n"; \
exit 1; \
else \
echo "Add License finished successfully"; \
fi

.PHONY: for-all
for-all:
@set -e; for dir in $(ALL_MODULES); do \
(cd "$${dir}" && $${CMD} ); \
done

.PHONY: ci-check
ci-check: vet lint check-license
15 changes: 15 additions & 0 deletions internal/tools/empty_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package tools
9 changes: 9 additions & 0 deletions internal/tools/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/open-telemetry/opentelemetry-log-collection/internal/tools

go 1.15

require (
github.com/golangci/golangci-lint v1.38.0 // indirect
github.com/google/addlicense v0.0.0-20200906110928-a0294312aa76 // indirect
github.com/vektra/mockery v1.1.2 // indirect
)
Loading