-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
133 lines (112 loc) · 4.76 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
SHELL=/bin/bash -o pipefail
export GO111MODULE := on
export PATH := .bin:${PATH}
export PWD := $(shell pwd)
GO_DEPENDENCIES = github.com/ory/go-acc \
golang.org/x/tools/cmd/goimports \
github.com/golang/mock/mockgen \
github.com/go-swagger/go-swagger/cmd/swagger \
github.com/ory/cli \
github.com/go-bindata/go-bindata/go-bindata
define make-go-dependency
# go install is responsible for not re-building when the code hasn't changed
.bin/$(notdir $1): go.sum go.mod
GOBIN=$(PWD)/.bin/ go install $1
endef
.bin/golangci-lint: Makefile
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b .bin v1.31.0
$(foreach dep, $(GO_DEPENDENCIES), $(eval $(call make-go-dependency, $(dep))))
node_modules: package.json
npm ci
docs/node_modules: docs/package.json
cd docs; npm ci
.bin/clidoc: go.mod
go build -o .bin/clidoc ./cmd/clidoc/.
docs/cli: .bin/clidoc
clidoc .
.PHONY: lint
lint: .bin/golangci-lint
golangci-lint run -v ./...
# Runs full test suite including tests where databases are enabled
.PHONY: test-legacy-migrations
test-legacy-migrations: test-resetdb .bin/go-bindata
cd internal/fizzmigrate/client; go-bindata -o sql_migration_files.go -pkg client ./migrations/sql/...
cd internal/fizzmigrate/consent; go-bindata -o sql_migration_files.go -pkg consent ./migrations/sql/...
cd internal/fizzmigrate/jwk; go-bindata -o sql_migration_files.go -pkg jwk ./migrations/sql/...
cd internal/fizzmigrate/oauth2; go-bindata -o sql_migration_files.go -pkg oauth2 ./migrations/sql/...
source scripts/test-env.sh && go test -tags legacy_migration_test sqlite -failfast -timeout=20m ./internal/fizzmigrate
docker rm -f hydra_test_database_mysql
docker rm -f hydra_test_database_postgres
docker rm -f hydra_test_database_cockroach
# Runs full test suite including tests where databases are enabled
.PHONY: test
test: .bin/go-acc
make test-resetdb
source scripts/test-env.sh && go-acc ./... -- -failfast -timeout=20m -tags sqlite
docker rm -f hydra_test_database_mysql
docker rm -f hydra_test_database_postgres
docker rm -f hydra_test_database_cockroach
# Resets the test databases
.PHONY: test-resetdb
test-resetdb: node_modules
docker kill hydra_test_database_mysql || true
docker kill hydra_test_database_postgres || true
docker kill hydra_test_database_cockroach || true
docker rm -f hydra_test_database_mysql || true
docker rm -f hydra_test_database_postgres || true
docker rm -f hydra_test_database_cockroach || true
docker run --rm --name hydra_test_database_mysql -p 3444:3306 -e MYSQL_ROOT_PASSWORD=secret -d mysql:5.7
docker run --rm --name hydra_test_database_postgres -p 3445:5432 -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=postgres -d postgres:9.6
docker run --rm --name hydra_test_database_cockroach -p 3446:26257 -d cockroachdb/cockroach:v20.2.6 start-single-node --insecure
# Runs tests in short mode, without database adapters
.PHONY: docker
docker:
docker build -f .docker/Dockerfile-build -t oryd/hydra:latest-sqlite .
.PHONY: e2e
e2e: node_modules test-resetdb
source ./scripts/test-env.sh
./test/e2e/circle-ci.bash memory
./test/e2e/circle-ci.bash memory-jwt
./test/e2e/circle-ci.bash postgres
./test/e2e/circle-ci.bash postgres-jwt
./test/e2e/circle-ci.bash mysql
./test/e2e/circle-ci.bash mysql-jwt
./test/e2e/circle-ci.bash cockroach
./test/e2e/circle-ci.bash cockroach-jwt
# Runs tests in short mode, without database adapters
.PHONY: quicktest
quicktest:
go test -failfast -short -tags sqlite ./...
# Formats the code
.PHONY: format
format: .bin/goimports node_modules docs/node_modules
goimports -w --local github.com/ory .
npm run format
cd docs; npm run format
# Generates mocks
.PHONY: mocks
mocks: .bin/mockgen
mockgen -package oauth2_test -destination oauth2/oauth2_provider_mock_test.go github.com/ory/fosite OAuth2Provider
# Generates the SDKs
.PHONY: sdk
sdk: .bin/cli
swagger generate spec -m -o ./spec/api.json -x internal/httpclient -x gopkg.in/square/go-jose.v2
cli dev swagger sanitize ./spec/api.json
swagger flatten --with-flatten=remove-unused -o ./spec/api.json ./spec/api.json
swagger validate ./spec/api.json
rm -rf internal/httpclient
mkdir -p internal/httpclient
swagger generate client -f ./spec/api.json -t internal/httpclient -A Ory_Hydra
make format
.PHONY: install-stable
install-stable:
HYDRA_LATEST=$$(git describe --abbrev=0 --tags)
git checkout $$HYDRA_LATEST
GO111MODULE=on go install \
-tags sqlite \
-ldflags "-X github.com/ory/hydra/driver/config.Version=$$HYDRA_LATEST -X github.com/ory/hydra/driver/config.Date=`TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ'` -X github.com/ory/hydra/driver/config.Commit=`git rev-parse HEAD`" \
.
git checkout master
.PHONY: install
install:
GO111MODULE=on go install -tags sqlite .