https://github.com/aletheia7/gogitver
Go package that embeds a git tag/version string in your application
https://github.com/aletheia7/gogitver
git go golang mage magefile make makefile semver version
Last synced: 4 months ago
JSON representation
Go package that embeds a git tag/version string in your application
- Host: GitHub
- URL: https://github.com/aletheia7/gogitver
- Owner: aletheia7
- License: bsd-2-clause
- Created: 2014-09-17T08:26:07.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-11-20T01:25:32.000Z (over 5 years ago)
- Last Synced: 2024-06-19T13:47:12.374Z (12 months ago)
- Topics: git, go, golang, mage, magefile, make, makefile, semver, version
- Language: Go
- Size: 33.2 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://godoc.org/github.com/aletheia7/gogitver)
#### gogitver and [mage (go make)](https://github.com/magefile/mage)
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:
```bash
git tag -a# View the git tag:
git describe --tags --long# Instead of "go install" execute:
mage
```#### Install and [mage](https://github.com/magefile/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.```bash
# 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:
```bash
git tag -a 1.0.7
```
Run mage:
```bash
mage
```#### gogitver and [GNUMake](https://www.gnu.org/software/make/manual/make.html)
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:
```bash
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](https://www.gnu.org/software/make/manual/make.html)
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.```bash
# 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:
```bash
git tag -a 1.0.7
```
Run make:
```bash
make
```[GNUMake](https://www.gnu.org/software/make/manual/make.html)
Software Version Guidelines: [Semantic Versioning](http://semver.org)
Compare & parse semver version strings: [godoc go-semver](http://godoc.org/code.google.com/p/go-semver/version), [code: go-semver](https://code.google.com/p/go-semver/)
#### Example```go
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
```bash
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.[](https://opensource.org/)