git-webhook-ci/pkg/watcher/watcher.go

38 lines
690 B
Go
Raw Normal View History

package watcher
import (
"fmt"
"log"
"os"
"os/exec"
)
type WatcherIface interface {
Monitor(path string) error
Listen(binaryPath, scriptPath string, outputErr chan<- error)
Close() error
}
type DeployFunc func(binaryPath, scriptPath string) error
func Deploy(binaryPath, scriptPath string) error {
err := execute(binaryPath, scriptPath)
if err != nil {
return fmt.Errorf("execute: %s", err)
}
log.Println("deploy done")
return nil
}
func execute(binaryPath, scriptPath string) error {
cmd := exec.Command(binaryPath, scriptPath)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("cmd.Run %s", err)
}
return nil
}