From c58213dfb5ecb95f7d7033a0cc111398244738c0 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Fri, 24 May 2024 11:50:18 -0500 Subject: [PATCH] add ci command to oizys-cli --- pkgs/oizys/oizys-go/cmd/ci.go | 20 ++++++++++++++++++++ pkgs/oizys/oizys-go/cmd/root.go | 3 ++- pkgs/oizys/oizys-go/default.nix | 16 +++++++++++++--- pkgs/oizys/oizys-go/pkg/oizys.go | 30 ++++++++++++++++++------------ 4 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 pkgs/oizys/oizys-go/cmd/ci.go diff --git a/pkgs/oizys/oizys-go/cmd/ci.go b/pkgs/oizys/oizys-go/cmd/ci.go new file mode 100644 index 0000000..968f88f --- /dev/null +++ b/pkgs/oizys/oizys-go/cmd/ci.go @@ -0,0 +1,20 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) +// gh workflow run build.yml -F lockFile=@flake.lock + +var ciCmd= &cobra.Command{ + Use: "ci", + Short: "offload build to GHA", + Run: func(cmd *cobra.Command, args []string) { + oizys.CI(args...) + }, +} + + +func init() { + rootCmd.AddCommand(ciCmd) + +} diff --git a/pkgs/oizys/oizys-go/cmd/root.go b/pkgs/oizys/oizys-go/cmd/root.go index 059130e..c23615a 100644 --- a/pkgs/oizys/oizys-go/cmd/root.go +++ b/pkgs/oizys/oizys-go/cmd/root.go @@ -3,9 +3,10 @@ package cmd import ( "os" + o "oizys/pkg" + cc "github.com/ivanpirog/coloredcobra" "github.com/spf13/cobra" - o "oizys/pkg" ) func Execute() { diff --git a/pkgs/oizys/oizys-go/default.nix b/pkgs/oizys/oizys-go/default.nix index fa3d00b..8363f56 100644 --- a/pkgs/oizys/oizys-go/default.nix +++ b/pkgs/oizys/oizys-go/default.nix @@ -1,7 +1,9 @@ { + lib, installShellFiles, buildGoModule, - lib, + makeWrapper, + gh, ... }: buildGoModule { @@ -11,10 +13,18 @@ buildGoModule { src = lib.cleanSource ./.; vendorHash = "sha256-NCHU491j6fRfSk6LA9tS9yiuT/gZhPic46mNTVf1Jeg="; - nativeBuildInputs = [ installShellFiles ]; + nativeBuildInputs = [ + installShellFiles + makeWrapper + ]; postInstall = '' installShellCompletion --cmd oizys \ - --zsh <($out/bin/oizys completion zsh) + --zsh <(OIZYS_SKIP_CHECK=true $out/bin/oizys completion zsh) + ''; + + postFixup = '' + wrapProgram $out/bin/oizys \ + --prefix PATH ${lib.makeBinPath [ gh ]} ''; } diff --git a/pkgs/oizys/oizys-go/pkg/oizys.go b/pkgs/oizys/oizys-go/pkg/oizys.go index 6d81218..f9f0694 100644 --- a/pkgs/oizys/oizys-go/pkg/oizys.go +++ b/pkgs/oizys/oizys-go/pkg/oizys.go @@ -8,12 +8,11 @@ import ( "os" "os/exec" "strings" + "time" "github.com/muesli/termenv" "golang.org/x/term" - "time" - "github.com/briandowns/spinner" ) @@ -52,7 +51,7 @@ func (o *Oizys) Output() string { ) } -func (o *Oizys) Set ( +func (o *Oizys) Set( flake, host, cache string, verbose bool, ) { @@ -118,7 +117,7 @@ func ellipsis(s string, maxLen int) string { func (p *packages) show(verbose bool) { p.summary() - if !verbose || (len(p.names) == 0) { + if !verbose || (len(p.names) == 0) { return } @@ -159,7 +158,6 @@ func showFailedOutput(buf []byte) { } func (o *Oizys) GitPull() { - cmdOutput, err := o.git("status", "--porcelain").Output() if err != nil { log.Fatal(err) @@ -171,14 +169,13 @@ func (o *Oizys) GitPull() { os.Exit(1) } - cmdOutput, err = o.git("pull").CombinedOutput() + cmdOutput, err = o.git("pull").CombinedOutput() if err != nil { showFailedOutput(cmdOutput) log.Fatal(err) } } - func parseDryRun(buf string) (*packages, *packages) { lines := strings.Split(strings.TrimSpace(buf), "\n") var parts [2][]string @@ -232,10 +229,10 @@ func (o *Oizys) NixosRebuild(subcmd string, rest ...string) { o.flake, } args = append(args, rest...) - if o.verbose { - args = append(args, "--print-build-logs") + if o.verbose { + args = append(args, "--print-build-logs") fmt.Println("CMD:", "sudo", strings.Join(args, " ")) - } + } cmd := exec.Command("sudo", args...) runCommand(cmd) } @@ -267,11 +264,20 @@ func (o *Oizys) CacheBuild(rest ...string) { } func (o *Oizys) CheckFlake() { - if _, err := os.Stat(o.flake); errors.Is(err, fs.ErrNotExist) { - log.Fatalln("path to flake:", o.flake, "does not exist") + if _, ok := os.LookupEnv("OIZYS_SKIP_CHECK"); !ok { + if _, err := os.Stat(o.flake); errors.Is(err, fs.ErrNotExist) { + log.Fatalln("path to flake:", o.flake, "does not exist") + } } } +func (o *Oizys) CI(rest ...string) { + args := []string{"workflow", "run", "build.yml", "-F", fmt.Sprintf("host=%s", o.host)} + args = append(args, rest...) + cmd := exec.Command("gh", args...) + runCommand(cmd) +} + func Output(flake string, host string) string { return fmt.Sprintf( "%s#nixosConfigurations.%s.config.system.build.toplevel",