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

make the makefile slightly more elegant #86

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- run: make build
- run: make mox

# Need to run tests with a temp dir on same file system for os.Rename to succeed.
- run: 'mkdir -p tmp && TMPDIR=$PWD/tmp make test'
Expand Down
147 changes: 88 additions & 59 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,77 +1,102 @@
default: build
GO ?= $(shell which go || echo go)
DOCKER ?= $(shell which docker || echo docker)
DOCKER_COMPOSE ?= $(shell docker compose &> /dev/null && echo "$(which docker)" compose || echo docker-compose)

build:
# build early to catch syntax errors
CGO_ENABLED=0 go build
CGO_ENABLED=0 go vet ./...
CGO_ENABLED=0 go vet -tags integration
gosrc = $(shell find * -type f -name '*.go')
gomod = go.mod go.sum
GOFLAGS = -trimpath

mox: $(gosrc) $(gomod) config/doc.go webmail/api.ts webadmin webaccount webmail
CGO_ENABLED=0 go build $(GOFLAGS) -o $@

webmail/api.ts: webmail/api.json $(gomod)
$(GO) run github.com/mjl-/sherpats/cmd/sherpats -bytes-to-string -slices-nullable -maps-nullable -nullable-optional -namespace api api <$< >$@

.mox.tmp: main.go
CGO_ENABLED=0 go build $(GOFLAGS) -o $@
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to get rid of this abomination, but with gendoc.sh creating a circular dependency with the mox target, this has to stay as long as gendoc.sh is a thing.


