From f0173549156ed740eab34e465a9590da2379f577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Tue, 7 Apr 2020 15:50:35 +0100 Subject: [PATCH 1/2] fix(project): refactor and cleanup Makefile --- .dockerignore | 4 - .gitignore | 1 - .travis.yml | 14 ++-- Dockerfile | 7 +- Makefile | 191 ++++-------------------------------------- demo/Dockerfile | 7 +- make/cc.mk | 18 ++++ make/docker.mk | 11 +++ make/go.mk | 65 ++++++++++++++ make/lint-versions.mk | 22 +++++ make/vars.mk | 10 +++ ui/Makefile | 38 +++++++++ 12 files changed, 192 insertions(+), 196 deletions(-) create mode 100644 make/cc.mk create mode 100644 make/docker.mk create mode 100644 make/go.mk create mode 100644 make/lint-versions.mk create mode 100644 make/vars.mk create mode 100644 ui/Makefile diff --git a/.dockerignore b/.dockerignore index c8de8bade..9153eb3e0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,9 +1,5 @@ -.build -.coverage -bindata_assetfs.go karma ui/build ui/coverage ui/node_modules -vendor Dockerfile diff --git a/.gitignore b/.gitignore index f27d1de76..839a79f5e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -/.build /coverage.txt /cmd/karma/bindata_assetfs.go /karma diff --git a/.travis.yml b/.travis.yml index 461d297e4..21f487c41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,7 +49,7 @@ jobs: name: Test JavaScript code if: (repo = prymitive/karma AND type != pull_request) OR (fork = true AND type = pull_request) <<: *DEFAULTS_JS - script: make test-js + script: make -C ui test-js after_success: - travis_retry curl -s --connect-timeout 30 --fail https://codecov.io/bash | bash -s -- -F ui @@ -58,7 +58,7 @@ jobs: name: Test JavaScript code with Pacific/Easter time zone if: (repo = prymitive/karma AND type != pull_request) OR (fork = true AND type = pull_request) <<: *DEFAULTS_JS - script: env TZ=Pacific/Easter make test-js + script: env TZ=Pacific/Easter make -C ui test-js after_success: - travis_retry curl -s --connect-timeout 30 --fail https://codecov.io/bash | bash -s -- -F ui @@ -66,7 +66,7 @@ jobs: name: Lint git commit if: (repo = prymitive/karma AND type != pull_request) OR (fork = true AND type = pull_request) <<: *DEFAULTS_JS - script: make lint-git-ci + script: make -C ui lint-git-ci - stage: Lint name: Lint Go code @@ -100,21 +100,21 @@ jobs: name: Lint JavaScript code if: (repo = prymitive/karma AND type != pull_request) OR (fork = true AND type = pull_request) <<: *DEFAULTS_JS - script: make lint-js + script: make -C ui lint-js - stage: Lint name: Check JavaScript code formatting if: (repo = prymitive/karma AND type != pull_request) OR (fork = true AND type = pull_request) <<: *DEFAULTS_JS script: - - make format-js + - make -C ui format - git diff --exit-code - stage: Lint name: Lint documentation if: (repo = prymitive/karma AND type != pull_request) OR (fork = true AND type = pull_request) <<: *DEFAULTS_JS - script: make lint-docs + script: make -C ui lint-docs - stage: Lint name: Verify OpenAPI client code @@ -147,7 +147,7 @@ jobs: env: - NODE_ENV=test - secure: "DTDy4as3DV3QUw6LWNInEh2iFXrsMuMnb+WRNSwORu8OcgyLKVNrQ5SwQLV1lm0RFTCEN+sSxjOJwQp5PXEgLXcT/MP5xfg2p3HDEj7k7GqJLI4OykYpdh7YHGaX+cAGsrjPfuWAf7pdBlYplEDdGHGkK9BLkBIx6owkzvw0Z8Je3+kTxRAae8vIXpzmgiN+NGzP14UF92tky+/ZS2aLrhqVbTpWEP5j0mEhOpy6Ebh31nCTuW2FA+8oD0HVckC/JTLbIGPQgpzLrdEEE/imjZB9Gx4022lkcuZjf8u+hRytgqKp93l01MPxHrGCZ9V18r3QFZCAXGtFh8dg8xSAvk1cvFfJUDHkW1XhaUdsLubGI7zDw111N+5Do9L3MjJ2jd1x7ZPUSJwKUGPeRw/7CsNDPtC2Pcmkdb3D0SNeH4ia/L43A9+e3nuJ6vthAkEd7zBIcp9diVJ2nyry0d5YdFQStezksJgFADOO/OleMyMhLTdqBUE7sFf7QtD6R9nhZuIe//3UGVRuTJJmDU8wZEzK8CUyhPjbnpMTMbyq8bIYIk96E5Nrxp65RDOv9pPpvPfHf0WvALn/fmwa79AUafugYDoAXokv1RqrU0L977MRwEDDkGOuO1civoudfNQ2sAh6SR1eaSp9AygJgvpodLy1lEJZm3VxffjrSNdoejU=" - script: ./scripts/percy-skip-deps.sh || make test-percy + script: ./scripts/percy-skip-deps.sh || make -C ui test-percy - stage: Build and Deploy name: Cross compile binaries diff --git a/Dockerfile b/Dockerfile index 96c3f234e..1d37c2782 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,19 +3,18 @@ RUN mkdir -p /src/ui COPY ui/package.json ui/package-lock.json /src/ui/ RUN cd /src/ui && npm install RUN apk add make git -COPY Makefile /src/Makefile COPY ui /src/ui -RUN make -C /src ui +RUN make -C /src/ui build FROM golang:1.14.1-alpine3.11 as go-builder RUN apk add make git COPY Makefile /src/Makefile +COPY make /src/make COPY go.mod /src/go.mod COPY go.sum /src/go.sum -RUN make -C /src download-deps +RUN make -C /src download-deps-go RUN make -C /src install-deps-build-go COPY --from=nodejs-builder /src/ui /src/ui -COPY --from=nodejs-builder /src/.build /src/.build COPY cmd /src/cmd COPY internal /src/internal ARG VERSION diff --git a/Makefile b/Makefile index 6cca98f43..63adba194 100644 --- a/Makefile +++ b/Makefile @@ -1,185 +1,24 @@ -NAME := karma -VERSION ?= $(shell git describe --tags --always --dirty='-dev') +include make/vars.mk +include make/go.mk +include make/cc.mk +include make/docker.mk +include make/lint-versions.mk -# define a recursive wildcard function, we'll need it to find deeply nested -# sources in the ui directory -# based on http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html -rwildcard = $(foreach d, $(wildcard $1*), $(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) +.PHONY: lint +lint: lint-versions + make -f go.mk test + make -C ui lint-js + make -C ui lint-docs -SOURCES := $(call rwildcard, cmd internal, *) -ASSET_SOURCES := $(call rwildcard, ui/public ui/src, *) - -GO_BINDATA_MODE := prod -ifdef DEBUG - GO_BINDATA_MODE = debug -endif - -.DEFAULT_GOAL := $(NAME) - -.build/deps-build-go.ok: go.mod go.sum - @mkdir -p .build - GO111MODULE=on go install github.com/go-bindata/go-bindata/... - GO111MODULE=on go install github.com/elazarl/go-bindata-assetfs/... - touch $@ - -.build/deps-test-go.ok: go.mod go.sum - @mkdir -p .build - GO111MODULE=on go install github.com/hansboder/gocovmerge - touch $@ - -.build/deps-lint-go.ok: go.mod go.sum - @mkdir -p .build - GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint - touch $@ - -.build/deps-build-node.ok: ui/package.json ui/package-lock.json - @mkdir -p .build - cd ui && npm install - touch $@ - -.build/artifacts-bindata_assetfs.%: - @mkdir -p .build - rm -f .build/artifacts-bindata_assetfs.* - touch $@ - -.build/artifacts-ui.ok: .build/deps-build-node.ok $(ASSET_SOURCES) - @mkdir -p .build - cd ui && (npm run build || (test -n "$$CI" && rm -fr node_modules && npm install && npm run build)) - touch $@ - -cmd/karma/bindata_assetfs.go: .build/deps-build-go.ok .build/artifacts-bindata_assetfs.$(GO_BINDATA_MODE) .build/artifacts-ui.ok - go-bindata-assetfs -o cmd/karma/bindata_assetfs.go ui/build/... ui/src/... cmd/karma/tests/bindata/... - -$(NAME): .build/deps-build-go.ok go.mod cmd/karma/bindata_assetfs.go $(SOURCES) - GO111MODULE=on go build -ldflags "-X main.version=$(VERSION)" ./cmd/karma - -.PHONY: download-deps -download-deps: - GO111MODULE=on go mod download - -.PHONY: install-deps-build-go -install-deps-build-go: .build/deps-build-go.ok - -word-split = $(word $2,$(subst -, ,$1)) -cc-%: .build/deps-build-go.ok go.mod cmd/karma/bindata_assetfs.go $(SOURCES) - $(eval GOOS := $(call word-split,$*,1)) - $(eval GOARCH := $(call word-split,$*,2)) - $(eval GOARM := $(call word-split,$*,3)) - $(eval GOARMBIN := $(patsubst %,v%,$(GOARM))) - $(eval GOEXT := $(patsubst $(GOOS),,$(patsubst windows,.exe,$(GOOS)))) - $(eval BINARY := "karma-$(GOOS)-$(GOARCH)$(GOARMBIN)$(GOEXT)") - @awk -v bin=$(BINARY) -v goos=$(GOOS) -v goarch=$(GOARCH) -v goarm=$(GOARM) 'BEGIN { printf "[+] %-25s GOOS=%-10s GOARCH=%-10s GOARM=%1s\n", bin, goos, goarch, goarm }' - @env CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) go build -o $(BINARY) -ldflags="-X main.version=$(shell make show-version)" ./cmd/karma - @test -f $(BINARY) - @awk -v bin=$(BINARY) -v size=`du -h $(BINARY) | awk '{print $$1}'` -v type="`file -b $(BINARY)`" 'BEGIN { printf "[-] %-25s SIZE=%-10s TYPE=%s\n", bin, size, type }' - -PLATFORMS := cc-darwin-386 cc-darwin-amd64 cc-dragonfly-amd64 cc-freebsd-386 cc-freebsd-amd64 cc-freebsd-arm-5 cc-freebsd-arm-6 cc-freebsd-arm-7 cc-linux-386 cc-linux-amd64 cc-linux-arm-5 cc-linux-arm-6 cc-linux-arm-7 cc-linux-arm64 cc-linux-ppc64 cc-linux-ppc64le cc-linux-mips cc-linux-mipsle cc-linux-mips64 cc-linux-mips64le cc-linux-s390x cc-netbsd-386 cc-netbsd-amd64 cc-netbsd-arm-5 cc-netbsd-arm-6 cc-netbsd-arm-7 cc-openbsd-386 cc-openbsd-amd64 cc-openbsd-arm-5 cc-openbsd-arm-6 cc-openbsd-arm-7 cc-solaris-amd64 cc-windows-386 cc-windows-amd64 -crosscompile: $(PLATFORMS) - @echo +.PHONY: test +test: lint + make -f go.mk test-go + make -C ui test-js .PHONY: clean clean: - rm -fr .build cmd/karma/bindata_assetfs.go $(NAME) $(NAME)-* ui/build ui/node_modules coverage.txt - -.PHONY: docker-image -docker-image: - docker build --build-arg VERSION=$(VERSION) -t $(NAME):$(VERSION) . - -.PHONY: run-demo -run-demo: - docker build --build-arg VERSION=$(VERSION) -t $(NAME):demo -f demo/Dockerfile . - @docker rm -f $(NAME)-demo || true - docker run --rm --name $(NAME)-demo -p 8080:8080 -p 9093:9093 -p 9094:9094 $(NAME):demo - -.PHONY: lint-git-ci -lint-git-ci: .build/deps-build-node.ok - ui/node_modules/.bin/commitlint-travis - -.PHONY: lint-go -lint-go: .build/deps-lint-go.ok - GO111MODULE=on golangci-lint run -v - -.PHONY: lint-js -lint-js: .build/deps-build-node.ok - cd ui && ./node_modules/.bin/eslint --quiet src - -.PHONY: lint-docs -lint-docs: .build/deps-build-node.ok - $(CURDIR)/ui/node_modules/.bin/markdownlint *.md docs - -.PHONY: lint-golang-version -lint-golang-version: - $(eval CI_VERSION := $(shell grep -E '^(\ +)go:' .travis.yml | awk '{print $$2}' | tr -d "'\"" | sed -E s_'^([0-9]+\.[0-9]+)$$'_'\1.0'_g)) - $(eval BUILD_VERSION := $(shell grep -E '^FROM golang:' Dockerfile | cut -d : -f 2 | awk '{print $1}' | cut -d '-' -f 1)) - $(eval DEMO_VERSION := $(shell grep -E '^FROM golang:' demo/Dockerfile | cut -d : -f 2 | awk '{print $1}' | cut -d '-' -f 1)) - @if [ "$(CI_VERSION)" != "$(BUILD_VERSION)" ] || [ "$(CI_VERSION)" != "$(DEMO_VERSION)" ] || [ "$(BUILD_VERSION)" != "$(DEMO_VERSION)" ]; then \ - echo "Golang version mismatch: CI_VERSION=$(CI_VERSION) BUILD_VERSION=$(BUILD_VERSION) DEMO_VERSION=$(DEMO_VERSION)"; \ - exit 1; \ - fi - -.PHONY: lint-nodejs-version -lint-nodejs-version: - $(eval CI_VERSION := $(shell cat .nvmrc)) - $(eval BUILD_VERSION := $(shell grep -E '^FROM node:' Dockerfile | cut -d : -f 2 | awk '{print $1}' | cut -d '-' -f 1)) - $(eval DEMO_VERSION := $(shell grep -E '^FROM node:' demo/Dockerfile | cut -d : -f 2 | awk '{print $1}' | cut -d '-' -f 1)) - @if [ "$(CI_VERSION)" != "$(BUILD_VERSION)" ] || [ "$(CI_VERSION)" != "$(DEMO_VERSION)" ] || [ "$(BUILD_VERSION)" != "$(DEMO_VERSION)" ]; then \ - echo "Node version mismatch: CI_VERSION=$(CI_VERSION) BUILD_VERSION=$(BUILD_VERSION) DEMO_VERSION=$(DEMO_VERSION)"; \ - exit 1; \ - fi - -.PHONY: lint-versions -lint-versions: lint-golang-version lint-nodejs-version - -.PHONY: lint -lint: lint-go lint-js lint-docs lint-versions - -.PHONY: benchmark-go -benchmark-go: - GO111MODULE=on go test -run=NONE -bench=. -benchmem ./... - -.PHONY: test-go -test-go: .build/deps-test-go.ok - @rm -f profile.* - GO111MODULE=on ./scripts/test-unit.sh - GO111MODULE=on ./scripts/test-main.sh - GO111MODULE=on ./scripts/gocovmerge.sh - -.PHONY: test-js -test-js: .build/deps-build-node.ok - cd ui && CI=true npm test -- --coverage - -.PHONY: test-percy -test-percy: .build/deps-build-node.ok - cd ui && CI=true npm run snapshot - -.PHONY: test -test: lint test-go test-js - -.PHONY: format-go -format-go: .build/deps-build-go.ok - gofmt -l -s -w . - -.PHONY: format-js -format-js: .build/deps-build-node.ok - cd ui && ./node_modules/.bin/prettier --write 'src/**/*.js' 'src/**/*.tsx' - -.PHONY: openapi-client -openapi-client: - for f in $(wildcard internal/mapper/*/Dockerfile) ; do $(MAKE) -C `dirname "$$f"` ; done + rm -fr cmd/karma/bindata_assetfs.go $(NAME) $(NAME)-* ui/build ui/node_modules coverage.txt .PHONY: show-version show-version: @echo $(VERSION) - -# Creates mock bindata_assetfs.go with source assets -.PHONY: mock-assets -mock-assets: .build/deps-build-go.ok - rm -fr ui/build - mkdir ui/build - cp ui/public/* ui/build/ - go-bindata-assetfs -o cmd/karma/bindata_assetfs.go -nometadata ui/build/... cmd/karma/tests/bindata/... - # force assets rebuild on next make run - rm -f .build/bindata_assetfs.* - -.PHONY: ui -ui: .build/artifacts-ui.ok diff --git a/demo/Dockerfile b/demo/Dockerfile index 335b85643..889c488c9 100644 --- a/demo/Dockerfile +++ b/demo/Dockerfile @@ -3,19 +3,18 @@ RUN mkdir -p /src/ui COPY ui/package.json ui/package-lock.json /src/ui/ RUN cd /src/ui && npm install RUN apk add make git -COPY Makefile /src/Makefile COPY ui /src/ui -RUN make -C /src ui +RUN make -C /src/ui build FROM golang:1.14.1-alpine3.11 as go-builder RUN apk add make git COPY Makefile /src/Makefile +COPY make /src/make COPY go.mod /src/go.mod COPY go.sum /src/go.sum -RUN make -C /src download-deps +RUN make -C /src download-deps-go RUN make -C /src install-deps-build-go COPY --from=nodejs-builder /src/ui /src/ui -COPY --from=nodejs-builder /src/.build /src/.build COPY cmd /src/cmd COPY internal /src/internal ARG VERSION diff --git a/make/cc.mk b/make/cc.mk new file mode 100644 index 000000000..5d5988482 --- /dev/null +++ b/make/cc.mk @@ -0,0 +1,18 @@ +include make/vars.mk + +word-split = $(word $2,$(subst -, ,$1)) +cc-%: go.mod go.sum cmd/karma/bindata_assetfs.go $(SOURCES_GO) + $(eval GOOS := $(call word-split,$*,1)) + $(eval GOARCH := $(call word-split,$*,2)) + $(eval GOARM := $(call word-split,$*,3)) + $(eval GOARMBIN := $(patsubst %,v%,$(GOARM))) + $(eval GOEXT := $(patsubst $(GOOS),,$(patsubst windows,.exe,$(GOOS)))) + $(eval BINARY := "karma-$(GOOS)-$(GOARCH)$(GOARMBIN)$(GOEXT)") + @awk -v bin=$(BINARY) -v goos=$(GOOS) -v goarch=$(GOARCH) -v goarm=$(GOARM) 'BEGIN { printf "[+] %-25s GOOS=%-10s GOARCH=%-10s GOARM=%1s\n", bin, goos, goarch, goarm }' + @env CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) go build -o $(BINARY) -ldflags="-X main.version=$(shell make show-version)" ./cmd/karma + @test -f $(BINARY) + @awk -v bin=$(BINARY) -v size=`du -h $(BINARY) | awk '{print $$1}'` -v type="`file -b $(BINARY)`" 'BEGIN { printf "[-] %-25s SIZE=%-10s TYPE=%s\n", bin, size, type }' + +PLATFORMS := cc-darwin-386 cc-darwin-amd64 cc-dragonfly-amd64 cc-freebsd-386 cc-freebsd-amd64 cc-freebsd-arm-5 cc-freebsd-arm-6 cc-freebsd-arm-7 cc-linux-386 cc-linux-amd64 cc-linux-arm-5 cc-linux-arm-6 cc-linux-arm-7 cc-linux-arm64 cc-linux-ppc64 cc-linux-ppc64le cc-linux-mips cc-linux-mipsle cc-linux-mips64 cc-linux-mips64le cc-linux-s390x cc-netbsd-386 cc-netbsd-amd64 cc-netbsd-arm-5 cc-netbsd-arm-6 cc-netbsd-arm-7 cc-openbsd-386 cc-openbsd-amd64 cc-openbsd-arm-5 cc-openbsd-arm-6 cc-openbsd-arm-7 cc-solaris-amd64 cc-windows-386 cc-windows-amd64 +crosscompile: $(PLATFORMS) + @echo diff --git a/make/docker.mk b/make/docker.mk new file mode 100644 index 000000000..992bf42e7 --- /dev/null +++ b/make/docker.mk @@ -0,0 +1,11 @@ +include make/vars.mk + +.PHONY: docker-image +docker-image: + docker build --build-arg VERSION=$(VERSION) -t $(NAME):$(VERSION) . + +.PHONY: run-demo +run-demo: + docker build --build-arg VERSION=$(VERSION) -t $(NAME):demo -f demo/Dockerfile . + @docker rm -f $(NAME)-demo || true + docker run --rm --name $(NAME)-demo -p 8080:8080 -p 9093:9093 -p 9094:9094 $(NAME):demo diff --git a/make/go.mk b/make/go.mk new file mode 100644 index 000000000..4013a83d4 --- /dev/null +++ b/make/go.mk @@ -0,0 +1,65 @@ +include make/vars.mk + +ENV := GO111MODULE=on +GO := $(ENV) go +GOBIN := $(shell go env GOBIN) +ifeq ($(GOBIN),) +GOBIN = $(shell go env GOPATH)/bin +endif + +ui/build/index.html: $(call rwildcard, ui/src ui/package.json ui/package-lock.json, *) + @$(MAKE) -C ui build + +$(GOBIN)/go-bindata: go.mod go.sum + $(GO) install github.com/go-bindata/go-bindata/... +$(GOBIN)/go-bindata-assetfs: $(GOBIN)/go-bindata go.mod go.sum + $(GO) install github.com/elazarl/go-bindata-assetfs/... +cmd/karma/bindata_assetfs.go: $(GOBIN)/go-bindata-assetfs $(SOURCES_JS) ui/build/index.html + go-bindata-assetfs -o cmd/karma/bindata_assetfs.go ui/build/... ui/src/... cmd/karma/tests/bindata/... + +.DEFAULT_GOAL := $(NAME) +$(NAME): go.mod go.sum cmd/karma/bindata_assetfs.go $(SOURCES_GO) + $(GO) build -ldflags "-X main.version=$(VERSION)" ./cmd/karma + +$(GOBIN)/gocovmerge: go.mod go.sum + $(GO) install github.com/hansboder/gocovmerge +.PHONY: test-go +test-go: $(GOBIN)/gocovmerge + @rm -f profile.* + $(ENV) ./scripts/test-unit.sh + $(ENV) ./scripts/test-main.sh + $(ENV) ./scripts/gocovmerge.sh + +.PHONY: benchmark-go +benchmark-go: + $(GO) test -run=NONE -bench=. -benchmem ./... + +$(GOBIN)/golangci-lint: go.mod go.sum + $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint +.PHONY: lint-go +lint-go: $(GOBIN)/golangci-lint + $(ENV) golangci-lint run -v + +.PHONY: format-go +format-go: + gofmt -l -s -w . + +.PHONY: download-deps-go +download-deps-go: + $(GO) mod download + +.PHONY: install-deps-build-go +install-deps-build-go: $(GOBIN)/go-bindata-assetfs + +.PHONY: openapi-client +openapi-client: + for f in $(wildcard internal/mapper/*/Dockerfile) ; do $(MAKE) -C `dirname "$$f"` ; done + +# Creates mock bindata_assetfs.go with source assets +.PHONY: mock-assets +mock-assets: $(GOBIN)/go-bindata-assetfs + rm -fr ui/build + mkdir ui/build + cp ui/public/* ui/build/ + go-bindata-assetfs -o cmd/karma/bindata_assetfs.go -nometadata ui/build/... cmd/karma/tests/bindata/... + rm -fr ui/build diff --git a/make/lint-versions.mk b/make/lint-versions.mk new file mode 100644 index 000000000..89f720142 --- /dev/null +++ b/make/lint-versions.mk @@ -0,0 +1,22 @@ +.PHONY: lint-golang-version +lint-golang-version: + $(eval CI_VERSION := $(shell grep -E '^(\ +)go:' .travis.yml | awk '{print $$2}' | tr -d "'\"" | sed -E s_'^([0-9]+\.[0-9]+)$$'_'\1.0'_g)) + $(eval BUILD_VERSION := $(shell grep -E '^FROM golang:' Dockerfile | cut -d : -f 2 | awk '{print $1}' | cut -d '-' -f 1)) + $(eval DEMO_VERSION := $(shell grep -E '^FROM golang:' demo/Dockerfile | cut -d : -f 2 | awk '{print $1}' | cut -d '-' -f 1)) + @if [ "$(CI_VERSION)" != "$(BUILD_VERSION)" ] || [ "$(CI_VERSION)" != "$(DEMO_VERSION)" ] || [ "$(BUILD_VERSION)" != "$(DEMO_VERSION)" ]; then \ + echo "Golang version mismatch: CI_VERSION=$(CI_VERSION) BUILD_VERSION=$(BUILD_VERSION) DEMO_VERSION=$(DEMO_VERSION)"; \ + exit 1; \ + fi + +.PHONY: lint-nodejs-version +lint-nodejs-version: + $(eval CI_VERSION := $(shell cat .nvmrc)) + $(eval BUILD_VERSION := $(shell grep -E '^FROM node:' Dockerfile | cut -d : -f 2 | awk '{print $1}' | cut -d '-' -f 1)) + $(eval DEMO_VERSION := $(shell grep -E '^FROM node:' demo/Dockerfile | cut -d : -f 2 | awk '{print $1}' | cut -d '-' -f 1)) + @if [ "$(CI_VERSION)" != "$(BUILD_VERSION)" ] || [ "$(CI_VERSION)" != "$(DEMO_VERSION)" ] || [ "$(BUILD_VERSION)" != "$(DEMO_VERSION)" ]; then \ + echo "Node version mismatch: CI_VERSION=$(CI_VERSION) BUILD_VERSION=$(BUILD_VERSION) DEMO_VERSION=$(DEMO_VERSION)"; \ + exit 1; \ + fi + +.PHONY: lint-versions +lint-versions: lint-golang-version lint-nodejs-version diff --git a/make/vars.mk b/make/vars.mk new file mode 100644 index 000000000..b87854458 --- /dev/null +++ b/make/vars.mk @@ -0,0 +1,10 @@ +NAME := karma +VERSION ?= $(shell git describe --tags --always --dirty='-dev') + +# define a recursive wildcard function, we'll need it to find deeply nested +# sources in the ui directory +# based on http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html +rwildcard = $(foreach d, $(wildcard $1*), $(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) + +SOURCES_GO = $(call rwildcard, cmd internal, *) +SOURCES_JS = $(call rwildcard, ui/build/index.html ui/src cmd/karma/test/bindata, *) diff --git a/ui/Makefile b/ui/Makefile new file mode 100644 index 000000000..aa6dd948c --- /dev/null +++ b/ui/Makefile @@ -0,0 +1,38 @@ +# define a recursive wildcard function, we'll need it to find deeply nested +# sources in the ui directory +# based on http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html +rwildcard = $(foreach d, $(wildcard $1*), $(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) + +node_modules/%: package.json package-lock.json + npm install + touch $@ + +build/index.html: node_modules/react-scripts/bin/react-scripts.js $(call rwildcard, public src, *) + npm run build + +.PHONY: build +build: build/index.html + +.PHONY: test-js +test-js: node_modules/jest/bin/jest.js + CI=true npm test -- --coverage + +.PHONY: test-percy +test-percy: node_modules/@storybook/react/bin/build.js + CI=true npm run snapshot + +.PHONY: lint-js +lint-js: node_modules/eslint/bin/eslint.js + node_modules/eslint/bin/eslint.js --quiet src + +.PHONY: lint-git-ci +lint-git-ci: node_modules/@commitlint/travis-cli/lib/cli.js + node_modules/@commitlint/travis-cli/lib/cli.js + +.PHONY: lint-docs +lint-docs: node_modules/markdownlint-cli/markdownlint.js + node_modules/markdownlint-cli/markdownlint.js ../*.md ../docs + +.PHONY: format +format: node_modules/prettier/bin-prettier.js + node_modules/prettier/bin-prettier.js --write 'src/**/*.js' 'src/**/*.tsx' From e79ec0266089c2e0a7ec2be8f1e876833d62b24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Tue, 7 Apr 2020 16:17:43 +0100 Subject: [PATCH 2/2] fix(ci): prune GOCACHE if it gets too big --- .travis.yml | 2 ++ scripts/prune-go-cache.sh | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100755 scripts/prune-go-cache.sh diff --git a/.travis.yml b/.travis.yml index 21f487c41..7aa360c28 100644 --- a/.travis.yml +++ b/.travis.yml @@ -169,6 +169,8 @@ jobs: - shasum -a 512 karma-*.tar.gz | tee sha512sum.txt # verify that there are no uncommited changes - git diff --exit-code + # prune GOCACHE if it gets too big + - ./scripts/prune-go-cache.sh deploy: provider: releases api_key: diff --git a/scripts/prune-go-cache.sh b/scripts/prune-go-cache.sh new file mode 100755 index 000000000..fb7aaba26 --- /dev/null +++ b/scripts/prune-go-cache.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -o errexit +set -o pipefail + + +GOCACHE=$(go env GOCACHE) +SIZE=`du -sxm ${GOCACHE} | awk '{print $1}'` +echo "GOCACHE size: ${SIZE}MB" + +if [ $SIZE -gt 3500 ]; then + echo "Pruning GOCACHE at ${GOCACHE}" + find "${GOCACHE}" -type f -delete +fi