Skip to content

Commit

Permalink
add version command and setup github release
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazuki Hasegawa committed Sep 14, 2018
1 parent 701602e commit d161f01
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 36 deletions.
46 changes: 36 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
---

defaults: &defaults
docker:
- image: golang:1.10
working_directory: /go/src/github.com/corrupt952/tmuxist
version: 2
jobs:
test:
docker:
- image: golang:1.10
working_directory: /go/src/github.com/corrupt952/tmuxist
<<: *defaults
steps:
- run: go get -u github.com/golang/dep/cmd/dep
- checkout
Expand All @@ -17,9 +21,7 @@ jobs:
paths:
- "vendor/"
build:
docker:
- image: golang:1.10
working_directory: /go/src/github.com/corrupt952/tmuxist
<<: *defaults
environment:
BUILD_GOOS: darwin
BUILD_GOARCH: amd64
Expand All @@ -31,18 +33,42 @@ jobs:
keys:
- dep-{{ checksum "Gopkg.lock" }}
- dep-
- run: make build
- run: make package
- save_cache:
key: dep-{{ checksum "Gopkg.lock" }}
paths:
- "vendor/"
- persist_to_workspace:
root: .
paths:
- Makefile
- pkg/tmuxist_*
- store_artifacts:
path: pkg
release:
<<: *defaults
steps:
- run: go get -u github.com/tcnksm/ghr
- attach_workspace:
at: .
- run: make release
workflows:
version: 2
test_and_build:
jobs:
- test
- test:
filters:
tags:
only: /.*/
- build:
requires:
- test
requires: [test]
filters:
tags:
only: /.*/
- release:
requires: [build]
filters:
branches:
ignore: /.*/
tags:
only: /^\d+\.\d+\.\d+$/
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
OUTPUT_PATH ?= tmuxist
BUILD_FLAGS ?= -a -v -race
VERSION ?= 0.0.1
LDFLAGS ?= "-X main.version=${VERSION}"

all: build

dep:
dep ensure

build: dep
gox -output="pkg/{{.Dir}}_{{.OS}}_{{.Arch}}" -osarch="darwin/amd64 linux/amd64 linux/386"
gox -ldflags=${LDFLAGS} -output="pkg/{{.OS}}_{{.Arch}}/{{.Dir}}" -osarch="darwin/amd64 linux/amd64 linux/386"

package: build
cd pkg \
&& find * -type d | xargs -I{} tar -zcvf tmuxist_${VERSION}_{}.tar.gz {}/tmuxist \
&& find * -type d | xargs -I{} rm -rf {}

release:
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} pkg


run: dep
go run *.go
Expand All @@ -19,8 +28,8 @@ test: dep
go test .

clean:
rm -f pkg/tmuxist_*
rm -rf pkg/*

vars:
echo ${OUTPUT_PATH}
echo ${BUILD_FLAGS}
echo ${VERSION}
echo ${LDFLAGS}
4 changes: 2 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"os"
"log"
"github.com/hashicorp/logutils"
"log"
"os"
)

// logging
Expand Down
60 changes: 42 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import (
"bytes"
"context"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
Expand All @@ -11,11 +13,13 @@ import (
"strings"
"syscall"
"text/template"
"bytes"
"fmt"

"github.com/pelletier/go-toml"
"github.com/google/subcommands"
"github.com/pelletier/go-toml"
)

var (
version string
)

const (
Expand Down Expand Up @@ -213,6 +217,41 @@ func (cmd *startCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{
return subcommands.ExitSuccess
}

// version commands
type versionCmd struct{}

func (*versionCmd) Name() string {
return "version"
}
func (*versionCmd) Synopsis() string {
return "Print tmuxist version"
}
func (*versionCmd) Usage() string {
return "version: tmuxist version\n"
}
func (*versionCmd) SetFlags(f *flag.FlagSet) {
}
func (*versionCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
fmt.Print(version)
return subcommands.ExitSuccess
}

func main() {
initLogger()

subcommands.Register(subcommands.HelpCommand(), "")
subcommands.Register(subcommands.CommandsCommand(), "")
subcommands.Register(&initCmd{}, "")
subcommands.Register(&editCmd{}, "")
subcommands.Register(&outputCmd{}, "")
subcommands.Register(&startCmd{}, "")
subcommands.Register(&versionCmd{}, "")

flag.Parse()
ctx := context.Background()
os.Exit(int(subcommands.Execute(ctx)))
}

func getConfigurationPath(profile string) (string, error) {
fpath, err := absolutePath(filepath.Join(CONFIG_DIR_PATH, profile+".toml"))
if err != nil {
Expand Down Expand Up @@ -244,18 +283,3 @@ func absolutePath(path string) (string, error) {

return strings.Replace(path, "~", usr.HomeDir, 1), nil
}

func main() {
initLogger()

subcommands.Register(subcommands.HelpCommand(), "")
subcommands.Register(subcommands.CommandsCommand(), "")
subcommands.Register(&initCmd{}, "")
subcommands.Register(&editCmd{}, "")
subcommands.Register(&outputCmd{}, "")
subcommands.Register(&startCmd{}, "")

flag.Parse()
ctx := context.Background()
os.Exit(int(subcommands.Execute(ctx)))
}

0 comments on commit d161f01

Please sign in to comment.