version

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2016 License: Apache-2.0 Imports: 2 Imported by: 12

README

version

version is a Go library for automatic build versioning. It attempts to simplify the mundane task of adding build version information to any Go package.

Usage

Install the command line utility to generate the linker flags necessary for versioning from the cmd/linkflags:

go install github.com/gravitational/version/cmd/linkflags

Add the following configuration to your build script / Makefile (assuming a bash script):

GO_LDFLAGS=$(linkflags -pkg=path/to/your/package)

# build with the linker flags:
go build -ldflags="${GO_LDFLAGS}"

To use, simply import the package and either obtain the version with Get or print the JSON-formatted version with Print:

package main

import "github.com/gravitational/version"

func main() {
	version.Print()
}

If you have a custom vendoring solution, you might have this package stored under a different path than the default (go get). In this case, you can override the default with a command line option (using godep as a vendoring solution):

MY_PACKAGE=github.com/my/package
MY_PACKAGE_PATH=$(pwd)
GO_LDFLAGS=$(linkflags -pkg=${MY_PACKAGE_PATH} -verpkg=${MY_PACKAGE}/Godeps/_workspace/src/github.com/gravitational/version)

The version part of the version information requires that you properly tag your packages:

$ git tag
v1.0.0-alpha.1
v1.0.0-beta.1

The build versioning scheme is a slight modification of the scheme from the Kubernetes project. It consists of three parts:

  • a version string in semver format
  • git commit ID
  • git tree state (clean or dirty)
type Info struct {
	Version      string `json:"version"`
	GitCommit    string `json:"gitCommit"`
	GitTreeState string `json:"gitTreeState"`
}

Documentation

Overview

Copyright 2015 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2015 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package version supplies version information collected at build time.

Copyright 2015 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(baseVersion string)

Init sets an alternative default for the version string.

func Print

func Print()

Print prints build version in default format.

Types

type Info

type Info struct {
	Version      string `json:"version"`
	GitCommit    string `json:"gitCommit"`
	GitTreeState string `json:"gitTreeState"`
}

Info describes build version with a semver-complaint version string and git-related commit/tree state details.

func Get

func Get() Info

Get returns current build version.

func (Info) String

func (r Info) String() string

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL