add ldflags for branch to gothub update

このコミットが含まれているのは:
Arya Kiran 2023-04-30 21:58:47 +05:30
コミット 6a30308d82
この署名に対応する既知のキーがデータベースに存在しません
GPGキーID: 842D12BDA50DF120
1個のファイルの変更6行の追加2行の削除

ファイルの表示

@ -3,6 +3,7 @@ package gothub
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -30,6 +31,9 @@ func update() {
os.Exit(1) os.Exit(1)
} }
gitPull := exec.Command("git", "pull") gitPull := exec.Command("git", "pull")
curBranch := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
curBranchOut, _ := curBranch.CombinedOutput()
ldFlags := "-X codeberg.org/gothub/gothub/utils.Branch=" + strings.Replace(string(curBranchOut), "\n", "", -1)
var out bytes.Buffer var out bytes.Buffer
gitPull.Stdout = &out gitPull.Stdout = &out
err := gitPull.Run() err := gitPull.Run()
@ -42,7 +46,7 @@ func update() {
os.Exit(1) os.Exit(1)
} }
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
err := exec.Command("go", "build", "-o", "gothub.exe").Run() err := exec.Command("go", "build", "-o", "gothub.exe", ldFlags).Run()
if err != nil { if err != nil {
fmt.Println("Couldn't build GotHub.", err) fmt.Println("Couldn't build GotHub.", err)
os.Exit(1) os.Exit(1)
@ -51,7 +55,7 @@ func update() {
os.Exit(0) os.Exit(0)
} }
} else { } else {
err := exec.Command("go", "build").Run() err := exec.Command("go", "build", "-ldflags", ldFlags).Run()
if err != nil { if err != nil {
fmt.Println("Couldn't build GotHub.", err) fmt.Println("Couldn't build GotHub.", err)
os.Exit(1) os.Exit(1)