Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ COPY . /thoom/gulp
WORKDIR /thoom/gulp
RUN apk add --update --no-cache git ca-certificates
RUN go get -d ./...
RUN CGO_ENABLED=0 go build -ldflags "-X github.com/thoom/gulp/client.buildVersion=$BUILD_VERSION-buildkit" -o gulp
RUN CGO_ENABLED=0 go build -ldflags "-X github.com/thoom/gulp/client.buildVersion=$BUILD_VERSION" -o gulp
RUN touch /tmp/hosts

FROM scratch
Expand Down
9 changes: 7 additions & 2 deletions client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"fmt"
"runtime"
"strings"
"time"
)
Expand Down Expand Up @@ -40,7 +41,7 @@ func BuildHeaders(reqHeaders []string, configHeaders map[string]string, includeJ
headers := make(map[string]string)

// Set the default User-Agent and Accept type
headers["USER-AGENT"] = fmt.Sprintf("thoom.Gulp/%s", GetVersion())
headers["USER-AGENT"] = CreateUserAgent()
headers["ACCEPT"] = "application/json;q=1.0, */*;q=0.8"

if includeJSON {
Expand All @@ -66,9 +67,13 @@ func BuildHeaders(reqHeaders []string, configHeaders map[string]string, includeJ
// GetVersion builds the version from the build branch
func GetVersion() string {
version := buildVersion
if version == "" {
if version == "" || version == "snapshot" {
version = defaultVersion
}

return version
}

func CreateUserAgent() string {
return fmt.Sprintf("thoom.Gulp/%s (%s %s)", GetVersion(), strings.Title(runtime.GOOS), strings.ToUpper(runtime.GOARCH))
}
18 changes: 17 additions & 1 deletion client/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package client

import (
"fmt"
"runtime"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -14,7 +16,7 @@ func TestBuildHeadersBase(t *testing.T) {
assert.Equal(3, len(headers))

assert.Contains(headers, "USER-AGENT")
assert.Equal("thoom.Gulp/"+GetVersion(), headers["USER-AGENT"])
assert.Equal(CreateUserAgent(), headers["USER-AGENT"])

assert.Contains(headers, "ACCEPT")
assert.Equal("application/json;q=1.0, */*;q=0.8", headers["ACCEPT"])
Expand Down Expand Up @@ -111,9 +113,23 @@ func TestGetVersion(t *testing.T) {
assert.Equal(defaultVersion, GetVersion())
}

func TestGetVersionSnapshot(t *testing.T) {
assert := assert.New(t)

buildVersion = "snapshot"
assert.Equal(defaultVersion, GetVersion())
}

func TestGetVersionEnv(t *testing.T) {
assert := assert.New(t)

buildVersion = "TestVersion"
assert.Equal("TestVersion", GetVersion())
}

func TestCreateUserAgent(t *testing.T) {
assert := assert.New(t)

expected := fmt.Sprintf("thoom.Gulp/%s (%s %s)", GetVersion(), strings.Title(runtime.GOOS), strings.ToUpper(runtime.GOARCH))
assert.Equal(expected, CreateUserAgent())
}
4 changes: 2 additions & 2 deletions output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ func (bo *BuffOut) PrintErr(txt string, err error) {
// PrintVersion will output the current version and colophon
func (bo *BuffOut) PrintVersion(version string) {
bo.PrintBlock(fmt.Sprintf(`thoom.Gulp
gulp version: %s
gulp version: %s-%s-%s
go version: %s
author: Z.d.Peacock <zdp@thoomtech.com>
link: https://github.com/thoom/gulp`, version, runtime.Version()))
link: https://github.com/thoom/gulp`, version, strings.Title(runtime.GOOS), strings.ToUpper(runtime.GOARCH), runtime.Version()))

fmt.Fprintln(bo.Out, "")
}
Expand Down
10 changes: 5 additions & 5 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env GOOS=linux GOARCH=386 go build -ldflags "-X github.com/thoom/gulp/client.buildVersion=$RELEASE_VERSION-linux386" -o gulp && tar cfz gulp.linux-386.tar.gz gulp
env GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/thoom/gulp/client.buildVersion=$RELEASE_VERSION-linux64" -o gulp && tar cfz gulp.linux-amd64.tar.gz gulp
env GOOS=darwin GOARCH=amd64 go build -ldflags "-X github.com/thoom/gulp/client.buildVersion=$RELEASE_VERSION-darwin-amd64" -o gulp && tar cfz gulp.darwin-amd64.tar.gz gulp
env GOOS=darwin GOARCH=arm64 go build -ldflags "-X github.com/thoom/gulp/client.buildVersion=$RELEASE_VERSION-darwin-arm64" -o gulp && tar cfz gulp.darwin-arm64.tar.gz gulp
env GOOS=windows GOARCH=amd64 go build -ldflags "-X github.com/thoom/gulp/client.buildVersion=$RELEASE_VERSION-windows" -o gulp && zip gulp.windows.zip gulp
env GOOS=linux GOARCH=386 go build -ldflags "-X github.com/thoom/gulp/client.buildVersion=$RELEASE_VERSION" -o gulp && tar cfz gulp.linux-386.tar.gz gulp
env GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/thoom/gulp/client.buildVersion=$RELEASE_VERSION" -o gulp && tar cfz gulp.linux-amd64.tar.gz gulp
env GOOS=darwin GOARCH=amd64 go build -ldflags "-X github.com/thoom/gulp/client.buildVersion=$RELEASE_VERSION" -o gulp && tar cfz gulp.darwin-amd64.tar.gz gulp
env GOOS=darwin GOARCH=arm64 go build -ldflags "-X github.com/thoom/gulp/client.buildVersion=$RELEASE_VERSION" -o gulp && tar cfz gulp.darwin-arm64.tar.gz gulp
env GOOS=windows GOARCH=amd64 go build -ldflags "-X github.com/thoom/gulp/client.buildVersion=$RELEASE_VERSION" -o gulp && zip gulp.windows.zip gulp