Skip to content

Commit

Permalink
Adds infrastructure to release gowsdl binaries.
Browse files Browse the repository at this point in the history
  • Loading branch information
c4milo committed Sep 12, 2015
1 parent 18ea5f2 commit ad21f3e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
./gowsdl
myservice
build
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
GHACCOUNT := hooklift
NAME := gowsdl
VERSION := v0.1.0

include common.mk

deps:
go get github.com/c4milo/github-release
go get github.com/mitchellh/gox
go get github.com/hooklift/assert
25 changes: 14 additions & 11 deletions cmd/gowsdl/main.go → cmd/gowsdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,24 @@ package main
import (
"bytes"
"flag"
"fmt"
"go/format"
"log"
"os"
"fmt"

gen "github.com/hooklift/gowsdl"
)

const version = "v0.0.1"
// Version is initialized in compilation time by go build.
var Version string

// Name is initialized in compilation time by go build.
var Name string

var vers = flag.Bool("v", false, "Shows gowsdl version")
var pkg = flag.String("p", "myservice", "Package under which code will be generated")
var outFile = flag.String("o", "myservice.go", "File where the generated code will be saved")


func init() {
log.SetFlags(0)
log.SetOutput(os.Stdout)
Expand All @@ -72,15 +75,15 @@ func init() {

func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] myservice.wsdl\n", os.Args[0])
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "Usage: %s [options] myservice.wsdl\n", os.Args[0])
flag.PrintDefaults()
}

flag.Parse()

// Show app version
if *vers {
log.Println(version)
log.Println(Version)
os.Exit(0)
}

Expand All @@ -96,7 +99,7 @@ func main() {
}

// load wsdl
gowsdl, err := gen.NewGoWsdl(wsdlPath, *pkg, false)
gowsdl, err := gen.NewGoWSDL(wsdlPath, *pkg, false)
if err != nil {
log.Fatalln(err)
}
Expand All @@ -110,11 +113,11 @@ func main() {
pkg := "./" + *pkg
err = os.Mkdir(pkg, 0744)

fd, err := os.Create(pkg + "/" + *outFile)
file, err := os.Create(pkg + "/" + *outFile)
if err != nil {
log.Fatalln(err)
}
defer fd.Close()
defer file.Close()

data := new(bytes.Buffer)
data.Write(gocode["header"])
Expand All @@ -125,11 +128,11 @@ func main() {
// go fmt the generated code
source, err := format.Source(data.Bytes())
if err != nil {
fd.Write(data.Bytes())
file.Write(data.Bytes())
log.Fatalln(err)
}

fd.Write(source)
file.Write(source)

log.Println("Done 💩")
}
42 changes: 42 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
PLATFORM := $(shell go env | grep GOHOSTOS | cut -d '"' -f 2)
ARCH := $(shell go env | grep GOARCH | cut -d '"' -f 2)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
LDFLAGS := -ldflags "-X main.Version=$(VERSION) -X main.Name=$(NAME)"

test:
go test ./...

build:
go build -o build/$(NAME) $(LDFLAGS) cmd/$(NAME).go

install:
go install $(LDFLAGS)

compile:
@rm -rf build/
@gox $(LDFLAGS) \
-os="darwin" \
-os="linux" \
-os="solaris" \
-os="freebsd" \
-output "build/$(NAME)_$(VERSION)_{{.OS}}_{{.Arch}}/$(NAME)" \
./...

dist: compile
$(eval FILES := $(shell ls build))
@rm -rf dist && mkdir dist
@for f in $(FILES); do \
(cd $(shell pwd)/build/$$f && tar -cvzf ../../dist/$$f.tar.gz *); \
(cd $(shell pwd)/dist && shasum -a 512 $$f.tar.gz > $$f.sha512); \
echo $$f; \
done

release: dist
@latest_tag=$$(git describe --tags `git rev-list --tags --max-count=1`); \
comparison="$$latest_tag..HEAD"; \
if [ -z "$$latest_tag" ]; then comparison=""; fi; \
changelog=$$(git log $$comparison --oneline --no-merges --reverse); \
github-release $(GHACCOUNT)/$(NAME) $(VERSION) $(BRANCH) "**Changelog**<br/>$$changelog" 'dist/*'; \
git pull

.PHONY: test build install compile deps dist release

3 comments on commit ad21f3e

@sanbornm
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit broke go get install of binary, I fixed this in 13eb19f.

@sanbornm
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome. Does this get triggered on travis build or manually done?

@c4milo
Copy link
Member Author

@c4milo c4milo commented on ad21f3e Sep 14, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually, you commit everything locally, update the version in the Makefile, and make release will create a new tag and update the artifacts to Github releases for you.

Please sign in to comment.