Replace embedded version getter with Go build info for version#5790
Replace embedded version getter with Go build info for version#5790maruel wants to merge 1 commit into
Conversation
internal/core/versiongetter/main.go: The versiongetter utility used
go-git to retrieve the version from the repository tags at compilation
time. Replace versiongetter with Go's debug.ReadBuildInfo() (added in
go1.12), which provides version and VCS metadata from the binary itself.
scripts/binaries.mk: use variables to shell out less often. Switch from
using ./VERSION to using the git tag. This is likely the most tricky
part of this change.
scripts/dockerhub.mk already uses `git describe --tags | tr -d v` as the
version. So this does help make both docker version and tarballs
versioning more coherent.
Here's the outcomes:
| Scenario | Returns | Source |
|---|---|---|
| `go install @latest` | `v1.18.2` | `info.Main.Version` |
| `go build` in tagged repo (at tag) | `v1.18.2` | `info.Main.Version` |
| `go build` in tagged repo (past tag) | `v1.18.3-0.TIMESTAMP-HASH` | `info.Main.Version` |
| `go build` in untagged repo (fork) | `v0.0.0-TIMESTAMP-HASH` | `info.Main.Version` (Go pseudo-version) |
| `go build -buildvcs=false` | `devel` | fallback when no VCS settings |
| stripped/broken binary | `unknown` | `debug.ReadBuildInfo()` returned false |
Behavior change:
The local go install automatically bump the version for modified local
changes:
```
go install . && mediamtx --version
v1.18.3-0.20260520142345-762ae87b5f75
```
Ran:
make format lint binaries
make test
make test-32
Both make test and make test-32 "passed" but both printed "/bin/sh: git: not found" at the beginning.
Binaries are in the form mediamtx_v1.18.2-7-gdea66680_linux_armv6.tar.gz
since I have local changes.
Potential follow ups:
- make binaries ask for root access. One idea would be to mount the
container with the right user ID so the chown is not necessary.
- I didn't touch internal/upgrade/upgrade.go, so go-git is still a
dependency.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5790 +/- ##
==========================================
+ Coverage 62.83% 62.86% +0.03%
==========================================
Files 219 219
Lines 18659 18677 +18
==========================================
+ Hits 11725 11742 +17
- Misses 5973 5974 +1
Partials 961 961 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hello, the first implementation of the version retrieval system was based on |
|
By reviewing this patch i noticed that |
Can you clarify what you mean by go install becoming necessary?
|
internal/core/versiongetter/main.go: This utility used go-git to retrieve the version from the repository tags at go generate. Replace it with Go's debug.ReadBuildInfo() (added in go1.12), which provides version and VCS metadata from the binary itself.
scripts/binaries.mk: use variables to shell out less often. Switch from using ./VERSION to using the git tag. This is likely the most tricky part of this change.
scripts/dockerhub.mk already uses
git describe --tags | tr -d vas the version. So this does help make both docker version and tarballs versioning more coherent. Note that it's different from what scripts/binaries.mk used. I didn't change the command in script/binaries.mk.Behavior change:
The local go install automatically bumps the version for build with modified local
changes:
Previously:
Ran:
Both make test and make test-32 "passed" but both printed "/bin/sh: git: not found" at the beginning. Binaries are in the form mediamtx_v1.18.2-7-gdea66680_linux_armv6.tar.gz since I have local changes. This naming comes from
git describe --tags.Potential follow ups: