Skip to content
This repository has been archived by the owner on May 6, 2021. It is now read-only.

Commit

Permalink
fix imports and make build
Browse files Browse the repository at this point in the history
  • Loading branch information
sbose78 committed Oct 31, 2018
1 parent 5f0c23c commit 2d2fd00
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 87 deletions.
10 changes: 10 additions & 0 deletions .make/Makefile.lnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SERVER_BIN=$(INSTALL_PREFIX)/build-tool-detector
GOAGEN_BIN=$(VENDOR_DIR)/github.com/goadesign/goa/goagen/goagen
GOCOV_BIN=$(VENDOR_DIR)/github.com/axw/gocov/gocov/gocov
GOCOVMERGE_BIN=$(VENDOR_DIR)/github.com/wadey/gocovmerge/gocovmerge
GIT_BIN_NAME:=git
GO_BIN_NAME:=go
DEP_BIN_NAME:=dep
DOCKER_BIN_NAME=docker
CHECK_GOPATH_BIN:=$(INSTALL_PREFIX)/check_gopath
UNAME_S:=$(shell uname -s)
10 changes: 10 additions & 0 deletions .make/Makefile.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SERVER_BIN=$(INSTALL_PREFIX)/build-tool-detector.exe
GOAGEN_BIN=$(VENDOR_DIR)/github.com/goadesign/goa/goagen/goagen.exe
EXTRA_PATH=$(shell cygpath --unix '$(GO_BINDATA_DIR)')
GOCOV_BIN=$(VENDOR_DIR)/github.com/axw/gocov/gocov/gocov.exe
GOCOVMERGE_BIN=$(VENDOR_DIR)/github.com/wadey/gocovmerge/gocovmerge.exe
GIT_BIN_NAME=git.exe
GO_BIN_NAME=go.exe
DEP_BIN_NAME=dep.exe
DOCKER_BIN_NAME=docker.exe
CHECK_GOPATH_BIN := $(INSTALL_PREFIX)/check_gopath.exe
46 changes: 46 additions & 0 deletions .make/check_gopath.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"flag"
"fmt"
"log"
"os"
"path"
"path/filepath"
"runtime"
"strings"
)

// Checks if the packageName is checked out into one of the GOPATH entries
// under GOPATH[i]/src/packageName.
func main() {
var packageName string
flag.StringVar(&packageName, "packageName", "github.com/fabric8-services/build-tool-detector", "Package Name (e.g.)")
flag.Parse()

wd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}

for _, p := range strings.Split(os.Getenv("GOPATH"), string(filepath.ListSeparator)) {
// Check if p is a directory
if info, err := os.Stat(p); err == nil && info.IsDir() {
// Make sure we have an absolute path
abs, err := filepath.Abs(p)
if err != nil {
log.Fatal(err)
}
if wd == filepath.Join(abs, "src", packageName) {
os.Exit(0)
}
}
}

goPathStr := path.Join("$GOPATH", "src", packageName)
if runtime.GOOS == "windows" {
goPathStr = path.Join("%GOPATH%", "src", packageName)
}
log.Fatal(fmt.Errorf("Make sure you've checked out your project in %s", goPathStr))

}
5 changes: 2 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

233 changes: 179 additions & 54 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,61 +1,186 @@
#! /usr/bin/make
PROJECT_NAME=build-tool-detector
PACKAGE_NAME:=github.com/fabric8-services/$(PROJECT_NAME)
CUR_DIR=$(shell pwd)
TMP_PATH=$(CUR_DIR)/tmp
INSTALL_PREFIX=$(CUR_DIR)/bin
VENDOR_DIR=vendor
SOURCE_DIR ?= .
SOURCES := $(shell find $(SOURCE_DIR) -path $(SOURCE_DIR)/vendor -prune -o -name '*.go' -print)
DESIGN_DIR=design
DESIGNS := $(shell find $(SOURCE_DIR)/$(DESIGN_DIR) -path $(SOURCE_DIR)/vendor -prune -o -name '*.go' -print)

ifeq ($(OS),Windows_NT)
include ./.make/Makefile.win
else
include ./.make/Makefile.lnx
endif


