3 Commits

Author SHA1 Message Date
f6e4e64e81 feat: update logs 2024-05-25 06:47:21 +02:00
eaf0b1ff69 fix: change args by slice 2024-05-25 06:31:37 +02:00
9c735ccf64 fix: allow just binary execution 2024-05-24 22:25:36 +02:00
2 changed files with 9 additions and 6 deletions

View File

@@ -12,9 +12,9 @@ type Config struct {
Projects map[string][]ConfigScript `yaml:"projects"`
}
type ConfigScript struct {
Environment string `yaml:"environment"`
BinaryPath string `yaml:"binary"`
ScriptPath string `yaml:"script"`
Environment string `yaml:"environment"`
Command string `yaml:"command"`
Arguments []string `yaml:"args"`
}
func LoadConfig(path string) (*Config, error) {

View File

@@ -28,6 +28,7 @@ func main() {
log.Fatalf("Error loading config: %v", err)
}
http.HandleFunc("/", handlePayload(cfg.Secret, cfg.Projects))
log.Printf("server is up on %d\n", cfg.Port)
http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), nil)
}
@@ -56,6 +57,7 @@ func handlePayload(secret string, projects map[string][]config.ConfigScript) fun
proj, found := projects[project]
if !found {
http.Error(w, "not found", http.StatusNotFound)
log.Printf("project %s not found\n", project)
return
}
var payload internal.WebhookPayload
@@ -76,19 +78,20 @@ func handlePayload(secret string, projects map[string][]config.ConfigScript) fun
}
if !found {
http.Error(w, "not found", http.StatusNotFound)
log.Printf("project %s with branch %s not found\n", project, branchName)
return
}
go func() {
if err := execute(scr.BinaryPath, scr.ScriptPath); err != nil {
if err := execute(scr.Command, scr.Arguments...); err != nil {
log.Println(err)
}
}()
})
}
func execute(binaryPath, scriptPath string) error {
cmd := exec.Command(binaryPath, scriptPath)
func execute(command string, args ...string) error {
cmd := exec.Command(command, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr