github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/Makefile (about)

     1  # Makefile variables.
     2  SHELL=/bin/bash -o pipefail
     3  BIN=$(shell go env GOPATH)/bin
     4  
     5  ## Build tools.
     6  DEP=$(BIN)/dep
     7  GO_BINDATA=$(BIN)/go-bindata
     8  GENNY=$(BIN)/genny
     9  
    10  ## Test tools.
    11  GO_JUNIT_REPORT=$(BIN)/go-junit-report
    12  
    13  ## Release tools.
    14  GORELEASER=$(BIN)/goreleaser
    15  GODOWNLOADER=$(BIN)/godownloader
    16  
    17  ## Configurations.
    18  IMAGE?=buildtools
    19  GORELEASER_FLAGS?=--rm-dist
    20  LDFLAGS:=-ldflags '-extldflags "-static" -X github.com/fossas/fossa-cli/cmd/fossa/version.version=$(shell git rev-parse --abbrev-ref HEAD) -X github.com/fossas/fossa-cli/cmd/fossa/version.commit=$(shell git rev-parse HEAD) -X "github.com/fossas/fossa-cli/cmd/fossa/version.goversion=$(shell go version)" -X github.com/fossas/fossa-cli/cmd/fossa/version.buildType=development'
    21  
    22  all: build
    23  
    24  # Installing tools.
    25  $(DEP):
    26  	curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
    27  
    28  $(GO_BINDATA):
    29  	go get -u -v github.com/go-bindata/go-bindata/...
    30  
    31  $(GENNY):
    32  	go get -u -v github.com/cheekybits/genny
    33  
    34  $(GO_JUNIT_REPORT):
    35  	go get -u -v github.com/jstemmer/go-junit-report
    36  
    37  $(GORELEASER): $(DEP)
    38  	go get -d github.com/goreleaser/goreleaser
    39  	cd $$GOPATH/src/github.com/goreleaser/goreleaser
    40  	dep ensure -vendor-only
    41  	go install github.com/goreleaser/goreleaser
    42  
    43  $(GODOWNLOADER): $(DEP)
    44  	mkdir -p $$GOPATH/src/github.com/goreleaser
    45  	cd $$GOPATH/src/github.com/goreleaser && git clone https://github.com/goreleaser/godownloader
    46  	cd $$GOPATH/src/github.com/goreleaser/godownloader && dep ensure
    47  	go install github.com/goreleaser/godownloader
    48  
    49  # Building the CLI.
    50  .PHONY: build
    51  build: $(BIN)/fossa
    52  
    53  $(BIN)/fossa: $(GO_BINDATA) $(GENNY) $(DEP) $(shell find . -name *.go)
    54  	dep check
    55  	go generate ./...
    56  	go build -o $@ $(LDFLAGS) github.com/fossas/fossa-cli/cmd/fossa
    57  
    58  # Building various Docker images.
    59  .PHONY:
    60  docker-base: ./docker/base/Dockerfile
    61  	sudo docker build -t fossa/fossa-cli:base -f ./docker/base/Dockerfile $(DOCKER_FLAGS) .
    62  
    63  .PHONY:
    64  docker-buildtools: docker-base ./docker/buildtools/Dockerfile
    65  	sudo docker build -t fossa/fossa-cli:buildtools -f ./docker/buildtools/Dockerfile $(DOCKER_FLAGS) .
    66  
    67  ## TODO: we will deprecate this image once native integration tests are
    68  ## completely ready.
    69  .PHONY:
    70  docker-fixtures: docker-buildtools ./docker/fixtures/Dockerfile
    71  	sudo docker build -t fossa/fossa-cli:fixtures -f ./docker/fixtures/Dockerfile $(DOCKER_FLAGS) .
    72  
    73  # Development tasks.
    74  .PHONY: dev
    75  dev: docker-$(IMAGE)
    76  	sudo docker run --rm -it \
    77  		-v $$GOPATH/src/github.com/fossas/fossa-cli:/home/fossa/go/src/github.com/fossas/fossa-cli \
    78  		-v $$GOPATH/bin:/home/fossa/go/bin \
    79  		fossa/fossa-cli:$(IMAGE) /bin/bash
    80  
    81  # We don't mount the $GOPATH/bin because the host machine's binaries are
    82  # compiled for Darwin and won't run on Docker (Linux).
    83  .PHONY: dev-osx
    84  dev-osx: docker-$(IMAGE)
    85  	docker run --rm -it \
    86  		-v $$GOPATH/src/github.com/fossas/fossa-cli:/home/fossa/go/src/github.com/fossas/fossa-cli \
    87  		fossa/fossa-cli:$(IMAGE) /bin/bash
    88  
    89  .PHONY: vendor
    90  vendor: $(DEP)
    91  	$< ensure -v
    92  
    93  .PHONY: clean
    94  clean:
    95  	rm -f $(BIN)/fossa
    96  	find . -name *_generated.go | grep -v vendor | xargs rm -f
    97  
    98  # Testing tasks.
    99  .PHONY: test
   100  test:
   101  	make unit-test
   102  	make integration-test
   103  
   104  .PHONY: unit-test
   105  unit-test:
   106  	go test -short -covermode=atomic $(GO_TEST_FLAGS) ./...
   107  
   108  .PHONY: ci-unit-test
   109  ci-unit-test: $(GO_JUNIT_REPORT)
   110  	GO_TEST_FLAGS="-coverprofile=coverage.txt -v" make -s unit-test | go-junit-report;
   111  	if [ -n "$${CODECOV_TOKEN}" ]; then curl -s https://codecov.io/bash | bash 1>&2; fi
   112  
   113  .PHONY: integration-test
   114  integration-test:
   115  	# Ensure the binary is recompiled before every test.
   116  	make
   117  	go test -covermode=atomic $(GO_TEST_FLAGS) ./...
   118  
   119  .PHONY: ci-integration-test
   120  ci-integration-test: $(GO_JUNIT_REPORT)
   121  	GO_TEST_FLAGS="-coverprofile=coverage.txt -v" make -s integration-test | go-junit-report;
   122  	if [ -n "$${CODECOV_TOKEN}" ]; then curl -s https://codecov.io/bash | bash 1>&2; fi
   123  
   124  # Release tasks.
   125  install.sh: $(GODOWNLOADER)
   126  	# 1. Set default installation location to /usr/local/bin.
   127  	# 2. Use default permissions for /usr/local/bin.
   128  	# 3. Try `sudo install` when `install` fails.
   129  	godownloader --repo=fossas/fossa-cli \
   130  		| sed 's/\.\/bin/\/usr\/local\/bin/' \
   131  		| sed 's/install -d/install -d -m 775/' \
   132  		| sed 's/install "$${srcdir}\/$${binexe}" "$${BINDIR}\/"/install "$${srcdir}\/$${binexe}" "$${BINDIR}\/" 2> \/dev\/null || sudo install "$${srcdir}\/$${binexe}" "$${BINDIR}\/"/' \
   133  		> install.sh
   134  
   135  .PHONY: release
   136  release: $(GORELEASER) install.sh
   137  	# Check that the commit is tagged and starts with "v".
   138  	[[ $$(git tag -l --points-at HEAD) == v* ]]
   139  	GOVERSION=$$(go version) goreleaser $(GORELEASER_FLAGS)