CURRENT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PROJECT_REPO := 'github.com/tinakurian'
PROJECT_NAME := 'build-tool-detector'

.DEFAULT_GOAL := all

all: clean install generate build test check
# This is a fix for a non-existing user in passwd file when running in a docker
# container and trying to clone repos of dependencies
GIT_COMMITTER_NAME ?= "user"
GIT_COMMITTER_EMAIL ?= "[email protected]"
export GIT_COMMITTER_NAME
export GIT_COMMITTER_EMAIL

# Build configuration
BUILD_TIME=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
BINARY_DIR:=${PWD}/bin
BINARY:=build-tool-detector
GITUNTRACKEDCHANGES:=$(shell git status --porcelain --untracked-files=no)
COMMIT=$(shell git rev-parse HEAD 2>/dev/null)
GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
ifneq ($(GITUNTRACKEDCHANGES),)
COMMIT := $(COMMIT)-dirty
COMMIT := $(COMMIT)-dirty
endif
LDFLAGS="-X main.Commit=${COMMIT} -X main.BuildTime=${BUILD_TIME}"
LDFLAGS2="-X main.ghClientID=${ghClientID} -X main.ghClientSecret=${ghClientSecret}"

SOURCEDIR=.
SOURCES := $(shell find $(SOURCEDIR) -name '*.go')

build: clean generate $(BINARY) ## Compiles executable
$(BINARY): $(SOURCES)
@go build -ldflags ${LDFLAGS} -o ${BINARY_DIR}/${BINARY}

