Skip to content

Commit

Permalink
layered makefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
muir committed Jan 16, 2024
1 parent 0d81bd3 commit fb5e750
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 55 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: '1.18'
- name: Checkout peers
run: make ci_checkout_peers CLONE_DEPTH=2
- name: Run coverage
run: make calculate_coverage

Expand Down
58 changes: 3 additions & 55 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@

GOHOME ?= ${HOME}
GOPATH ?= ${GOHOME}
GOBIN ?= ${GOPATH}/bin

ZZZGO = $(wildcard ../xop*-go/*.zzzgo ../xop*-go/*/*.zzzgo ../xop*-go/*/*/*.zzzgo)
ZZZGENERATED = $(patsubst %.zzzgo, %.go, $(ZZZGO))
PB = xopproto/ingest.pb.go xopproto/ingest_grpc.pb.go
TOOLS = ${GOBIN}/gofumpt ${GOBIN}/goimports ${GOBIN}/enumer
TEST_ONLY ?=

ME = xop-go
RELATED = xopresty-go xopotel-go

all: $(ZZZGENERATED) $(PB) .gitattributes
go generate ./...
go build ./...
for i in $(RELATED); do (echo $$i ...; cd ../$$i && go generate ./... && go build ./...); done

include Makefile.common

ci_checkout_peers:;
branch="$${GITHUB_REF##*/}"; for i in $(RELATED); do (cd ..; git clone https://github.com/xoplog/$$i --depth 1 -b $$branch || git clone https://github.com/xoplog/$$i --depth 1); done

.gitattributes: $(ZZZGENERATED)
echo '*.zzzgo linguist-language=Go' > $@
echo 'doc.go linguist-documentation' >> $@
echo '*.md linguist-documentation' >> $@
echo '*.pb.go linguist-generated' >> $@
for i in $(ZZZGENERATED); do echo "$$i linguist-generated" >> $@; done
branch="$${GITHUB_REF##*/}"; for i in $(RELATED); do (cd ..; git clone https://github.com/xoplog/$$i --depth $(CLONE_DEPTH) -b $$branch || git clone https://github.com/xoplog/$$i --depth $(CLONE_DEPTH)); done

test: $(ZZZGENERATED) testadjuster
go generate ./...
Expand All @@ -49,23 +29,6 @@ citest:
XOPLEVEL_xoptestutil=warn XOPLEVEL_foo=debug go test -tags xoptesting ./xoptest/xoptestutil -run TestAdjuster -count 1
XOPLEVEL_xoptestutil=debug XOPLEVEL_foo=warn go test -tags xoptesting ./xoptest/xoptestutil -run TestAdjuster -count 1

${GOBIN}/gofumpt:;
go install mvdan.cc/gofumpt@latest

${GOBIN}/goimports:;
go install golang.org/x/tools/cmd/goimports@latest

${GOBIN}/enumer:;
go install github.com/dmarkham/enumer@latest

%.go : %.zzzgo tools/xopzzz/xopzzz.go $(TOOLS) Makefile
go run tools/xopzzz/xopzzz.go < $< > $@.tmp
-chmod +w $@
gofumpt -w $@.tmp
goimports -w $@.tmp
-mv $@.tmp $@
-chmod -w $@

calculate_coverage:
echo "mode: atomic" > coverage.txt
for d in $$(go list ./...); do \
Expand All @@ -84,21 +47,6 @@ calculate_coverage:
egrep -v 'xoptestutil/|xopoteltest/' > coverage.txt.tmp
mv coverage.txt.tmp coverage.txt

coverage: calculate_coverage
go tool cover -html=coverage.txt

golanglint:
# binary will be $(go env GOPATH)/bin/golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.52.2
golangci-lint --version

lint:;
golangci-lint run

misspell:;
go install github.com/client9/misspell/cmd/misspell@latest
misspell -w `find . -name \*.md`

OTEL_TAG="v1.12.0"

../opentelemetry-specification:
Expand Down
55 changes: 55 additions & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

GOHOME ?= ${HOME}
GOPATH ?= ${GOHOME}
GOBIN ?= ${GOPATH}/bin

ZZZGO = $(wildcard ../xop*-go/*.zzzgo ../xop*-go/*/*.zzzgo ../xop*-go/*/*/*.zzzgo)
ZZZGENERATED = $(patsubst %.zzzgo, %.go, $(ZZZGO))
PB = xopproto/ingest.pb.go xopproto/ingest_grpc.pb.go
TOOLS = ${GOBIN}/gofumpt ${GOBIN}/goimports ${GOBIN}/enumer
TEST_ONLY ?=
CLONE_DEPTH ?= 1

all: $(ZZZGENERATED) $(PB) .gitattributes
go generate ./...
go build ./...
for i in $(RELATED); do (echo $$i ...; cd ../$$i && go generate ./... && go build ./...); done

.gitattributes: $(ZZZGENERATED)
echo '*.zzzgo linguist-language=Go' > $@
echo 'doc.go linguist-documentation' >> $@
echo '*.md linguist-documentation' >> $@
echo '*.pb.go linguist-generated' >> $@
for i in $(ZZZGENERATED); do echo "$$i linguist-generated" >> $@; done

${GOBIN}/gofumpt:;
go install mvdan.cc/gofumpt@latest

${GOBIN}/goimports:;
go install golang.org/x/tools/cmd/goimports@latest

${GOBIN}/enumer:;
go install github.com/dmarkham/enumer@latest

%.go : %.zzzgo tools/xopzzz/xopzzz.go $(TOOLS) Makefile
go run tools/xopzzz/xopzzz.go < $< > $@.tmp
-chmod +w $@
gofumpt -w $@.tmp
goimports -w $@.tmp
-mv $@.tmp $@
-chmod -w $@

coverage: calculate_coverage
go tool cover -html=coverage.txt

golanglint:
# binary will be $(go env GOPATH)/bin/golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.52.2
golangci-lint --version

lint:;
golangci-lint run

misspell:;
go install github.com/client9/misspell/cmd/misspell@latest
misspell -w `find . -name \*.md`
25 changes: 25 additions & 0 deletions Makefile.peer
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

include Makefile.common

test: $(ZZZGENERATED) testadjuster
go generate ./...
go test -tags xoptesting ./... -failfast $(TEST_ONLY)
go test -tags xoptesting -race ./... -failfast $(TEST_ONLY)

citest:
go test ./... -failfast
go test -race ./... -failfast

calculate_coverage:
echo "mode: atomic" > coverage.txt
for d in $$(go list ./...); do \
go test -race -covermode=atomic -coverprofile=profile.out -coverpkg=github.com/xoplog/$(ME)/... $$d; \
if [ -f profile.out ]; then \
grep -v ^mode profile.out >> coverage.txt; \
rm profile.out; \
fi; \
done
grep -v '\.pb.go:' coverage.txt | \
egrep -v 'xoptestutil/|xopoteltest/' > coverage.txt.tmp
mv coverage.txt.tmp coverage.txt

0 comments on commit fb5e750

Please sign in to comment.