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

44 lines
796 B
Go
Raw Normal View History

package watcher
import (
"fmt"
"log"
"os"
"os/exec"
2023-02-26 16:59:20 +01:00
"github.com/fsnotify/fsnotify"
)
2023-02-26 16:59:20 +01:00
type NotifyIface interface {
NewWatcher() (*fsnotify.Watcher, error)
}
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
}