help: ## Hey! That's me!
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-10s\033[0m %s\n", $$1, $$2}'

.PHONY: install ## Fetches all dependencies using dep
install:
dep ensure -v

.PHONY: update ## Updates all dependencies defined for dep
update:
dep ensure -update -v

clean: ## Cleans up the project binaries and generated Goa files
@rm -rf app
@rm -rf client
@rm -rf tool
@rm -rf public/swagger
@rm -rf public/schema
@rm -rf public/js
if [ -f ${BINARY_DIR} ] ; then rm ${BINARY_DIR} ; fi


generate: clean ## (re)generates all goagen-generated files
@goagen controller -d $(PROJECT_REPO)/$(PROJECT_NAME)/design -o controllers
@goagen app -d $(PROJECT_REPO)/$(PROJECT_NAME)/design
@goagen swagger -d $(PROJECT_REPO)/$(PROJECT_NAME)/design
@goagen schema -d $(PROJECT_REPO)/$(PROJECT_NAME)/design -o public
@goagen client -d $(PROJECT_REPO)/$(PROJECT_NAME)/design

.PHONY: test
test: build ## Executes all tests
BUILD_TIME=`date -u '+%Y-%m-%dT%H:%M:%SZ'`

.DEFAULT_GOAL := help

This comment has been minimized.

Copy link
@bartoszmajsak

bartoszmajsak Nov 5, 2018

Contributor

I think the default goal should be all. Why is it help? I would assume typing make will just "make" the project. WDYT @tinakurian @sbose78?

I also think this commit should come as two (and maybe even PRs to spread the knowledge)

This comment has been minimized.

Copy link
@sbose78

sbose78 Nov 5, 2018

Author Member

Right, make should do a make build?

I usually never push to master directly without a PR, but did it this time because

  • this commit made the master compile again ( after moving the repo ).
  • I'm trying to cover all the dependencies we have, in order to get this deployed ( or at least have a CI setup asap ).

# Call this function with $(call log-info,"Your message")
define log-info =
@echo "INFO: $(1)"
endef

# -------------------------------------------------------------------
# help!
# -------------------------------------------------------------------

.PHONY: help
help: ## Prints this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort

# -------------------------------------------------------------------
# required tools
# -------------------------------------------------------------------

# Find all required tools:
GIT_BIN := $(shell command -v $(GIT_BIN_NAME) 2> /dev/null)

DEP_BIN_DIR := $(TMP_PATH)/bin
DEP_BIN := $(DEP_BIN_DIR)/$(DEP_BIN_NAME)
DEP_VERSION=v0.4.1

GO_BIN := $(shell command -v $(GO_BIN_NAME) 2> /dev/null)

$(INSTALL_PREFIX):
mkdir -p $(INSTALL_PREFIX)
$(TMP_PATH):
mkdir -p $(TMP_PATH)

.PHONY: prebuild-check
prebuild-check: $(TMP_PATH) $(INSTALL_PREFIX)
# Check that all tools where found
ifndef GIT_BIN
$(error The "$(GIT_BIN_NAME)" executable could not be found in your PATH)
endif
ifndef DEP_BIN
$(error The "$(DEP_BIN_NAME)" executable could not be found in your PATH)
endif
ifndef GO_BIN
$(error The "$(GO_BIN_NAME)" executable could not be found in your PATH)
endif

# -------------------------------------------------------------------
# deps
# -------------------------------------------------------------------
$(DEP_BIN_DIR):
mkdir -p $(DEP_BIN_DIR)



.PHONY: deps
deps: $(DEP_BIN) $(VENDOR_DIR) ## Download build dependencies.

# install dep in a the tmp/bin dir of the repo
$(DEP_BIN): $(DEP_BIN_DIR)
@echo "Installing 'dep' $(DEP_VERSION) at '$(DEP_BIN_DIR)'..."
mkdir -p $(DEP_BIN_DIR)
ifeq ($(UNAME_S),Darwin)
@curl -L -s https://github.com/golang/dep/releases/download/$(DEP_VERSION)/dep-darwin-amd64 -o $(DEP_BIN)
@cd $(DEP_BIN_DIR) && \
curl -L -s https://github.com/golang/dep/releases/download/$(DEP_VERSION)/dep-darwin-amd64.sha256 -o $(DEP_BIN_DIR)/dep-darwin-amd64.sha256 && \
echo "1544afdd4d543574ef8eabed343d683f7211202a65380f8b32035d07ce0c45ef dep" > dep-darwin-amd64.sha256 && \
shasum -a 256 --check dep-darwin-amd64.sha256
else
@curl -L -s https://github.com/golang/dep/releases/download/$(DEP_VERSION)/dep-linux-amd64 -o $(DEP_BIN)
@cd $(DEP_BIN_DIR) && \
echo "31144e465e52ffbc0035248a10ddea61a09bf28b00784fd3fdd9882c8cbb2315 dep" > dep-linux-amd64.sha256 && \
sha256sum -c dep-linux-amd64.sha256
endif
@chmod +x $(DEP_BIN)

$(VENDOR_DIR): Gopkg.toml
@echo "checking dependencies with $(DEP_BIN_NAME)"
@$(DEP_BIN) ensure -v


# -------------------------------------------------------------------
# support for generating goa code
# -------------------------------------------------------------------
$(GOAGEN_BIN): $(VENDOR_DIR)
cd $(VENDOR_DIR)/github.com/goadesign/goa/goagen && go build -v

# -------------------------------------------------------------------
# clean
# -------------------------------------------------------------------

# For the global "clean" target all targets in this variable will be executed
CLEAN_TARGETS =

CLEAN_TARGETS += clean-artifacts
.PHONY: clean-artifacts
## Removes the ./bin directory.
clean-artifacts:
-rm -rf $(INSTALL_PREFIX)

CLEAN_TARGETS += clean-object-files
.PHONY: clean-object-files
## Runs go clean to remove any executables or other object files.
clean-object-files:
go clean ./...

CLEAN_TARGETS += clean-generated
.PHONY: clean-generated
## Removes all generated code.
clean-generated:
-rm -rf ./app
-rm -rf ./swagger/

CLEAN_TARGETS += clean-vendor
.PHONY: clean-vendor
## Removes the ./vendor directory.
clean-vendor:
-rm -rf $(VENDOR_DIR)

CLEAN_TARGETS += clean-tmp
.PHONY: clean-tmp
## Removes the ./vendor directory.
clean-tmp:
-rm -rf $(TMP_DIR)

# Keep this "clean" target here after all `clean-*` sub tasks
.PHONY: clean
clean: $(CLEAN_TARGETS) ## Runs all clean-* targets.

# -------------------------------------------------------------------
# build the binary executable (to ship in prod)
# -------------------------------------------------------------------
LDFLAGS=-ldflags "-X ${PACKAGE_NAME}/app.Commit=${COMMIT} -X ${PACKAGE_NAME}/app.BuildTime=${BUILD_TIME}"

$(SERVER_BIN): prebuild-check deps generate ## Build the server
@echo "building $(SERVER_BIN)..."
go build -v $(LDFLAGS) -o $(SERVER_BIN)

.PHONY: build
build: $(SERVER_BIN) ## Build the server

.PHONY: generate
generate: prebuild-check $(DESIGNS) $(GOAGEN_BIN) $(VENDOR_DIR) ## Generate GOA sources. Only necessary after clean of if changed `design` folder.
$(GOAGEN_BIN) app -d ${PACKAGE_NAME}/${DESIGN_DIR}
$(GOAGEN_BIN) controller -d ${PACKAGE_NAME}/${DESIGN_DIR} -o controllers/ --pkg controllers --app-pkg ${PACKAGE_NAME}/app
$(GOAGEN_BIN) swagger -d ${PACKAGE_NAME}/${DESIGN_DIR}


.PHONY: test
test: build ## Executes all tests
@ginkgo -r

.PHONY: format ## Removes unneeded imports and formats source code
Expand All @@ -67,8 +192,8 @@ check: ## Concurrently runs a whole bunch of static analysis tools
@gometalinter --enable=misspell --enable=gosimple --enable-gc --vendor --skip=app --skip=client --skip=tool --exclude ^app/test/ --deadline 300s ./...

.PHONY: run
run: ## runs the service locally
${BINARY_DIR}/${BINARY}
run: build ## runs the service locally
$SERVER_BIN

.PHONY: tools
tools: ## Installs all necessary tools
Expand Down
14 changes: 7 additions & 7 deletions controllers/build-tool-detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
"fmt"

"github.com/goadesign/goa"
"github.com/tinakurian/build-tool-detector/app"
"github.com/tinakurian/build-tool-detector/config"
errs "github.com/tinakurian/build-tool-detector/controllers/error"
"github.com/tinakurian/build-tool-detector/domain/repository"
"github.com/tinakurian/build-tool-detector/domain/repository/github"
"github.com/tinakurian/build-tool-detector/domain/types"
"github.com/tinakurian/build-tool-detector/log"
"github.com/fabric8-services/build-tool-detector/app"
"github.com/fabric8-services/build-tool-detector/config"
errs "github.com/fabric8-services/build-tool-detector/controllers/error"
"github.com/fabric8-services/build-tool-detector/domain/repository"
"github.com/fabric8-services/build-tool-detector/domain/repository/github"
"github.com/fabric8-services/build-tool-detector/domain/types"
"github.com/fabric8-services/build-tool-detector/log"
)

var (
Expand Down
6 changes: 3 additions & 3 deletions controllers/build-tool-detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/viper"
"github.com/tinakurian/build-tool-detector/app/test"
"github.com/tinakurian/build-tool-detector/config"
controllers "github.com/tinakurian/build-tool-detector/controllers"
"github.com/fabric8-services/build-tool-detector/app/test"
"github.com/fabric8-services/build-tool-detector/config"
controllers "github.com/fabric8-services/build-tool-detector/controllers"
"gopkg.in/h2non/gock.v1"
)

Expand Down
2 changes: 1 addition & 1 deletion controllers/error/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/tinakurian/build-tool-detector/controllers/error"
. "github.com/fabric8-services/build-tool-detector/controllers/error"
)

var _ = Describe("Error", func() {
Expand Down
4 changes: 2 additions & 2 deletions domain/repository/github/github_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"net/http"

"github.com/google/go-github/github"
"github.com/tinakurian/build-tool-detector/config"
"github.com/tinakurian/build-tool-detector/domain/types"
"github.com/fabric8-services/build-tool-detector/config"
"github.com/fabric8-services/build-tool-detector/domain/types"
)

const (
Expand Down
Loading

0 comments on commit 2d2fd00

Please sign in to comment.