修复配置默认值未应用,输出到文件[D]

This commit is contained in:
LollipopKit 2022-06-02 12:14:32 +08:00
parent b955ce7f20
commit 4f92b82b14

29
main.go
View File

@ -23,6 +23,7 @@ const (
var (
configs = []Config{}
configsLock = &sync.RWMutex{}
logFile *os.File
)
func init() {
@ -30,7 +31,9 @@ func init() {
for {
os.Mkdir(logDir, perm)
file := ".log/" + time.Now().Format("2006-01-02") + ".txt"
logFile, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, perm)
var err error
logFile, err = os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, perm)
if err != nil {
panic(err)
}
@ -77,36 +80,34 @@ func main() {
return
}
log.Printf("Received: [Name] %s [Sender] %s", payload.Repository.FullName, payload.Sender.FullName)
log.Printf("\nReceived: [Name] %s [Sender] %s", payload.Repository.FullName, payload.Sender.FullName)
// 寻找配置
for _, commit := range payload.Commits {
var path string
var script string
var signal string
c := Config{}
for _, config := range configs {
if config.Repo == payload.Repository.FullName {
path = config.Path
script = config.Script
signal = config.Signal
c.Path = config.Path
c.Script = config.Script
c.Signal = config.Signal
break
}
}
// 包含部署信号
if strings.Contains(commit.Message, signal) {
log.Printf("Commit: [SHA] %s [Message] %s\n", commit.ID, commit.Message)
if strings.Contains(commit.Message, c.Signal) {
log.Printf("Commit: [SHA] %s [Message] %s", commit.ID, commit.Message)
log.Println("Ready to deploy")
projectPath := fmt.Sprintf(path+"/%s/", payload.Repository.Name)
scriptPath := projectPath + script
projectPath := fmt.Sprintf(c.Path+"/%s/", payload.Repository.Name)
scriptPath := projectPath + c.Script
log.Printf("Running script: %s\n", scriptPath)
// 开始执行脚本
cmd := exec.Command(scriptPath)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdout = logFile
cmd.Stderr = logFile
cmd.Dir = projectPath
err = cmd.Run()
if err != nil {