Skip to content

Commit

Permalink
fix: improve makefile dependency building
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Aug 5, 2020
1 parent d36c26f commit 8e1d69a
Showing 1 changed file with 44 additions and 32 deletions.
76 changes: 44 additions & 32 deletions Makefile
Expand Up @@ -7,45 +7,57 @@ K := $(foreach exec,$(EXECUTABLES),\
export GO111MODULE := on
export PATH := .bin:${PATH}

.PHONY: deps
deps:
ifneq ("$(shell base64 Makefile))","$(shell cat .bin/.lock)")
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b .bin/ v1.24.0
bash <(curl https://raw.githubusercontent.com/ory/hydra/master/install.sh) -b .bin/ v1.4.10
go build -o .bin/go-acc github.com/ory/go-acc
go build -o .bin/goreturns github.com/sqs/goreturns
go build -o .bin/listx github.com/ory/x/tools/listx
go build -o .bin/mockgen github.com/golang/mock/mockgen
go build -o .bin/swagger github.com/go-swagger/go-swagger/cmd/swagger
go build -o .bin/goimports golang.org/x/tools/cmd/goimports
go build -o .bin/packr2 github.com/gobuffalo/packr/v2/packr2
go build -o .bin/yq github.com/mikefarah/yq
go build -o .bin/pkger github.com/markbates/pkger/cmd/pkger
go build -o .bin/ory github.com/ory/cli
GO_DEPENDENCIES = github.com/ory/go-acc \
github.com/sqs/goreturns \
github.com/ory/x/tools/listx \
github.com/golang/mock/mockgen \
github.com/go-swagger/go-swagger/cmd/swagger \
golang.org/x/tools/cmd/goimports \
github.com/ory/cli \
github.com/mikefarah/yq \
github.com/markbates/pkger/cmd/pkger \
github.com/gobuffalo/packr/v2/packr2

define make-go-dependency
# go install is responsible for not re-building when the code hasn't changed
.PHONY: .bin/$(notdir $1)
.bin/$(notdir $1):
GOBIN=$(PWD)/.bin/ go install $1
endef
$(foreach dep, $(GO_DEPENDENCIES), $(eval $(call make-go-dependency, $(dep))))
$(call make-lint-dependency)

node_modules: package.json
npm ci
echo "$$(base64 Makefile)" > .bin/.lock
endif

docs/node_modules: docs/package.json
cd docs; npm ci

.bin/golangci-lint: Makefile
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b .bin v1.24.0

.bin/hydra: Makefile
bash <(curl https://raw.githubusercontent.com/ory/hydra/master/install.sh) -b .bin v1.4.10

.PHONY: docs
docs:
cd docs; npm i; npm run build
docs: docs/node_modules
cd docs; npm run build

.PHONY: lint
lint: deps
which golangci-lint
GO111MODULE=on golangci-lint run -v ./...
lint: .bin/golangci-lint
golangci-lint run -v ./...

.PHONY: cover
cover:
go test ./... -coverprofile=cover.out
go tool cover -func=cover.out

.PHONE: mocks
mocks: deps
mocks: .bin/mockgen
mockgen -mock_names Manager=MockLoginExecutorDependencies -package internal -destination internal/hook_login_executor_dependencies.go github.com/ory/kratos/selfservice loginExecutorDependencies

.PHONY: install
install: deps
install: .bin/packr2
packr2
GO111MODULE=on go install -tags sqlite .
packr2 clean
Expand All @@ -60,9 +72,9 @@ test:

# Generates the SDK
.PHONY: sdk
sdk: deps
sdk: .bin/swagger .bin/cli
swagger generate spec -m -o .schema/api.swagger.json -x internal/httpclient
ory dev swagger sanitize ./.schema/api.swagger.json
cli dev swagger sanitize ./.schema/api.swagger.json
swagger validate ./.schema/api.swagger.json
swagger flatten --with-flatten=remove-unused -o ./.schema/api.swagger.json ./.schema/api.swagger.json
swagger validate ./.schema/api.swagger.json
Expand All @@ -84,7 +96,7 @@ quickstart-dev:

# Formats the code
.PHONY: format
format: deps
format: .bin/goreturns
goreturns -w -local github.com/ory $$(listx .)
npm run format

Expand All @@ -94,17 +106,17 @@ docker:
docker build -f .docker/Dockerfile-build -t oryd/kratos:latest-sqlite .

.PHONY: test-e2e
test-e2e: test-resetdb
test-e2e: node_modules test-resetdb
source script/test-envs.sh
test/e2e/run.sh sqlite
test/e2e/run.sh postgres
test/e2e/run.sh cockroach
test/e2e/run.sh mysql

.PHONY: migrations-sync
migrations-sync:
ory dev pop migration sync persistence/sql/migrations/templates persistence/sql/migratest/testdata
migrations-sync: .bin/cli
cli dev pop migration sync persistence/sql/migrations/templates persistence/sql/migratest/testdata

.PHONY: migrations-render
migrations-render:
ory dev pop migration render persistence/sql/migrations/templates persistence/sql/migrations/sql
migrations-render: .bin/cli
cli dev pop migration render persistence/sql/migrations/templates persistence/sql/migrations/sql

0 comments on commit 8e1d69a

Please sign in to comment.