pharosnet / gitcgen

generate a go file contains a git commit id

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Latest Git Commit Id Generator

generate a go file contains a git commit id.

It is good to generate a go file in a go http server project, that the http server can publish a url to show it's version.

Install

Using go get

go get github.com/pharosnet/gitcgen@v1.2.0

Using download

Usage

Commands

Name short Name Desc
show s show latest git commit id
gen g generate a go file contains latest git commit id

show command args:

Name Short Name Value Desc
work_tree w string the path of git project

gen command args:

Name Short Name Value Desc
work_tree w string the path of git project
output o string the file path of generated go file, such as "./foo/bar.go"
short s bool use short git commit id. default is true.

Examples:

Show latest git commit id

gitcgen show -w="{TARGET_GIT_PROJECT_LOCAL_PATH}"

Generate a go file

gitcgen gen -w="{TARGET_GIT_PROJECT_LOCAL_PATH}" -o="./foo/bar.go"

Using in go generate

//go:generate gitcgen gen -w="./" -o="./versions/git_latest_commit_id.go"
func main() {
    // ...
}

Advance

Using it in CI / CD.

About

generate a go file contains a git commit id

License:MIT License


Languages

Language:Go 100.0%