From c80ed2f05dec7080918f4766650c8d821e8a14ff Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 6 Jul 2024 22:25:09 +0200 Subject: Execute build function from craft.sh craft.sh is the script which needs to be located inside the repository root to define how the repository should be used. The first defined function is `build()` which is used to build the repository content. --- main.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 505daf1..383b398 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main // see `man 5 githooks` for details import ( + "bytes" "errors" "fmt" "io" @@ -32,7 +33,9 @@ func main() { } log.Printf("Git ref update: %s\n", update) commit := update.updated - _ = prepareWorkbench(repo, commit) + workbench := prepareWorkbench(repo, commit) + defer os.RemoveAll(workbench) + craft(workbench) } } @@ -48,12 +51,30 @@ func runCommand(dir string, name string, args ...string) { } } +func craft(workbench string) { + script := `#!/bin/sh + +source craft.sh +build +` + + cmd := exec.Command("busybox", "ash") + cmd.Dir = workbench + cmd.Stdin = bytes.NewBufferString(script) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + err := cmd.Run() + if err != nil { + log.Fatal(err) + } +} + func prepareWorkbench(repo string, commit string) string { workbench, err := os.MkdirTemp("", "*-craft") if err != nil { log.Fatal(err) } - defer os.RemoveAll(workbench) runCommand( workbench, -- cgit v1.2.3-70-g09d2