diff --git a/pkgs/oizys/cmd/ci.go b/pkgs/oizys/cmd/ci.go index 94870ab..8da5364 100644 --- a/pkgs/oizys/cmd/ci.go +++ b/pkgs/oizys/cmd/ci.go @@ -1,8 +1,10 @@ package cmd import ( - "oizys/internal/oizys" + "oizys/internal/github" + "os" + "github.com/charmbracelet/log" "github.com/spf13/cobra" ) @@ -12,11 +14,28 @@ var ciCmd = &cobra.Command{ Use: "ci", Short: "offload build to GHA", Run: func(cmd *cobra.Command, args []string) { - oizys.CI(args...) + inputs := make(map[string]interface{}) + if includeLock { + log.Debug("including lock file in inputs") + inputs["lockFile"] = readLockFile() + } + github.CreateDispatch("build.yml", ref, inputs) }, } +var includeLock bool +var ref string + func init() { rootCmd.AddCommand(ciCmd) - + ciCmd.Flags().BoolVar(&includeLock, "lockfile", false, "include lock file in inputs") + ciCmd.Flags().StringVar(&ref, "ref", "main", "git ref to trigger workflow on") +} + +func readLockFile() string { + dat, err := os.ReadFile("flake.lock") + if err != nil { + log.Fatal("failed to read flake.lock", "err", err) + } + return string(dat) } diff --git a/pkgs/oizys/internal/github/main.go b/pkgs/oizys/internal/github/main.go index 008ad5d..0e67cc7 100644 --- a/pkgs/oizys/internal/github/main.go +++ b/pkgs/oizys/internal/github/main.go @@ -152,3 +152,27 @@ func ReadMarkdownFromZip(zipData []byte, fileName string) (string, error) { // Return the markdown content as string return string(content), nil } + +// func CI(rest ...string) { +// args := []string{ +// "workflow", "run", "build.yml", +// "-F", fmt.Sprintf("hosts=%s", o.host), +// } +// args = append(args, rest...) +// cmd := exec.Command("gh", args...) +// e.ExitWithCommand(cmd) +// } + +func CreateDispatch(workflowFileName string, ref string, inputs map[string]interface{}) { + event := github.CreateWorkflowDispatchEventRequest{Ref: ref, Inputs: inputs} + _, err := client.Actions.CreateWorkflowDispatchEventByFileName( + context.Background(), + "daylinmorgan", + "oizys", + workflowFileName, + event, + ) + if err != nil { + log.Fatal("failed to dispatch event", "filename", workflowFileName, "err", err) + } +} diff --git a/pkgs/oizys/internal/oizys/main.go b/pkgs/oizys/internal/oizys/main.go index a9d3347..2e29c6f 100644 --- a/pkgs/oizys/internal/oizys/main.go +++ b/pkgs/oizys/internal/oizys/main.go @@ -6,6 +6,7 @@ import ( "fmt" "io/fs" "oizys/internal/git" + // "oizys/internal/github" "oizys/internal/ui" "os" "os/exec" @@ -316,16 +317,6 @@ func CacheBuild(rest ...string) { e.ExitWithCommand(cmd) } -func CI(rest ...string) { - args := []string{ - "workflow", "run", "build.yml", - "-F", fmt.Sprintf("hosts=%s", o.host), - } - args = append(args, rest...) - cmd := exec.Command("gh", args...) - e.ExitWithCommand(cmd) -} - func UpdateRepo() { log.Info("rebasing HEAD on origin/flake-lock") o.repo.Fetch()