Skip to content

Commit

Permalink
fix: use .bin in PATH and improve CI tasks (ory#1897)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Jun 8, 2020
1 parent 4bfbddb commit 9c6eba8
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 168 deletions.
1 change: 1 addition & 0 deletions .bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
16 changes: 8 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ version: 2.1
orbs:
goreleaser: ory/goreleaser@0.1.8
slack: circleci/slack@3.4.2
sdk: ory/sdk@0.1.33
sdk: ory/sdk@0.1.35
changelog: ory/changelog@0.1.2
nancy: ory/nancy@0.0.9
nancy: ory/nancy@0.0.10
docs: ory/docs@0.0.4
golangci: ory/golangci@0.0.4

Expand All @@ -25,7 +25,7 @@ jobs:

test:
docker:
- image: circleci/golang:1.14
- image: circleci/golang:1.14-node
environment:
- GO111MODULE=on
- TEST_DATABASE_POSTGRESQL=postgres://test:test@localhost:5432/postgres?sslmode=disable
Expand All @@ -45,20 +45,20 @@ jobs:
steps:
- checkout
- setup_remote_docker
- run: GO111MODULE=off go get github.com/mattn/goveralls github.com/ory/go-acc
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- hydra-v1-{{ checksum "go.sum" }}-{{ checksum "Makefile" }}
- run: go mod download
- run: make deps
- save_cache:
key: go-mod-v1-{{ checksum "go.sum" }}
key: hydra-v1-{{ checksum "go.sum" }}-{{ checksum "Makefile" }}
paths:
- "/go/pkg/mod"
- run: go-acc -o coverage.txt ./... -- -failfast -timeout=20m
- ".bin"
- run: .bin/go-acc -o coverage.txt ./... -- -failfast -timeout=20m
# Running race conditions requires parallel tests, otherwise it's worthless (which is the case)
# - run: go test -race -short $(go list ./... | grep -v cmd)
- run: test -z "$CIRCLE_PR_NUMBER" && goveralls -service=circle-ci -coverprofile=coverage.txt -repotoken=$COVERALLS_REPO_TOKEN || echo "forks are not allowed to push to coveralls"
- run: go install github.com/go-bindata/go-bindata/go-bindata github.com/gobuffalo/packr/v2/packr2
- run: make docker

test-e2e:
Expand Down
79 changes: 46 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
SHELL=/bin/bash -o pipefail

.PHONY: tools
tools:
npm i
go install github.com/ory/go-acc github.com/ory/x/tools/listx github.com/go-swagger/go-swagger/cmd/swagger github.com/go-bindata/go-bindata/go-bindata github.com/sqs/goreturns github.com/ory/sdk/swagutil
EXECUTABLES = docker-compose docker node npm go
K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH")))

export GO111MODULE := on
export PATH := .bin:${PATH}

.PHONY: deps
deps:
ifneq ("$(shell base64 Makefile))","$(shell cat .bin/.lock)")
npm ci
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/ory-dev github.com/ory/meta/tools/ory-dev
go build -o .bin/packr2 github.com/gobuffalo/packr/v2/packr2
go build -o .bin/go-bindata github.com/go-bindata/go-bindata/go-bindata
echo "v0" > .bin/.lock
echo "$$(base64 Makefile)" > .bin/.lock
endif

# Runs full test suite including tests where databases are enabled
.PHONY: test-legacy-migrations
test-legacy-migrations:
test-legacy-migrations: deps
make test-resetdb
make sqlbin
source scripts/test-env.sh && go test -tags legacy_migration_test -failfast -timeout=20m ./internal/fizzmigrate
Expand All @@ -17,16 +36,16 @@ test-legacy-migrations:

# Runs full test suite including tests where databases are enabled
.PHONY: test
test:
test: deps
make test-resetdb
source scripts/test-env.sh && $$(go env GOPATH)/bin/go-acc ./... -- -failfast -timeout=20m
source scripts/test-env.sh && go-acc ./... -- -failfast -timeout=20m
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:
test-resetdb: deps
docker kill hydra_test_database_mysql || true
docker kill hydra_test_database_postgres || true
docker kill hydra_test_database_cockroach || true
Expand All @@ -39,7 +58,7 @@ test-resetdb:

# Runs tests in short mode, without database adapters
.PHONY: docker
docker:
docker: deps
packr2
CGO_ENABLED=0 GO111MODULE=on GOOS=linux GOARCH=amd64 go build
packr2 clean
Expand All @@ -48,8 +67,7 @@ docker:
rm hydra

.PHONY: e2e
e2e:
make test-resetdb
e2e: deps test-resetdb
source ./scripts/test-env.sh
./test/e2e/circle-ci.bash memory
./test/e2e/circle-ci.bash memory-jwt
Expand All @@ -69,42 +87,42 @@ quicktest:

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

# Generates mocks
.PHONY: mocks
mocks:
mocks: deps
mockgen -package oauth2_test -destination oauth2/oauth2_provider_mock_test.go github.com/ory/fosite OAuth2Provider

# Adds sql files to the binary using go-bindata
.PHONY: sqlbin
sqlbin:
cd internal/fizzmigrate/client; $$(go env GOPATH)/bin/go-bindata -o sql_migration_files.go -pkg client ./migrations/sql/...
cd internal/fizzmigrate/consent; $$(go env GOPATH)/bin/go-bindata -o sql_migration_files.go -pkg consent ./migrations/sql/...
cd internal/fizzmigrate/jwk; $$(go env GOPATH)/bin/go-bindata -o sql_migration_files.go -pkg jwk ./migrations/sql/...
cd internal/fizzmigrate/oauth2; $$(go env GOPATH)/bin/go-bindata -o sql_migration_files.go -pkg oauth2 ./migrations/sql/...
sqlbin: deps
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/...

# Runs all code generators
.PHONY: gen
.PHONY: gen deps
gen: mocks sqlbin sdk

# Generates the SDKs
.PHONY: sdk
sdk:
$$(go env GOPATH)/bin/swagger generate spec -m -o ./.schema/api.swagger.json -x internal/httpclient,gopkg.in/square/go-jose.v2
$$(go env GOPATH)/bin/swagutil sanitize ./.schema/api.swagger.json
$$(go env GOPATH)/bin/swagger flatten --with-flatten=remove-unused -o ./.schema/api.swagger.json ./.schema/api.swagger.json
$$(go env GOPATH)/bin/swagger validate ./.schema/api.swagger.json
sdk: deps
swagger generate spec -m -o ./.schema/api.swagger.json -x internal/httpclient,gopkg.in/square/go-jose.v2
ory-dev swagger sanitize ./.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
rm -rf internal/httpclient
mkdir -p internal/httpclient
$$(go env GOPATH)/bin/swagger generate client -f ./.schema/api.swagger.json -t internal/httpclient -A Ory_Hydra
swagger generate client -f ./.schema/api.swagger.json -t internal/httpclient -A Ory_Hydra
make format


.PHONY: install-stable
install-stable:
install-stable: deps
HYDRA_LATEST=$$(git describe --abbrev=0 --tags)
git checkout $$HYDRA_LATEST
packr2
Expand All @@ -115,12 +133,7 @@ install-stable:
git checkout master

.PHONY: install
install:
install: deps
packr2
GO111MODULE=on go install .
packr2 clean

.PHONY: init
init:
GO111MODULE=on go get .
GO111MODULE=on go install github.com/ory/go-acc
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ It is possible to develop ORY Hydra on Windows, but please be aware that all gui

##### Install Tools

When cloning ORY Hydra, run `make tools`. It will download several required dependencies. If you haven't run the command
When cloning ORY Hydra, run `make deps`. It will download several required dependencies. If you haven't run the command
in a while it's probably a good idea to run it again.

#### Formatting Code
Expand Down
4 changes: 2 additions & 2 deletions cmd/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ func setTracingLogger(logger *reqlog.Middleware) {
_, _, spanCtx := httptrace.Extract(r.Context(), r)

if spanCtx.HasTraceID() {
fields = fields.WithField("trace_id", spanCtx.TraceIDString())
fields = fields.WithField("trace_id", spanCtx.TraceID.String())
}
if spanCtx.HasSpanID() {
fields = fields.WithField("span_id", spanCtx.SpanIDString())
fields = fields.WithField("span_id", spanCtx.SpanID.String())
}

return fields
Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ require (
github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e
github.com/ory/analytics-go/v4 v4.0.1
github.com/ory/fosite v0.31.3
github.com/ory/go-acc v0.2.1
github.com/ory/go-acc v0.2.2
github.com/ory/graceful v0.1.1
github.com/ory/herodot v0.8.3
github.com/ory/sdk/swagutil v0.0.0-20200528141631-666b43d19aa3
github.com/ory/meta/tools/ory-dev v0.0.0-20200608154018-9d325ca2087d
github.com/ory/viper v1.7.5
github.com/ory/x v0.0.126
github.com/ory/x v0.0.128
github.com/pborman/uuid v1.2.0
github.com/phayes/freeport v0.0.0-20171002181615-b8543db493a5
github.com/pkg/errors v0.9.1
github.com/pkg/profile v1.3.0 // indirect
github.com/prometheus/client_golang v1.1.0
github.com/prometheus/client_golang v1.4.0
github.com/rs/cors v1.6.0
github.com/rubenv/sql-migrate v0.0.0-20190212093014-1007f53448d7
github.com/sawadashota/encrypta v0.0.2
Expand All @@ -55,11 +55,10 @@ require (
github.com/toqueteos/webbrowser v1.2.0
github.com/uber/jaeger-client-go v2.22.1+incompatible
github.com/urfave/negroni v1.0.0
go.opentelemetry.io/otel v0.2.1
go.opentelemetry.io/otel v0.6.0
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
golang.org/x/tools v0.0.0-20200313205530-4303120df7d8
gopkg.in/square/go-jose.v2 v2.5.0
)
Loading

0 comments on commit 9c6eba8

Please sign in to comment.