diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 38 |
1 files changed, 15 insertions, 23 deletions
@@ -12,6 +12,10 @@ import ( "time" ) +const ( + workbench = `build` +) + var ( key = "" repo = "" @@ -52,15 +56,13 @@ func main() { waitBoot() - workbench := prepareWorkbench(repo, commit) - defer os.RemoveAll(workbench) - craft(workbench) + checkoutSources(repo, commit) + craft() } -func runCommand(dir string, name string, args ...string) { - log.Printf("%s %s\n", name, strings.Join(args, " ")) - command := exec.Command(name, args...) - command.Dir = dir +func runCommand(name string, args ...string) { + log.Printf("Remote execution: %s %s\n", name, strings.Join(args, " ")) + command := sshCommand(name, args...) command.Stderr = os.Stderr command.Stdout = os.Stdout err := command.Run() @@ -130,14 +132,14 @@ func waitBoot() { log.Fatalf("Could not reach VM %d times - giving up", retries) } -func craft(workbench string) { +func craft() { script := fmt.Sprintf(`#!/bin/sh +cd %s %s -`, task) +`, workbench, task) - cmd := exec.Command("sh") - cmd.Dir = workbench + cmd := sshCommand("sh") cmd.Stdin = bytes.NewBufferString(script) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr @@ -148,14 +150,8 @@ func craft(workbench string) { } } -func prepareWorkbench(repo string, commit string) string { - workbench, err := os.MkdirTemp("", "*-craft") - if err != nil { - log.Fatal(err) - } - +func checkoutSources(repo string, commit string) string { runCommand( - workbench, "git", "clone", repo, @@ -163,7 +159,6 @@ func prepareWorkbench(repo string, commit string) string { ) runCommand( - workbench, "git", "--git-dir", filepath.Join(workbench, ".git"), @@ -174,11 +169,8 @@ func prepareWorkbench(repo string, commit string) string { ) runCommand( - workbench, "git", - "--git-dir", - filepath.Join(workbench, ".git"), - "--work-tree", + "-C", workbench, "submodule", "update", |