-
-
Notifications
You must be signed in to change notification settings - Fork 83
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 #7 from ricoberger/prepare-next-release
Prepare next release
- Loading branch information
Showing
6 changed files
with
150 additions
and
72 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,45 +1,78 @@ | ||
WHAT := script_exporter | ||
BUILDTIME := $(shell date +%FT%T%Z) | ||
VERSION=`git describe --tags` | ||
COMMIT=`git rev-parse HEAD` | ||
BUILDUSER := $(shell id -un) | ||
WHAT := curltest script_exporter | ||
|
||
.PHONY: build build-darwin-amd64 build-linux-amd64 build-windows-amd64 release | ||
PROJECT ?= script_exporter | ||
REPO ?= github.com/ricoberger/script_exporter | ||
PWD ?= $(shell pwd) | ||
VERSION ?= $(shell git describe --tags) | ||
REVISION ?= $(shell git rev-parse HEAD) | ||
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) | ||
BUILDUSER ?= $(shell id -un) | ||
BUILDTIME ?= $(shell date '+%Y%m%d-%H:%M:%S') | ||
|
||
.PHONY: build build-darwin-amd64 build-linux-amd64 build-windows-amd64 clean release release-major release-minor release-patch | ||
|
||
build: | ||
for target in $(WHAT); do \ | ||
go build -ldflags "-X github.com/ricoberger/script_exporter/pkg/version.GitCommit=${COMMIT} \ | ||
-X github.com/ricoberger/script_exporter/pkg/version.Version=${VERSION} \ | ||
-X github.com/ricoberger/script_exporter/pkg/version.BuildTime=${BUILDTIME} \ | ||
-X github.com/ricoberger/script_exporter/pkg/version.BuildUser=${BUILDUSER}" \ | ||
go build -ldflags "-X ${REPO}/pkg/version.Version=${VERSION} \ | ||
-X ${REPO}/pkg/version.Revision=${REVISION} \ | ||
-X ${REPO}/pkg/version.Branch=${BRANCH} \ | ||
-X ${REPO}/pkg/version.BuildUser=${BUILDUSER} \ | ||
-X ${REPO}/pkg/version.BuildDate=${BUILDTIME}" \ | ||
-o ./bin/$$target ./cmd/$$target; \ | ||
done | ||
|
||
build-darwin-amd64: | ||
for target in $(WHAT); do \ | ||
CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -a -installsuffix cgo -ldflags "-X github.com/ricoberger/script_exporter/pkg/version.GitCommit=${COMMIT} \ | ||
-X github.com/ricoberger/script_exporter/pkg/version.Version=${VERSION} \ | ||
-X github.com/ricoberger/script_exporter/pkg/version.BuildTime=${BUILDTIME} \ | ||
-X github.com/ricoberger/script_exporter/pkg/version.BuildUser=${BUILDUSER}" \ | ||
CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -a -installsuffix cgo -ldflags "-X ${REPO}/pkg/version.Version=${VERSION} \ | ||
-X ${REPO}/pkg/version.Revision=${REVISION} \ | ||
-X ${REPO}/pkg/version.Branch=${BRANCH} \ | ||
-X ${REPO}/pkg/version.BuildUser=${BUILDUSER} \ | ||
-X ${REPO}/pkg/version.BuildDate=${BUILDTIME}" \ | ||
-o ./bin/$$target-${VERSION}-darwin-amd64 ./cmd/$$target; \ | ||
done | ||
|
||
build-linux-amd64: | ||
for target in $(WHAT); do \ | ||
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -installsuffix cgo -ldflags "-X github.com/ricoberger/script_exporter/pkg/version.GitCommit=${COMMIT} \ | ||
-X github.com/ricoberger/script_exporter/pkg/version.Version=${VERSION} \ | ||
-X github.com/ricoberger/script_exporter/pkg/version.BuildTime=${BUILDTIME} \ | ||
-X github.com/ricoberger/script_exporter/pkg/version.BuildUser=${BUILDUSER}" \ | ||
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -installsuffix cgo -ldflags "-X ${REPO}/pkg/version.Version=${VERSION} \ | ||
-X ${REPO}/pkg/version.Revision=${REVISION} \ | ||
-X ${REPO}/pkg/version.Branch=${BRANCH} \ | ||
-X ${REPO}/pkg/version.BuildUser=${BUILDUSER} \ | ||
-X ${REPO}/pkg/version.BuildDate=${BUILDTIME}" \ | ||
-o ./bin/$$target-${VERSION}-linux-amd64 ./cmd/$$target; \ | ||
done | ||
|
||
build-windows-amd64: | ||
for target in $(WHAT); do \ | ||
CGO_ENABLED=0 GOARCH=amd64 GOOS=windows go build -a -installsuffix cgo -ldflags "-X github.com/ricoberger/script_exporter/pkg/version.GitCommit=${COMMIT} \ | ||
-X github.com/ricoberger/script_exporter/pkg/version.Version=${VERSION} \ | ||
-X github.com/ricoberger/script_exporter/pkg/version.BuildTime=${BUILDTIME} \ | ||
-X github.com/ricoberger/script_exporter/pkg/version.BuildUser=${BUILDUSER}" \ | ||
CGO_ENABLED=0 GOARCH=amd64 GOOS=windows go build -a -installsuffix cgo -ldflags "-X ${REPO}/pkg/version.Version=${VERSION} \ | ||
-X ${REPO}/pkg/version.Revision=${REVISION} \ | ||
-X ${REPO}/pkg/version.Branch=${BRANCH} \ | ||
-X ${REPO}/pkg/version.BuildUser=${BUILDUSER} \ | ||
-X ${REPO}/pkg/version.BuildDate=${BUILDTIME}" \ | ||
-o ./bin/$$target-${VERSION}-windows-amd64.exe ./cmd/$$target; \ | ||
done | ||
|
||
release: build-darwin-amd64 build-linux-amd64 build-windows-amd64 | ||
clean: | ||
rm -rf ./bin | ||
|
||
release: clean build-darwin-amd64 build-linux-amd64 build-windows-amd64 | ||
|
||
release-major: | ||
$(eval MAJORVERSION=$(shell git describe --tags --abbrev=0 | sed s/v// | awk -F. '{print "v"$$1+1".0.0"}')) | ||
git checkout master | ||
git pull | ||
git tag -a $(MAJORVERSION) -m 'release $(MAJORVERSION)' | ||
git push origin --tags | ||
|
||
release-minor: | ||
$(eval MINORVERSION=$(shell git describe --tags --abbrev=0 | sed s/v// | awk -F. '{print "v"$$1"."$$2+1".0"}')) | ||
git checkout master | ||
git pull | ||
git tag -a $(MINORVERSION) -m 'release $(MINORVERSION)' | ||
git push origin --tags | ||
|
||
release-patch: | ||
$(eval PATCHVERSION=$(shell git describe --tags --abbrev=0 | sed s/v// | awk -F. '{print "v"$$1"."$$2"."$$3+1}')) | ||
git checkout master | ||
git pull | ||
git tag -a $(PATCHVERSION) -m 'release $(PATCHVERSION)' | ||
git push origin --tags |
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,25 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) != 2 { | ||
os.Exit(1) | ||
} | ||
|
||
t := os.Args[1] | ||
res, err := http.Get(t) | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
|
||
defer res.Body.Close() | ||
|
||
fmt.Printf("# HELP curl_status_code returns the status code of the target\n") | ||
fmt.Printf("# TYPE curl_status_code gauge\n") | ||
fmt.Printf("curl_status_code{target=\"%s\"} %d\n", t, res.StatusCode) | ||
} |
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 |
---|---|---|
@@ -1,25 +1,60 @@ | ||
package version | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"runtime" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
// Build information. Populated at build-time. | ||
var ( | ||
// Version contains the version which is defined in the MAKEFILE | ||
Version string | ||
Version string | ||
Revision string | ||
Branch string | ||
BuildUser string | ||
BuildDate string | ||
GoVersion = runtime.Version() | ||
) | ||
|
||
// BuildTime is the time when the binaries where build | ||
BuildTime string | ||
// versionInfoTmpl contains the template used by Print. | ||
var versionInfoTmpl = ` | ||
{{.program}}, version {{.version}} (branch: {{.branch}}, revision: {{.revision}}) | ||
build user: {{.buildUser}} | ||
build date: {{.buildDate}} | ||
go version: {{.goVersion}} | ||
` | ||
|
||
// BuildUser is the name of the user which build the binaries | ||
BuildUser string | ||
// Print returns version information. | ||
func Print(program string) (string, error) { | ||
m := map[string]string{ | ||
"program": program, | ||
"version": Version, | ||
"revision": Revision, | ||
"branch": Branch, | ||
"buildUser": BuildUser, | ||
"buildDate": BuildDate, | ||
"goVersion": GoVersion, | ||
} | ||
t, err := template.New("version").Parse(versionInfoTmpl) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// GitCommit is the git commit on which the binaries where build | ||
GitCommit string | ||
var buf bytes.Buffer | ||
if err := t.ExecuteTemplate(&buf, "version", m); err != nil { | ||
return "", err | ||
} | ||
return strings.TrimSpace(buf.String()), nil | ||
} | ||
|
||
// GoVersion is the version of go with which the program was build | ||
GoVersion = runtime.Version() | ||
// Info returns version, branch and revision information. | ||
func Info() string { | ||
return fmt.Sprintf("(version=%s, branch=%s, revision=%s)", Version, Branch, Revision) | ||
} | ||
|
||
// Author hold author information | ||
Author = "Rico Berger <mail@ricoberger.de>" | ||
) | ||
// BuildContext returns goVersion, buildUser and buildDate information. | ||
func BuildContext() string { | ||
return fmt.Sprintf("(go=%s, user=%s, date=%s)", GoVersion, BuildUser, BuildDate) | ||
} |