Do you really need the branch? You get the commit hash for free since Go 
1.18 : https://tip.golang.org/doc/go1.18#go-version
You can see the embedded version information with: go version -m 
<executable_file>

On Monday, 6 February 2023 at 17:33:53 UTC burker...@gmail.com wrote:

> You can use go:generate and go:embed to achieve this. In our CI/CD 
> pipeline we generate a json file with a lot of information like vcs, 
> branch, tag, date and time, hash and a lot more. Then we embed this json 
> into the binary.
>
> I became aware of this technique from 
>
> https://levelup.gitconnected.com/a-better-way-than-ldflags-to-add-a-build-version-to-your-go-binaries-2258ce419d2d?gi=c2bc81346d42
> .
>
> Hope this helps.
>
> quin...@gmail.com <quin...@gmail.com> schrieb am Mo. 6. Feb. 2023 um 
> 16:48:
>
>>
>> Hi,
>>
>> I would like to be able to extract the VCS branch name used during build.
>> Currently I append "-X main.BranchName=${BRANCH}" to the build line which 
>> works, but I was hoping there might be a cunning way to extract this from 
>> runtime/debug?
>>
>> Thanks,
>>
>> -Steve
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/6f0a10e1-f818-4b98-8384-3fe925ec69dcn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/6f0a10e1-f818-4b98-8384-3fe925ec69dcn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/eb634451-e374-4db9-99c9-fb0f557eff7dn%40googlegroups.com.

Reply via email to