Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #56 from itskingori/updates
Browse files Browse the repository at this point in the history
Command and build process updates
  • Loading branch information
itskingori committed May 19, 2018
2 parents 9a58a8a + 61e55bc commit 46bdea2
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Expand Up @@ -14,5 +14,5 @@
vendor/

# Built artefact
/binaries/
sanaa
/bin/
/sanaa
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -5,10 +5,10 @@ go:
- "1.10.x"
before_install:
- curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
- make install
- make dependencies
script: make test
before_deploy:
- ./scripts/compile.sh ${TRAVIS_TAG}
- ./scripts/compile.sh ${TRAVIS_TAG} ${TRAVIS_COMMIT}
deploy:
- provider: releases
api_key:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog

## 0.8.0

* Configure commands to not accept arguments i.e. `server`, `worker` and
`version`.
* Improve `version` command to include build SHA.

## 0.7.0

* Remove explicit region configuration, no need for `--s3-region` flag since
Expand Down
25 changes: 22 additions & 3 deletions Makefile
@@ -1,6 +1,22 @@
SHELL := /bin/bash

dependencies:
VERSION := $(version)
MAJOR_VERSION := $(shell echo $(VERSION) | cut -d'.' -f1)
MINOR_VERSION := $(shell echo $(VERSION) | cut -d'.' -f2)
PATCH_VERSION := $(shell echo $(VERSION) | cut -d'.' -f3)
COMMIT_VERSION := $(shell git rev-parse HEAD)
PACKAGE_PATH := github.com/itskingori/sanaa
LDFLAGS := \
-X $(PACKAGE_PATH)/service.majorVersion=$(MAJOR_VERSION) \
-X $(PACKAGE_PATH)/service.minorVersion=$(MINOR_VERSION) \
-X $(PACKAGE_PATH)/service.patchVersion=$(PATCH_VERSION) \
-X $(PACKAGE_PATH)/service.commitVersion=$(COMMIT_VERSION)

.PHONY: all tools dependencies build lint test

all: dependencies build

tools:
# install golint
go get -u github.com/golang/lint/golint

Expand All @@ -13,11 +29,14 @@ dependencies:
# install all known linters:
gometalinter --install

install:
dependencies:
dep ensure

build:
go build
@mkdir -p bin/
go build -ldflags="$(LDFLAGS)" -o ./bin/sanaa
@echo
@./bin/sanaa version

lint:
gometalinter --config="linters.json" ./...
Expand Down
4 changes: 3 additions & 1 deletion cmd/server.go
Expand Up @@ -31,7 +31,9 @@ var serverCmd = &cobra.Command{
Short: "Start the application web server",
Long: `Start the application web server listening on the configured binding address and port.`,
Args: func(cmd *cobra.Command, args []string) error {
err := validateRequestTTL(cmd)
err := cobra.NoArgs(cmd, args)

err = validateRequestTTL(cmd)
if err != nil {

return err
Expand Down
10 changes: 9 additions & 1 deletion cmd/version.go
Expand Up @@ -27,10 +27,18 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Print out the version of the software",
Long: "Print out the version of the software.",
Args: func(cmd *cobra.Command, args []string) error {
err := cobra.NoArgs(cmd, args)

return err
},
Run: func(cmd *cobra.Command, args []string) {
version := service.GetVersion()

fmt.Printf("Sanaa v%s\n", version.Str())
fmt.Printf("Name: %s\n", "Sanaa")
fmt.Printf("Command: %s\n", "sanaa")
fmt.Printf("Version: %s\n", version.Str())
fmt.Printf("Commit: %s\n", version.Commit)
},
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/worker.go
Expand Up @@ -31,7 +31,9 @@ var workerCmd = &cobra.Command{
Short: "Start the application background worker",
Long: `Start the application background worker to process enqeueud jobs.`,
Args: func(cmd *cobra.Command, args []string) error {
err := validateConcurrency(cmd)
err := cobra.NoArgs(cmd, args)

err = validateConcurrency(cmd)
if err != nil {

return err
Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Expand Up @@ -345,11 +345,11 @@ here][milestones]).
### Building

1. Fetch the code with `go get -v github.com/itskingori/sanaa`.
2. Install the Go development tools via `make dependencies`.
3. Install application dependencies via `make install` (they'll be placed in
2. Install the Go development tools via `make tools`.
3. Install application dependencies via `make dependencies` (they'll be placed in
`./vendor`). Requires [golang/dep][dep] package manager.
4. Build and install the binary with `make build`.
5. Run the command e.g. `./sanaa help` as a basic test.
5. Run the command e.g. `./bin/sanaa help` as a basic test.

### Testing

Expand Down
6 changes: 4 additions & 2 deletions scripts/compile.sh
Expand Up @@ -3,11 +3,12 @@
set -eu

version="$1"
commit_version="$2"
major_version="$(echo "${version}" | cut -d'.' -f1)"
minor_version="$(echo "${version}" | cut -d'.' -f2)"
patch_version="$(echo "${version}" | cut -d'.' -f3)"

binary_output_path="binaries"
binary_output_path="bin"
package_path="github.com/itskingori/sanaa"
target_platforms=(
'darwin/amd64'
Expand All @@ -16,7 +17,8 @@ target_platforms=(

ldflags="-X ${package_path}/service.majorVersion=${major_version} \
-X ${package_path}/service.minorVersion=${minor_version} \
-X ${package_path}/service.patchVersion=${patch_version}"
-X ${package_path}/service.patchVersion=${patch_version} \
-X ${package_path}/service.commitVersion=${commit_version}"

echo -e "Installing gox, Go's cross compilation tool"
go get -v github.com/mitchellh/gox
Expand Down
21 changes: 12 additions & 9 deletions service/version.go
Expand Up @@ -16,24 +16,27 @@
package service

var (
majorVersion = "0"
minorVersion = "0"
patchVersion = "0"
majorVersion string
minorVersion string
patchVersion string
commitVersion string
)

// Version represents version information.
type Version struct {
Major string
Minor string
Patch string
Major string
Minor string
Patch string
Commit string
}

// GetVersion returns version information.
func GetVersion() Version {
return Version{
Major: majorVersion,
Minor: minorVersion,
Patch: patchVersion,
Major: majorVersion,
Minor: minorVersion,
Patch: patchVersion,
Commit: commitVersion,
}
}

Expand Down
30 changes: 0 additions & 30 deletions service/version_test.go

This file was deleted.

0 comments on commit 46bdea2

Please sign in to comment.