-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (49 loc) · 1.04 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"autodeploy/common"
"github.com/joho/godotenv"
log "github.com/sirupsen/logrus"
"os"
"os/exec"
"time"
)
func main() {
godotenv.Load(".env")
f, err := os.OpenFile("autodeploy.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer f.Close()
log.SetOutput(f)
ticker := time.NewTicker(5 * time.Second)
for {
select {
case <-ticker.C:
commit, err := common.GetCommit()
if err != nil {
log.Errorln(err)
return
}
// get id from .id file
data, err := os.ReadFile(".id")
if err != nil {
log.Errorln(err)
return
}
if string(data) != commit.ID {
bashFilePath := os.Getenv("BashFilePath")
err = os.Chmod(bashFilePath, 0777)
if err != nil {
log.Errorln(err)
return
}
_, err := exec.Command("bash", bashFilePath).Output()
if err != nil {
log.Errorln(err)
}
common.SendMessage(common.GetTextMessage(commit), "chat232")
err = os.WriteFile(".id", []byte(commit.ID), 0644)
}
}
}
}