adding goreleaser

This commit is contained in:
Alex Goodman 2018-10-16 22:56:35 -04:00
parent dddb2e6b97
commit 9802546b60
No known key found for this signature in database
GPG key ID: 05328C611D8A520E
7 changed files with 125 additions and 49 deletions

26
.goreleaser.yml Normal file
View file

@ -0,0 +1,26 @@
release:
prerelease: true
builds:
- binary: dive
goos:
- darwin
- linux
goarch:
- amd64
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.buildTime={{.Date}}`.
archive:
format: tar.gz
fpm:
license: MIT
homepage: https://github.com/wagoodman/dive/
formats:
- deb
- rpm
brew:
github:
owner: wagoodman
name: homebrew-dive

37
.scripts/tag.sh Executable file
View file

@ -0,0 +1,37 @@
#!/bin/bash
set -u
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
echo "${BOLD}Tagging${NORMAL}"
#get highest tag number
VERSION=`git describe --abbrev=0 --tags`
#replace . with space so can split into an array
VERSION_BITS=(${VERSION//./ })
#get number parts and increase last one by 1
VNUM1=${VERSION_BITS[0]}
VNUM2=${VERSION_BITS[1]}
VNUM3=${VERSION_BITS[2]}
VNUM3=$((VNUM3+1))
#create new tag
NEW_TAG="$VNUM1.$VNUM2.$VNUM3"
echo "Updating $VERSION to $NEW_TAG"
#get current hash and see if it already has a tag
GIT_COMMIT=`git rev-parse HEAD`
NEEDS_TAG=`git describe --contains $GIT_COMMIT`
#only tag if no tag already (would be better if the git describe command above could have a silent option)
if [ -z "$NEEDS_TAG" ]; then
echo "Tagged with $NEW_TAG (Ignoring fatal:cannot describe - this means commit is untagged) "
git tag $NEW_TAG
git push --tags
else
echo "Already a tag on this commit"
fi

View file

@ -9,6 +9,10 @@ run: build
build:
go build -o build/$(BIN)
release: test
./.scripts/tag.sh
goreleaser --rm-dist
install:
go install ./...
@ -23,4 +27,4 @@ clean:
rm -rf vendor
go clean
.PHONY: build install test lint clean
.PHONY: build install test lint clean release

View file

@ -6,6 +6,7 @@ A tool for interrogating docker images.
## Installing
```
docker build -t die-test:latest .

View file

@ -0,0 +1,50 @@
package filetree
// TODO: rewrite this to be weighted by file size
// func TestEfficencyMap(t *testing.T) {
// trees := make([]*FileTree, 3)
// for ix, _ := range trees {
// tree := NewFileTree()
// tree.AddPath("/etc/nginx/nginx.conf", FileInfo{})
// tree.AddPath("/etc/nginx/public", FileInfo{})
// trees[ix] = tree
// }
// var expectedMap = map[string]int{
// "/etc/nginx/nginx.conf": 3,
// "/etc/nginx/public": 3,
// }
// actualMap := EfficiencyMap(trees)
// if !reflect.DeepEqual(expectedMap, actualMap) {
// t.Fatalf("Expected %v but go %v", expectedMap, actualMap)
// }
// }
//
// func TestEfficiencyScore(t *testing.T) {
// trees := make([]*FileTree, 3)
// for ix, _ := range trees {
// tree := NewFileTree()
// tree.AddPath("/etc/nginx/nginx.conf", FileInfo{})
// tree.AddPath("/etc/nginx/public", FileInfo{})
// trees[ix] = tree
// }
// expected := 2.0 / 6.0
// actual := CalculateEfficiency(trees)
// if math.Abs(expected-actual) > 0.0001 {
// t.Fatalf("Expected %f but got %f", expected, actual)
// }
//
// trees = make([]*FileTree, 1)
// for ix, _ := range trees {
// tree := NewFileTree()
// tree.AddPath("/etc/nginx/nginx.conf", FileInfo{})
// tree.AddPath("/etc/nginx/public", FileInfo{})
// trees[ix] = tree
// }
// expected = 1.0
// actual = CalculateEfficiency(trees)
// if math.Abs(expected-actual) > 0.0001 {
// t.Fatalf("Expected %f but got %f", expected, actual)
// }
// }

View file

@ -2,8 +2,6 @@ package filetree
import (
"fmt"
"math"
"reflect"
"testing"
)
@ -526,49 +524,3 @@ func TestRemoveOnIterate(t *testing.T) {
}
}
func TestEfficencyMap(t *testing.T) {
trees := make([]*FileTree, 3)
for ix, _ := range trees {
tree := NewFileTree()
tree.AddPath("/etc/nginx/nginx.conf", FileInfo{})
tree.AddPath("/etc/nginx/public", FileInfo{})
trees[ix] = tree
}
var expectedMap = map[string]int{
"/etc/nginx/nginx.conf": 3,
"/etc/nginx/public": 3,
}
actualMap := EfficiencyMap(trees)
if !reflect.DeepEqual(expectedMap, actualMap) {
t.Fatalf("Expected %v but go %v", expectedMap, actualMap)
}
}
func TestEfficiencyScore(t *testing.T) {
trees := make([]*FileTree, 3)
for ix, _ := range trees {
tree := NewFileTree()
tree.AddPath("/etc/nginx/nginx.conf", FileInfo{})
tree.AddPath("/etc/nginx/public", FileInfo{})
trees[ix] = tree
}
expected := 2.0 / 6.0
actual := CalculateEfficiency(trees)
if math.Abs(expected-actual) > 0.0001 {
t.Fatalf("Expected %f but got %f", expected, actual)
}
trees = make([]*FileTree, 1)
for ix, _ := range trees {
tree := NewFileTree()
tree.AddPath("/etc/nginx/nginx.conf", FileInfo{})
tree.AddPath("/etc/nginx/public", FileInfo{})
trees[ix] = tree
}
expected = 1.0
actual = CalculateEfficiency(trees)
if math.Abs(expected-actual) > 0.0001 {
t.Fatalf("Expected %f but got %f", expected, actual)
}
}

View file

@ -24,6 +24,12 @@ import (
"github.com/wagoodman/dive/cmd"
)
var (
version = "No version provided"
commit = "No commit provided"
buildTime = "No build timestamp provided"
)
func main() {
cmd.Execute()
}