123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package main
- import (
- "bytes"
- "encoding/json"
- "fmt"
- "os"
- "os/exec"
- "strconv"
- )
- func main() {
- versionFile := "version"
- b, err := os.ReadFile(versionFile)
- if err != nil {
- file, err := os.OpenFile(versionFile, os.O_RDWR|os.O_CREATE, 0777)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer file.Close()
- file.WriteString("v1.0.0")
- cmd := exec.Command("git", "add", versionFile)
- err = cmd.Run()
- if err != nil {
- fmt.Println(err)
- }
- return
- }
- fmt.Println("old version", string(b))
- file, err := os.OpenFile("version", os.O_RDWR|os.O_TRUNC, 0777)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer file.Close()
- bs := bytes.Split(b, []byte{'.'})
- lb := bs[len(bs)-1]
- i, err := strconv.Atoi(string(lb))
- if err != nil {
- fmt.Println(err)
- return
- }
- bs[len(bs)-1] = []byte(fmt.Sprintf("%d", i+1))
- tb := bytes.Join(bs, []byte{'.'})
- fmt.Println("new version", string(tb))
- file.Write(tb)
- cmd := exec.Command("git", "add", versionFile)
- err = cmd.Run()
- if err != nil {
- fmt.Println(err)
- }
- // Windows编译版本文件
- winVersionFile := "./versioninfo.json"
- _, err = os.Stat(winVersionFile)
- if err != nil {
- return
- }
- winB, err := os.ReadFile(winVersionFile)
- if err != nil {
- fmt.Println("open ", winVersionFile, "error: ", err)
- return
- }
- fmt.Println("xxxxxxxxxx", len(winB))
- var winV windowsVersion
- err = json.Unmarshal(winB, &winV)
- if err != nil {
- fmt.Println("invalid format of Windows version info: xxxx", err, string(winB))
- }
- winV.StringFileInfo.ProductVersion = string(tb)
- file1, _ := os.OpenFile(winVersionFile, os.O_RDWR|os.O_TRUNC, 0777)
- defer file1.Close()
- vb, _ := json.MarshalIndent(winV, "", " ")
- _, err = file1.Write(vb)
- if err != nil {
- fmt.Println("write new windows version error: ", err)
- return
- }
- cmd2 := exec.Command("git", "add", winVersionFile)
- err = cmd2.Run()
- if err != nil {
- fmt.Println(err)
- return
- }
- }
- type windowsVersion struct {
- FixedFileInfo struct {
- FileVersion struct {
- Major int
- Minor int
- Patch int
- Build int
- }
- ProductVersion struct {
- Major int
- Minor int
- Patch int
- Build int
- }
- FileFlagsMask string
- FileFlags string
- FileOS string
- FileType string
- FileSubType string
- }
- StringFileInfo struct {
- Comments string
- CompanyName string
- FileDescription string
- FileVersion string
- InternalName string
- LegalCopyright string
- LegalTrademarks string
- OriginalFilename string
- PrivateBuild string
- ProductName string
- ProductVersion string
- SpecialBuild string
- }
- VarFileInfo struct {
- Translation struct {
- LangID string
- CharsetID string
- }
- }
- IconPath string
- ManifestPath string
- }
|