{"id":29892298,"url":"https://github.com/joshdk/buildversion","last_synced_at":"2025-08-01T01:22:43.935Z","repository":{"id":305582780,"uuid":"1013978151","full_name":"joshdk/buildversion","owner":"joshdk","description":"🏗️ Library for determining and overriding the version of a Go application","archived":false,"fork":false,"pushed_at":"2025-07-19T21:02:07.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-21T00:09:20.655Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joshdk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-04T20:03:13.000Z","updated_at":"2025-07-20T23:41:27.000Z","dependencies_parsed_at":"2025-07-21T00:19:33.543Z","dependency_job_id":null,"html_url":"https://github.com/joshdk/buildversion","commit_stats":null,"previous_names":["joshdk/buildversion"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/joshdk/buildversion","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fbuildversion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fbuildversion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fbuildversion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fbuildversion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshdk","download_url":"https://codeload.github.com/joshdk/buildversion/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fbuildversion/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268152946,"owners_count":24204050,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-01T01:22:37.639Z","updated_at":"2025-08-01T01:22:43.921Z","avatar_url":"https://github.com/joshdk.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License][license-badge]][license-link]\n[![Actions][github-actions-badge]][github-actions-link]\n\n# Build Version\n\n🏗️ Library for determining and overriding the version of a Go application\n\n## Motivations\n\nThere are currently a number of ways to distribute a Go application. \nA user could download a prebuilt release binary, or run `go install`, or even clone the repo and `go build`/`go run` the code directly.\n\nInformation such as version strings, git commit SHAs, and timestamps may be available to programs executed in each of these scenarios.\n\nThis library aims to surface this information for inclusion in bug reports, or when displaying help text.\n\n## Usage\n\n### Basic Example\n\nHere is a simple program which templates out the default version, revision, \u0026 timestamp properties.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/joshdk/buildversion\"\n)\n\nfunc main() {\n\ttpl := `{{ .Version }}\n\t{{- if .Revision }} ({{ .Revision }}){{ end }}\n\t{{- if .Timestamp }} built on {{ .Timestamp }}{{ end }}`\n\n\tfmt.Print(buildversion.Template(tpl))\n}\n```\n\nWhen executed with `go install` or `go build` we can observe that the current commit, and the time that commit was originally authored, is printed.\n\n```shell\n$ go install .\n\n$ demo\nv0.0.1-0.20250707135443-82e199f920b9 (82e199f) built on 2025-07-07T13:54:43Z\n```\n\n```shell\n$ go build .\n\n$ ./demo\nv0.0.1-0.20250707135443-82e199f920b9 (82e199f) built on 2025-07-07T13:54:43Z\n```\n\nCommit information is not included when executed via `go run`, so a default version is printed instead.\n\n```shell\n$ go run .\ndevelopment\n```\n\n### Overriding the Version by Using ldflags\n\nThis program can be enhanced to consume build-time provided version, revision, \u0026 timestamp values as custom overrides.\n\n```go\nvar version, revision, timestamp string\n\nfunc main() {\n\ttpl := `{{ .Version }}\n\t{{- if .Revision }} ({{ .Revision }}){{ end }}\n\t{{- if .Timestamp }} built on {{ .Timestamp }}{{ end }}`\n\n\tbuildversion.Override(version, revision, timestamp)\n\t\n\tfmt.Print(buildversion.Template(tpl))\n}\n```\n\nThese values can be provided via `-ldflags`/`-X` (see [https://pkg.go.dev/cmd/link](https://pkg.go.dev/cmd/link)).\n\n```shell\n$ go build -buildvcs=false -ldflags \"-X 'main.version=$(git describe --tags --always)' -X 'main.revision=$(git rev-parse HEAD)' -X 'main.timestamp=$(date -u '+%Y-%m-%dT%H:%M:%SZ')'\" .             \n\n$ ./demo\nv1.2.3 (82e199f) built on 2025-07-19T03:16:33Z\n```\n\n### Templating\n\nThe following properties can be referenced from a Go `text/template` style template body: \n\n| Property               | Description                                                 |\n|------------------------|-------------------------------------------------------------|\n| `{{ .Path }}`          | Go import path of the main package being run                |\n| `{{ .Version }}`       | Package version string                                      |\n| `{{ .Revision }}`      | Current git commit SHA                                      |\n| `{{ .ShortRevision }}` | Current git commit SHA, truncated to the first 7 characters |\n| `{{ .Timestamp }}`     | RFC3339 timestamp of the current git commit                 |\n| `{{ .OS }}`            | Current operating system type (`GOOS`)                      |\n| `{{ .Arch }}`          | Current CPU architecture (`GOARCH`)                         |\n| `{{ .Runtime }}`       | Go runtime version                                          |\n\nThe `{{ .Version }}`, `{{ .Revision }}`/`{{ .ShortRevision }}`, \u0026 `{{ .Timestamp }}` are not guaranteed to contain a value if not explicitly overridden.\n\n## License\n\nThis code is distributed under the [MIT License][license-link], see [LICENSE.txt][license-file] for more information.\n\n[github-actions-badge]:  https://github.com/joshdk/buildversion/workflows/Test/badge.svg\n[github-actions-link]:   https://github.com/joshdk/buildversion/actions\n[license-badge]:         https://img.shields.io/badge/license-MIT-green.svg\n[license-file]:          https://github.com/joshdk/buildversion/blob/master/LICENSE.txt\n[license-link]:          https://opensource.org/licenses/MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshdk%2Fbuildversion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshdk%2Fbuildversion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshdk%2Fbuildversion/lists"}