github.com/ronaksoft/rony@v0.16.26-0.20230807065236-1743dbfe6959/internal/codegen/update_version.go (about)

     1  //go:build ignore
     2  // +build ignore
     3  
     4  package main
     5  
     6  import (
     7  	"os"
     8  	"os/exec"
     9  	"strings"
    10  	"text/template"
    11  	"time"
    12  )
    13  
    14  /*
    15     Creation Time: 2019 - Nov - 30
    16     Created by:  (ehsan)
    17     Maintainers:
    18        1.  Ehsan N. Moosa (E2)
    19     Auditor: Ehsan N. Moosa (E2)
    20     Copyright Ronak Software Group 2018
    21  */
    22  
    23  func main() {
    24  	f, err := os.Create("version.go")
    25  	if err != nil {
    26  		panic(err)
    27  	}
    28  	defer f.Close()
    29  
    30  	var riverVer, gitVer string
    31  	b, err := exec.Command("git", "--no-pager", "describe", "--abbrev=0").Output()
    32  	riverVer = strings.TrimSpace(string(b))
    33  	b, err = exec.Command("git", "--no-pager", "log", "--format=\"%H\"", "-n", "1").Output()
    34  	gitVer = strings.TrimSpace(string(b))
    35  
    36  	packageTemplate.Execute(f, struct {
    37  		Timestamp     time.Time
    38  		GitCommit     string
    39  		GitVersionTag string
    40  	}{
    41  		Timestamp:     time.Now(),
    42  		GitCommit:     gitVer,
    43  		GitVersionTag: riverVer,
    44  	})
    45  }
    46  
    47  var packageTemplate = template.Must(template.New("").Parse(`
    48  package codegen
    49  
    50  // This is auto-generated code; DO NOT EDIT.
    51  
    52  var (
    53  	Commit = {{ .GitCommit }}
    54  	Version = "{{ .GitVersionTag }}"
    55  )
    56  `))