-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from datawire/ark3/version-number
Add tag-based version numbers to all the commands
- Loading branch information
Showing
17 changed files
with
166 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
* | ||
!image | ||
!intercept | ||
!entrypoint.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"crypto/md5" | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
var Verbose bool | ||
|
||
func die(err error, args ...interface{}) { | ||
if err != nil { | ||
if args != nil { | ||
panic(fmt.Errorf("%v: %v", err, args)) | ||
} else { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
func main() { | ||
fmt.Printf("%x\n", hash()) | ||
} | ||
|
||
func hash() []byte { | ||
standard, err := shell("git ls-files --exclude-standard") | ||
die(err) | ||
others, err := shell("git ls-files --exclude-standard --others") | ||
die(err) | ||
|
||
files := append(standard, others...) | ||
|
||
h := md5.New() | ||
for _, file := range files { | ||
if strings.TrimSpace(file) == "" { | ||
continue | ||
} | ||
if Verbose { | ||
fmt.Printf("hashing %s\n", file) | ||
} | ||
h.Write([]byte(file)) | ||
info, err := os.Lstat(file) | ||
if err != nil { | ||
h.Write([]byte("error")) | ||
h.Write([]byte(err.Error())) | ||
} else { | ||
if info.Mode()&os.ModeSymlink != 0 { | ||
target, err := os.Readlink(file) | ||
die(err) | ||
h.Write([]byte("link")) | ||
h.Write([]byte(target)) | ||
} else if !info.IsDir() { | ||
h.Write([]byte("file")) | ||
f, err := os.Open(file) | ||
die(err, file) | ||
_, err = io.Copy(h, f) | ||
f.Close() | ||
die(err) | ||
} | ||
} | ||
} | ||
|
||
return h.Sum(nil) | ||
} | ||
|
||
func shell(command string) ([]string, error) { | ||
cmd := exec.Command("sh", "-c", command) | ||
out, err := cmd.CombinedOutput() | ||
str := string(out) | ||
lines := strings.Split(str, "\n") | ||
return lines, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2018 Datawire. All rights reserved. | ||
# | ||
# Makefile snippet for automatically setting VERSION. | ||
# | ||
## Inputs ## | ||
# (none) | ||
## Outputs ## | ||
# - Variable: VERSION | ||
ifeq ($(words $(filter $(abspath $(lastword $(MAKEFILE_LIST))),$(abspath $(MAKEFILE_LIST)))),1) | ||
_version.mk := $(lastword $(MAKEFILE_LIST)) | ||
|
||
VERSION ?= $(patsubst v%,%,$(shell git describe --tags --always))$(if $(shell git status -s),-dirty$(_version.dirty_hash)) | ||
|
||
_version.dirty_hash = $(shell GO111MODULE=off go run $(dir $(_version.mk))version.go) | ||
|
||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var version = &cobra.Command{ | ||
Use: "version", | ||
Short: "Show the program's version number", | ||
Run: showVersion, | ||
} | ||
|
||
func init() { | ||
apictl_key.AddCommand(version) | ||
} | ||
|
||
func showVersion(cmd *cobra.Command, args []string) { | ||
fmt.Println(Version) | ||
} |
Oops, something went wrong.