summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-07-06 22:25:09 +0200
committerxengineering <me@xengineering.eu>2024-07-06 22:25:09 +0200
commitc80ed2f05dec7080918f4766650c8d821e8a14ff (patch)
tree49433033236ac02777c6894a066c6516a62f185d
parent489cc1fa91bb5c8b6ca84e53443ff3d772937b53 (diff)
downloadcraft-c80ed2f05dec7080918f4766650c8d821e8a14ff.tar
craft-c80ed2f05dec7080918f4766650c8d821e8a14ff.tar.zst
craft-c80ed2f05dec7080918f4766650c8d821e8a14ff.zip
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.
-rw-r--r--main.go25
1 files 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,