diff --git a/.circleci/config.yml b/.circleci/config.yml index 2034cb4..282bee0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -33,8 +33,37 @@ jobs: name: Run tests command: ginkgo -race -r + release: + <<: *docker_golang + working_directory: /go/src/github.com/gocardless/pgreplay-go + steps: + - checkout + - run: + name: Release + command: | + CURRENT_VERSION="v$(cat VERSION)" + + if [[ $(git tag -l "${CURRENT_VERSION}") == "${CURRENT_VERSION}" ]]; then + echo "Version ${CURRENT_VERSION} is already released" + exit 0 + fi + + curl -L -o /tmp/goreleaser_Linux_x86_64.tar.gz https://github.com/goreleaser/goreleaser/releases/download/v0.101.0/goreleaser_Linux_x86_64.tar.gz + tar zxf /tmp/goreleaser_Linux_x86_64.tar.gz -C /tmp + + git log --pretty=oneline --abbrev-commit --no-decorate --no-color "$(git describe --tags --abbrev=0)..HEAD" -- pkg cmd vendor internal > /tmp/release-notes + git tag "${CURRENT_VERSION}" + git push --tags + + /tmp/goreleaser --rm-dist --release-notes /tmp/release-notes + workflows: version: 2 build-integration: jobs: - unit-integration + - release: + requires: + - unit-integration + filters: + branches: {only: master} diff --git a/.gitignore b/.gitignore index e660fd9..a5d8f72 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ bin/ +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..6b5d110 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,44 @@ +# View goreleaser docs for configuration settings +# https://goreleaser.com + +--- +project_name: pgreplay + +builds: + - binary: pgreplay + main: cmd/pgreplay/main.go + goos: + - darwin + - linux + goarch: + - amd64 + ldflags: > + -X github.com/gocardless/pgreplay/cmd/main.Version={{.Version}} + -X github.com/gocardless/pgreplay/cmd/main.Commit={{.Commit}} + -X github.com/gocardless/pgreplay/cmd/main.Date={{.Date}} + -a + -installsuffix cgo + env: + - CGO_ENABLED=0 + +nfpm: + name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + vendor: GoCardless + homepage: https://github.com/gocardless/pgreplay-go + maintainer: GoCardless Engineering + description: &description PostgreSQL load testing tool + formats: + - deb + +brew: + github: + owner: gocardless + name: homebrew-taps + commit_author: + name: GoCardless Engineering + email: engineering@gocardless.com + folder: Formula + homepage: https://github.com/gocardless/pgreplay-go + description: *description + test: system "#{bin}/pgreplay version" + install: bin.install "pgreplay" diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/cmd/pgreplay/main.go b/cmd/pgreplay/main.go index 1e95b3b..fbf1e89 100644 --- a/cmd/pgreplay/main.go +++ b/cmd/pgreplay/main.go @@ -6,6 +6,7 @@ import ( stdlog "log" "net/http" "os" + "runtime" "time" "github.com/alecthomas/kingpin" @@ -19,10 +20,9 @@ import ( ) var logger kitlog.Logger -var Version string // assigned during build var ( - app = kingpin.New("pgreplay", "Replay Postgres logs against database").Version(Version) + app = kingpin.New("pgreplay", "Replay Postgres logs against database").Version(versionStanza()) // Global flags applying to every command debug = app.Flag("debug", "Enable debug logging").Default("false").Bool() @@ -185,6 +185,22 @@ func main() { } } +// Set by goreleaser +var ( + Version = "dev" + Commit = "none" + Date = "unknown" + GoVersion = runtime.Version() + VersionStanza string +) + +func versionStanza() string { + return fmt.Sprintf( + "pgreplay Version: %v\nGit SHA: %v\nGo Version: %v\nGo OS/Arch: %v/%v\nBuilt at: %v", + Version, Commit, GoVersion, runtime.GOOS, runtime.GOARCH, Date, + ) +} + func checkSingleFormat(formats ...*string) (result *string) { var supplied = 0 for _, format := range formats {