Skip to content

Commit

Permalink
Implement version command (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
tburko authored Apr 1, 2021
1 parent 293fb8e commit 1a81425
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:

build_and_publish:
runs-on: ubuntu-latest
env:
version: v0.1.${{ github.run_number }}
steps:
- uses: actions/checkout@v2

Expand All @@ -22,16 +24,16 @@ jobs:
run: make test

- name: Build Klaabu for Linux
run: make GOOS=linux GOARCH=amd64 build
run: make GOOS=linux GOARCH=amd64 VERSION=${{ env.version }} build

- name: Build Klaabu for MacOS
run: make GOOS=darwin GOARCH=amd64 build
run: make GOOS=darwin GOARCH=amd64 VERSION=${{ env.version }} build

- name: Publish the Klaabu binary
uses: softprops/action-gh-release@v1
if: github.ref == 'refs/heads/master'
with:
tag_name: v0.1.${{ github.run_number }}
tag_name: ${{ env.version }}
files: |
./build/bin/klaabu-linux-amd64
./build/bin/klaabu-darwin-amd64
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ NAME := klaabu

BUILD := ${CURDIR}/build
BIN := ${BUILD}/bin
VERSION := dev

.PHONY: clean tidy compile shasum test run
.DEFAULT_GOAL := build
Expand All @@ -21,10 +22,10 @@ vendor:
compile:
ifdef GOOS
ifdef GOARCH
go build -mod=readonly -o ${BIN}/${NAME}-$(GOOS)-$(GOARCH) cli/*.go
go build -mod=readonly -ldflags="-X 'main.Version=$${VERSION}'" -o ${BIN}/${NAME}-$(GOOS)-$(GOARCH) cli/*.go
endif
else
go build -mod=readonly -o ${BIN}/${NAME} cli/*.go
go build -mod=readonly -ldflags="-X 'main.Version=$${VERSION}'" -o ${BIN}/${NAME} cli/*.go
endif

shasum:
Expand Down
1 change: 1 addition & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var commands = map[string]func(){
"init": initCommand,
"space": spaceCommand,
"validate": validateCommand,
"version": versionCommand,
}

func helpCommand(c string) {
Expand Down
27 changes: 27 additions & 0 deletions cli/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"flag"
"log"
"os"
)

var Version string

func versionCommand() {
commandName := "version"
flagSet := flag.NewFlagSet(commandName, flag.ExitOnError)
flagSet.Parse(os.Args[2:])

if len(os.Args) != 2 {
log.Printf("Usage: klaabu %s\n", flagSet.Name())
flagSet.PrintDefaults()
os.Exit(1)
}

if Version != "" {
log.Println(Version)
} else {
log.Println("development")
}
}

0 comments on commit 1a81425

Please sign in to comment.