gogitver

package module
v0.0.0-...-bd480a5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2019 License: BSD-2-Clause Imports: 1 Imported by: 0

README

gogitver and mage (go make)

A go package that inserts a git tag into your binary. Uses mage to efficiently compile your go application when the git tag changes. Other source code changes will still trigger a compile. The git version/tag is created beforehand with:

git tag -a

# View the git tag: 
git describe --tags --long

# Instead of "go install" execute:
mage

Install and mage

gogitver must be installed as a package under your application main directory. E.g. if your application resides under ~/go/src/app, gogitver must be installed under ~/go/src/app/gogitver. ~/go/src/app/vendor/gogitver is preferred.

# Example
mkdir ~/go/src/app/vendor/gogitver
cd ~/go/src/app
git clone --depth 1 https://github.com/aletheia7/gogitver.git vendor/gogitver
rm -fr vendor/gogitver/.git
# link mage_gogitver.go 
ln -s vendor/gogitver/mage_gogitver.go .
Add a mg.Dep(Gogitver) to your main magefile.go that should reside under ~/go/src/app .

Create a git tag:

git tag -a 1.0.7

Run mage:

mage

gogitver and GNUMake

A go package that inserts a git tag into your binary. Uses make to efficiently compile your go application when the git tag changes. Other source code changes will still trigger a compile. The git version/tag is created beforehand with:

git tag -a

# View the git tag: 
git describe --tags --long

# Instead of "go install" execute:
make
# Run "go install" and strip to remove debug symbols:
make strip
# Instead of "go clean" execute:
make clean

Install and GNUMake

gogitver must be installed as a package under your application main directory. E.g. if your application resides under ~/go/src/app, gogitver must be installed under ~/go/src/app/gogitver. ~/go/src/app/vendor/gogitver is preferred.

# Example
mkdir ~/go/src/app/vendor/gogitver
cd ~/go/src/app
git clone --depth 1 https://github.com/aletheia7/gogitver.git vendor/gogitver
rm -fr vendor/gogitver/.git
# link makefile
ln -s vendor/gogitver/makefile .

Create a git tag:

git tag -a 1.0.7

Run make:

make

GNUMake

Software Version Guidelines: Semantic Versioning

Compare & parse semver version strings: godoc go-semver, code: go-semver

Example

package main
import (
	"fmt"
	// Do not use "github.com/alethiea7/gogitver"
	// It will not work
	"app/gogitver"
)

func main() {

	fmt.Println(gogitver.Git())	
	fmt.Println(gogitver.Tag())
}

Ouput

1.0.7-0-g8e9e07b
1.0.7

License

Use of this source code is governed by a BSD-2-Clause license that can be found in the LICENSE file.

BSD-2-Clause License

Documentation

Overview

Package gogitver embeds a git tag into your application

Available make targets:

make
make strip
make clean

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Git

func Git() string

Git returns a "git describe --tags --long"

Example: 1.0.2-0-g641e39f

Example
package main

import (
	"fmt"
	"gogitver"
)

func main() {
	fmt.Println("git:", gogitver.Git())
	// git: 1.0.2-0-g641e39f
}
Output:

func Tag

func Tag() string

Tag returns a git tag

Tag is the left hand side of 1.0.2-α-0-g1234567 Example: 1.0.2-α

Example
package main

import (
	"fmt"
	"gogitver"
)

func main() {
	fmt.Println("tag:", gogitver.Tag())
	// tag: 1.0.2
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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