diff --git a/.drone.yml b/.drone.yml index 87ca16e3c..b1bd7bd56 100644 --- a/.drone.yml +++ b/.drone.yml @@ -9,9 +9,12 @@ script: - go get golang.org/x/tools/cmd/cover - go get golang.org/x/tools/cmd/vet - go get -u github.com/jteeuwen/go-bindata/... - - make bindata deps + + - go run make.go bindata - go run make.go build - - go run make.go vet test + - go run make.go vet + - go run make.go test + - make dist notify: diff --git a/.gitignore b/.gitignore index 35e5df54d..63905c71f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ drone.sublime-workspace *.rice-box.go *.db *.txt +*.min.css *.min.js *_bindata.go *.toml diff --git a/Makefile b/Makefile index b2122286a..58694db59 100644 --- a/Makefile +++ b/Makefile @@ -3,16 +3,6 @@ SHA := $(shell git rev-parse --short HEAD) VERSION := 0.4.0-alpha -all: concat bindata build - -deps: - go get github.com/jteeuwen/go-bindata/... - -test: - go vet github.com/drone/drone/pkg/... - go vet github.com/drone/drone/cmd/... - go test -cover -short github.com/drone/drone/pkg/... - # Execute the database test suite against mysql 5.5 # # You can launch a mysql container locally for testing: @@ -22,38 +12,14 @@ test_mysql: TEST_DRIVER="mysql" TEST_DATASOURCE="root@tcp(127.0.0.1:3306)/test" go test -short github.com/drone/drone/pkg/store/builtin mysql -P 3306 --protocol=tcp -u root -e 'drop database test;' -build: - go build -o bin/drone -ldflags "-X main.revision=$(SHA) -X main.version=$(VERSION).$(SHA)" github.com/drone/drone/cmd/drone-server - go build -o bin/drone-agent -ldflags "-X main.revision=$(SHA) -X main.version=$(VERSION).$(SHA)" github.com/drone/drone/cmd/drone-agent - run: - bin/drone-server --debug - -clean: - find . -name "*.out" -delete - find . -name "*_bindata.go" -delete - rm -f bin/drone* - -concat: - cat cmd/drone-server/static/scripts/drone.js \ - cmd/drone-server/static/scripts/services/*.js \ - cmd/drone-server/static/scripts/filters/*.js \ - cmd/drone-server/static/scripts/controllers/*.js \ - cmd/drone-server/static/scripts/term.js > cmd/drone-server/static/scripts/drone.min.js + bin/drone --debug # installs the drone binaries into bin install: install -t /usr/local/bin bin/drone install -t /usr/local/bin bin/drone-agent -# embeds all the static files directly -# into the drone binary file -bindata: - $$GOPATH/bin/go-bindata -o="cmd/drone-server/drone_bindata.go" cmd/drone-server/static/... - -bindata_debug: - $$GOPATH/bin/go-bindata --debug -o="cmd/drone-server/drone_bindata.go" cmd/drone-server/static/... - docker: docker build --file=cmd/drone-build/Dockerfile.alpine --rm=true -t drone/drone-build . diff --git a/make.go b/make.go index 3eea7696b..c9a4cd355 100644 --- a/make.go +++ b/make.go @@ -9,6 +9,7 @@ package main import ( "fmt" + "io/ioutil" "os" "os/exec" "path/filepath" @@ -34,6 +35,7 @@ var steps = map[string]step{ "build": build, "test": test, "image": image, + "clean": clean, } func main() { @@ -62,14 +64,84 @@ func embed() error { // scripts step concatinates all javascript files. func scripts() error { - // concatinate scripts + files := []string{ + "cmd/drone-server/static/scripts/term.js", + "cmd/drone-server/static/scripts/drone.js", + "cmd/drone-server/static/scripts/controllers/repos.js", + "cmd/drone-server/static/scripts/controllers/builds.js", + "cmd/drone-server/static/scripts/controllers/users.js", + "cmd/drone-server/static/scripts/services/repos.js", + "cmd/drone-server/static/scripts/services/builds.js", + "cmd/drone-server/static/scripts/services/users.js", + "cmd/drone-server/static/scripts/services/logs.js", + "cmd/drone-server/static/scripts/services/tokens.js", + "cmd/drone-server/static/scripts/services/feed.js", + "cmd/drone-server/static/scripts/filters/filter.js", + "cmd/drone-server/static/scripts/filters/gravatar.js", + "cmd/drone-server/static/scripts/filters/time.js", + } + + f, err := os.OpenFile( + "cmd/drone-server/static/scripts/drone.min.js", + os.O_CREATE|os.O_RDWR|os.O_TRUNC, + 0660) + + defer f.Close() + + if err != nil { + fmt.Println("Failed to open output file") + return err + } + + for _, input := range files { + content, err := ioutil.ReadFile(input) + + if err != nil { + return err + } + + f.Write(content) + } + return nil } -// styles step concatinates the css files. +// styles step concatinates the stylesheet files. func styles() error { - // concatinate styles - // inject css variables? + files := []string{ + "cmd/drone-server/static/styles/reset.css", + "cmd/drone-server/static/styles/fonts.css", + "cmd/drone-server/static/styles/alert.css", + "cmd/drone-server/static/styles/blankslate.css", + "cmd/drone-server/static/styles/list.css", + "cmd/drone-server/static/styles/label.css", + "cmd/drone-server/static/styles/range.css", + "cmd/drone-server/static/styles/switch.css", + "cmd/drone-server/static/styles/main.css", + } + + f, err := os.OpenFile( + "cmd/drone-server/static/styles/drone.min.css", + os.O_CREATE|os.O_RDWR|os.O_TRUNC, + 0660) + + defer f.Close() + + if err != nil { + fmt.Println("Failed to open output file") + return err + } + + for _, input := range files { + content, err := ioutil.ReadFile(input) + + if err != nil { + return err + } + + f.Write(content) + } + return nil } @@ -170,6 +242,47 @@ func image() error { return nil } +func clean() error { + err := filepath.Walk(".", func(path string, f os.FileInfo, err error) error { + suffixes := []string{ + ".out", + "_bindata.go", + } + + for _, suffix := range suffixes { + if strings.HasSuffix(path, suffix) { + if err := os.Remove(path); err != nil { + return err + } + } + } + + return nil + }) + + if err != nil { + return err + } + + files := []string{ + "bin/drone", + "bin/drone-agent", + "bin/drone-build", + } + + for _, file := range files { + if _, err := os.Stat(file); err != nil { + continue + } + + if err := os.Remove(file); err != nil { + return err + } + } + + return nil +} + // trace is a helper fucntion that writes a command // to stdout similar to bash +x func trace(args []string) {