config/doc.go: ./gendoc.sh
$(MAKE) .mox.tmp
./gendoc.sh
(cd webadmin && CGO_ENABLED=0 go run ../vendor/github.com/mjl-/sherpadoc/cmd/sherpadoc/*.go -adjust-function-names none Admin) >webadmin/adminapi.json
(cd webaccount && CGO_ENABLED=0 go run ../vendor/github.com/mjl-/sherpadoc/cmd/sherpadoc/*.go -adjust-function-names none Account) >webaccount/accountapi.json
(cd webmail && CGO_ENABLED=0 go run ../vendor/github.com/mjl-/sherpadoc/cmd/sherpadoc/*.go -adjust-function-names none Webmail) >webmail/api.json
go run vendor/github.com/mjl-/sherpats/cmd/sherpats/main.go -bytes-to-string -slices-nullable -maps-nullable -nullable-optional -namespace api api <webmail/api.json >webmail/api.ts
# build again, api json files above are embedded
CGO_ENABLED=0 go build
rm .mox.tmp

webadmin/adminapi.json: $(wildcard webadmin/*.go) $(gomod)
cd webadmin && CGO_ENABLED=0 $(GO) run github.com/mjl-/sherpadoc/cmd/sherpadoc -adjust-function-names none Admin >$(notdir $@)

webaccount/accountapi.json: $(wildcard webaccount/*.go) $(gomod)
cd webaccount && CGO_ENABLED=0 $(GO) run github.com/mjl-/sherpadoc/cmd/sherpadoc -adjust-function-names none Account >$(notdir $@)

webmail/api.json: $(wildcard webmail/*.go) $(gomod)
cd webmail && CGO_ENABLED=0 $(GO) run github.com/mjl-/sherpadoc/cmd/sherpadoc -adjust-function-names none Webmail >$(notdir $@)

.PHONY: lint
lint:
CGO_ENABLED=0 $(GO) vet ./...
CGO_ENABLED=0 $(GO) vet -tags integration
staticcheck ./...
staticcheck -tags integration
GOARCH=386 CGO_ENABLED=0 $(GO) vet ./...

.PHONY: test
test:
CGO_ENABLED=0 go test -shuffle=on -coverprofile cover.out ./...
go tool cover -html=cover.out -o cover.html
CGO_ENABLED=0 $(GO) test -shuffle=on -coverprofile cover.out ./...
$(GO) tool cover -html=cover.out -o cover.html

.PHONY: test-race
test-race:
CGO_ENABLED=1 go test -race -shuffle=on -covermode atomic -coverprofile cover.out ./...
go tool cover -html=cover.out -o cover.html
CGO_ENABLED=1 $(GO) test -race -shuffle=on -covermode atomic -coverprofile cover.out ./...
$(GO) tool cover -html=cover.out -o cover.html

# note: if testdata/upgradetest.mbox.gz exists, its messages will be imported
# during tests. helpful for performance/resource consumption tests.
.PHONY: test-upgrade
test-upgrade:
nice ./test-upgrade.sh

check:
staticcheck ./...
staticcheck -tags integration
GOARCH=386 CGO_ENABLED=0 go vet ./...

# having "err" shadowed is common, best to not have others
.PHONY: check-shadow
check-shadow:
go vet -vettool=$$(which shadow) ./... 2>&1 | grep -v '"err"'
$(GO) vet -vettool=$$(which shadow) ./... 2>&1 | grep -v '"err"'

.PHONY: fuzz
fuzz:
go test -fuzz FuzzParseSignature -fuzztime 5m ./dkim
go test -fuzz FuzzParseRecord -fuzztime 5m ./dkim
go test -fuzz . -fuzztime 5m ./dmarc
go test -fuzz . -fuzztime 5m ./dmarcrpt
go test -fuzz . -parallel 1 -fuzztime 5m ./imapserver
go test -fuzz . -parallel 1 -fuzztime 5m ./junk
go test -fuzz FuzzParseRecord -fuzztime 5m ./mtasts
go test -fuzz FuzzParsePolicy -fuzztime 5m ./mtasts
go test -fuzz . -parallel 1 -fuzztime 5m ./smtpserver
go test -fuzz . -fuzztime 5m ./spf
go test -fuzz FuzzParseRecord -fuzztime 5m ./tlsrpt
go test -fuzz FuzzParseMessage -fuzztime 5m ./tlsrpt


$(GO) test -fuzz FuzzParseSignature -fuzztime 5m ./dkim
$(GO) test -fuzz FuzzParseRecord -fuzztime 5m ./dkim
$(GO) test -fuzz . -fuzztime 5m ./dmarc
$(GO) test -fuzz . -fuzztime 5m ./dmarcrpt
$(GO) test -fuzz . -parallel 1 -fuzztime 5m ./imapserver
$(GO) test -fuzz . -parallel 1 -fuzztime 5m ./junk
$(GO) test -fuzz FuzzParseRecord -fuzztime 5m ./mtasts
$(GO) test -fuzz FuzzParsePolicy -fuzztime 5m ./mtasts
$(GO) test -fuzz . -parallel 1 -fuzztime 5m ./smtpserver
$(GO) test -fuzz . -fuzztime 5m ./spf
$(GO) test -fuzz FuzzParseRecord -fuzztime 5m ./tlsrpt
$(GO) test -fuzz FuzzParseMessage -fuzztime 5m ./tlsrpt

.PHONY: test-integration
test-integration:
docker image build --pull --no-cache -f Dockerfile -t mox_integration_moxmail .
docker image build --pull --no-cache -f testdata/integration/Dockerfile.test -t mox_integration_test testdata/integration
$(DOCKER) image build --pull --no-cache -f Dockerfile -t mox_integration_moxmail .
$(DOCKER) image build --pull --no-cache -f testdata/integration/Dockerfile.test -t mox_integration_test testdata/integration
-rm -rf testdata/integration/moxacmepebble/data
-rm -rf testdata/integration/moxmail2/data
-rm -f testdata/integration/tmp-pebble-ca.pem
MOX_UID=$$(id -u) docker-compose -f docker-compose-integration.yml run test
docker-compose -f docker-compose-integration.yml down --timeout 1

MOX_UID=$$(id -u) $(DOCKER_COMPOSE) -f docker-compose-integration.yml run test
$(DOCKER_COMPOSE) -f docker-compose-integration.yml down --timeout 1

.PHONY: imaptest-build
imaptest-build:
-docker-compose -f docker-compose-imaptest.yml build --no-cache --pull mox
-$(DOCKER_COMPOSE) -f docker-compose-imaptest.yml build --no-cache --pull mox

.PHONY: imaptest-run
imaptest-run:
-rm -r testdata/imaptest/data
mkdir testdata/imaptest/data
docker-compose -f docker-compose-imaptest.yml run --entrypoint /usr/local/bin/imaptest imaptest host=mox port=1143 [email protected] pass=testtest mbox=imaptest.mbox
docker-compose -f docker-compose-imaptest.yml down
$(DOCKER_COMPOSE) -f docker-compose-imaptest.yml run --entrypoint /usr/local/bin/imaptest imaptest host=mox port=1143 [email protected] pass=testtest mbox=imaptest.mbox
$(DOCKER_COMPOSE) -f docker-compose-imaptest.yml down


fmt:
go fmt ./...
$(GO) fmt ./...
gofmt -w -s *.go */*.go

jswatch:
Expand Down Expand Up @@ -100,26 +125,30 @@ webadmin/admin.htmlx:
webaccount/account.htmlx:
./node_modules/.bin/jshint --extract always webaccount/account.html | ./fixjshintlines.sh

.PHONY: frontend
frontend: webadmin/admin.htmlx webaccount/account.htmlx webmail/webmail.js webmail/msg.js webmail/text.js

.PHONY: docker
docker:
docker build -t mox:dev .
$(DOCKER) build -t mox:dev .

.PHONY: docker-release
docker-release:
./docker-release.sh

.PHONY: buildall
buildall:
GOOS=linux GOARCH=arm go build
GOOS=linux GOARCH=arm64 go build
GOOS=linux GOARCH=amd64 go build
GOOS=linux GOARCH=386 go build
GOOS=openbsd GOARCH=amd64 go build
GOOS=freebsd GOARCH=amd64 go build
GOOS=netbsd GOARCH=amd64 go build
GOOS=darwin GOARCH=amd64 go build
GOOS=dragonfly GOARCH=amd64 go build
GOOS=illumos GOARCH=amd64 go build
GOOS=solaris GOARCH=amd64 go build
GOOS=aix GOARCH=ppc64 go build
GOOS=windows GOARCH=amd64 go build
GOOS=linux GOARCH=arm $(GO) $(GOFLAGS) build
GOOS=linux GOARCH=arm64 $(GO) $(GOFLAGS) build
GOOS=linux GOARCH=amd64 $(GO) $(GOFLAGS) build
GOOS=linux GOARCH=386 $(GO) $(GOFLAGS) build
GOOS=openbsd GOARCH=amd64 $(GO) $(GOFLAGS) build
GOOS=freebsd GOARCH=amd64 $(GO) $(GOFLAGS) build
GOOS=netbsd GOARCH=amd64 $(GO) $(GOFLAGS) build
GOOS=darwin GOARCH=amd64 $(GO) $(GOFLAGS) build
GOOS=dragonfly GOARCH=amd64 $(GO) $(GOFLAGS) build
GOOS=illumos GOARCH=amd64 $(GO) $(GOFLAGS) build
GOOS=solaris GOARCH=amd64 $(GO) $(GOFLAGS) build
GOOS=aix GOARCH=ppc64 $(GO) $(GOFLAGS) build
GOOS=windows GOARCH=amd64 $(GO) $(GOFLAGS) build
# no plan9 for now
Loading