0
点赞
收藏
分享

微信扫一扫

15.Go程序版本信息(二)

梯梯笔记 2022-01-26 阅读 58

Go程序版本信息(二)

一、参考资料

  1. Golang项目中Makefile编写

二、优化

上篇中已经成功将版本信息添加到go项目的程序中,但是每此操作比较麻烦,可以使用脚本进行代替

三、shell脚本

  • release.sh

    # !/bin/bash
    ## Author: JonathanJiang
    ## Description: build for release, package all output
    
    p_version="1.0.3"
    p_date=`TZ=Asia/Shanghai date +%FT%T%z`
    p_branch=`git rev-parse --abbrev-ref HEAD`
    p_commit=`git rev-parse --short HEAD`
    p_tag=`git describe --tags --abbrev=0`
    
    version_folder="gitee.com/Jonathan_Jiang/simple_app/version"
    ldflags="-X '${version_folder}.version=${p_version}' -X '${version_folder}.built=${p_date}' -X '${version_folder}.git_commit=${p_commit}'"
    
    go build -ldflags "${ldflags}"
    echo "build success..."
    
  • 使用

    jonathanjiang@linux:simple_app$ sh release.sh 
    build success...
    jonathanjiang@linux:simple_app$ ./simple_app version
    Version:         1.0.3 
    Built:           2022-01-26T17:19:52+0800 
    Platform:        linux/amd64 
    GoVersion:       go1.17.2 
    GitCommit:       fd6c498 
    

四、MakeFile脚本

举报

相关推荐

0 条评论