Skip to content

Commit

Permalink
Merge pull request #6 from lpabon/makefile
Browse files Browse the repository at this point in the history
Makefile for csi-sanity
  • Loading branch information
lpabon authored Dec 20, 2017
2 parents 5d7652f + 5623d44 commit 3a003f9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
58 changes: 55 additions & 3 deletions cmd/csi-sanity/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,59 @@
all: csi-sanity
APP_NAME := csi-sanity
#VER :=$(shell git describe).$(shell git log --oneline -1 --pretty=format:"%h")
VER :=$(shell git log --oneline -1 --pretty=format:"%h")
BRANCH := $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
SHA := $(shell git rev-parse --short HEAD)
ARCH := $(shell go env GOARCH)
GOOS := $(shell go env GOOS)
DIR=.

csi-sanity: sanity_test.go
go test -c -o csi-sanity
ifdef APP_SUFFIX
VERSION = $(VER)-$(subst /,-,$(APP_SUFFIX))
else
ifeq (master,$(BRANCH))
VERSION = $(VER)
else
VERSION = $(VER)-$(BRANCH)
endif
endif

LDFLAGS :=-ldflags "-w -X github.com/kubernetes-csi/csi-test/cmd/csi-sanity.VERSION=$(VERSION) -extldflags '-z relro -z now'"
PACKAGE :=$(DIR)/dist/$(APP_NAME)-$(VERSION).$(GOOS).$(ARCH).tar.gz

all: $(APP_NAME)

$(APP_NAME): Makefile sanity_test.go
go test $(LDFLAGS) -c -o $(APP_NAME)

clean:
rm -f csi-sanity
rm -rf $(DIR)/dist

dist: $(PACKAGE)

$(PACKAGE): $(APP_NAME)
@echo Packaging Binaries...
@mkdir -p tmp/$(APP_NAME)
@cp $(APP_NAME) tmp/$(APP_NAME)/
@mkdir -p $(DIR)/dist/
tar -czf $@ -C tmp $(APP_NAME);
@rm -rf tmp
@echo
@echo Package $@ saved in dist directory

linux_amd64_dist:
GOOS=linux GOARCH=amd64 $(MAKE) dist

linux_arm_dist:
GOOS=linux GOARCH=arm $(MAKE) dist

linux_arm64_dist:
GOOS=linux GOARCH=arm64 $(MAKE) dist

darwin_amd64_dist:
GOOS=darwin GOARCH=amd64 $(MAKE) dist

release: darwin_amd64_dist linux_arm_dist linux_amd64_dist linux_arm64_dist

.PHONY: release darwin_amd64_dist linux_arm64_dist linux_amd64_dist \
linux_arm_dist linux_amd64_dist clean
8 changes: 8 additions & 0 deletions cmd/csi-sanity/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package sanity

import (
"flag"
"fmt"
"testing"

"github.com/kubernetes-csi/csi-test/pkg/sanity"
Expand All @@ -27,15 +28,22 @@ const (
)

var (
VERSION = "(dev)"
endpoint string
version bool
)

func init() {
flag.StringVar(&endpoint, prefix+"endpoint", "", "CSI endpoint")
flag.BoolVar(&version, prefix+"version", false, "Version of this program")
flag.Parse()
}

func TestSanity(t *testing.T) {
if version {
fmt.Printf("Version = %s\n", VERSION)
return
}
if len(endpoint) == 0 {
t.Fatalf("--%s.endpoint must be provided with an CSI endpoint", prefix)
}
Expand Down

0 comments on commit 3a003f9

Please sign in to comment.