🚧 发布项目:获取 Git 版本号

This commit is contained in:
徐晓伟 2023-11-22 14:06:41 +08:00
parent 5e9fb77aef
commit 05ed527a3e
3 changed files with 31 additions and 0 deletions

21
api/git.go Normal file
View File

@ -0,0 +1,21 @@
package api
import (
"fmt"
"log"
"os/exec"
)
// GitVersion 获取 Git 版本号
func GitVersion() (string, error) {
cmd := exec.Command("git1", "--version")
output, err := cmd.Output()
if err != nil {
log.Fatal("无法获取 Git 版本号")
return "", err
}
version := string(output)
fmt.Println("Git 版本:", version)
return version, nil
}

View File

@ -11,6 +11,11 @@ func PreReleaseCommand() *cli.Command {
Name: "pre-release",
Usage: "预发布",
Flags: flag.CommonFlag(),
Before: func(context *cli.Context) error {
_, err := api.GitVersion()
return err
},
Subcommands: []*cli.Command{
{
Name: "gitee",

View File

@ -11,6 +11,11 @@ func ReleaseCommand() *cli.Command {
Name: "release",
Usage: "发布",
Flags: flag.CommonFlag(),
Before: func(context *cli.Context) error {
_, err := api.GitVersion()
return err
},
Subcommands: []*cli.Command{
{
Name: "gitee",